- if (!mServiceHandler.mPendingOperations.isEmpty()) {
- return true;
- } else {
- return false;
- }
- //Log_OC.wtf(TAG, "Not finished yet");
- }
- }
-
- }
-
-
- /**
- * SyncFolder worker. Performs the pending operations in the order they were requested.
- *
- * Created with the Looper of a new thread, started in {@link OperationsService#onCreate()}.
- */
- private static class SyncFolderHandler extends Handler {
-
- // don't make it a final class, and don't remove the static ; lint will warn about a possible memory leak
-
- OperationsService mService;
-
- private ConcurrentMap<String,SynchronizeFolderOperation> mPendingOperations =
- new ConcurrentHashMap<String,SynchronizeFolderOperation>();
- private OwnCloudClient mOwnCloudClient = null;
- private FileDataStorageManager mStorageManager;
- private SynchronizeFolderOperation mCurrentSyncOperation;
-
-
- public SyncFolderHandler(Looper looper, OperationsService service) {
- super(looper);
- if (service == null) {
- throw new IllegalArgumentException("Received invalid NULL in parameter 'service'");
- }
- mService = service;
- }
-
- @Override
- public void handleMessage(Message msg) {
- Pair<Account, OCFile> itemSyncKey = (Pair<Account, OCFile>) msg.obj;
- nextOperation(itemSyncKey.first,itemSyncKey.second);
- mService.stopSelf(msg.arg1);
- }
-
-
- /**
- * Performs the next operation in the queue
- */
- private void nextOperation(Account account, OCFile file) {
-
- String syncKey = buildRemoteName(account,file);
-
- synchronized(mPendingOperations) {
- mCurrentSyncOperation = mPendingOperations.get(syncKey);
- }
-
- if (mCurrentSyncOperation != null) {
-
- RemoteOperationResult operationResult = null;
- try {
-
- OwnCloudAccount ocAccount = new OwnCloudAccount(account, mService);
- mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
- getClientFor(ocAccount, mService);
- mStorageManager = new FileDataStorageManager(
- account,
- mService.getContentResolver()
- );
-
-
- /// perform the operation
- if (mCurrentSyncOperation instanceof SyncOperation) {
- operationResult = ((SyncOperation)mCurrentSyncOperation).execute(mOwnCloudClient, mStorageManager);
- } else {
- operationResult = mCurrentSyncOperation.execute(mOwnCloudClient);
- }
-
- } catch (AccountsException e) {
- Log_OC.e(TAG, "Error while trying to get autorization", e);
- operationResult = new RemoteOperationResult(e);
- } catch (IOException e) {
- Log_OC.e(TAG, "Error while trying to get autorization", e);
- operationResult = new RemoteOperationResult(e);
-
- } finally {
- synchronized(mPendingOperations) {
- mPendingOperations.remove(syncKey);
- }
- }
-
- /// TODO notify operation result if needed
-