Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync_file_system / drive_backend / sync_task_manager.h
index 7b29035..0597b11 100644 (file)
@@ -30,6 +30,13 @@ namespace drive_backend {
 class SyncTaskToken;
 struct BlockingFactor;
 
+// This class manages asynchronous tasks for Sync FileSystem.  Each task must be
+// either a Task or a SyncTask.
+// The instance runs single task as the foreground task, and multiple tasks as
+// background tasks.  Running background task has a BlockingFactor that
+// describes which task can run in parallel.  When a task start running as a
+// background task, SyncTaskManager checks if any running background task
+// doesn't block the new background task, and queues it up if it can't run.
 class SyncTaskManager
     : public base::NonThreadSafe,
       public base::SupportsWeakPtr<SyncTaskManager> {
@@ -86,9 +93,23 @@ class SyncTaskManager
                               scoped_ptr<SyncTask> task,
                               const SyncStatusCallback& callback);
 
+  // Notifies SyncTaskManager that the task associated to |token| has finished
+  // with |status|.
   static void NotifyTaskDone(scoped_ptr<SyncTaskToken> token,
                              SyncStatusCode status);
-  static void MoveTaskToBackground(scoped_ptr<SyncTaskToken> token,
+
+  // Updates |blocking_factor| associated to the current task by specified
+  // |blocking_factor| and turns the current task to a background task if
+  // the current task is running as a foreground task.
+  // If specified |blocking_factor| is blocked by any other blocking factor
+  // associated to an existing background task, this function waits for the
+  // existing background task to finish.
+  // Upon the task is ready to run as a background task, calls |continuation|
+  // with new SyncTaskToken.
+  // Note that this function once releases previous |blocking_factor| before
+  // applying new |blocking_factor|.  So, any other task may be run before
+  // invocation of |continuation|.
+  static void UpdateBlockingFactor(scoped_ptr<SyncTaskToken> current_task_token,
                                    scoped_ptr<BlockingFactor> blocking_factor,
                                    const Continuation& continuation);
 
@@ -114,18 +135,12 @@ class SyncTaskManager
   void NotifyTaskDoneBody(scoped_ptr<SyncTaskToken> token,
                           SyncStatusCode status);
 
-  // Notifies SyncTaskManager that the running task turned to a background task.
-  void NotifyTaskBackgrounded(scoped_ptr<SyncTaskToken> foreground_task_token,
-                              const SyncTaskToken& background_task_token);
-
-  // Non-static version of MoveTaskToBackground.
-  void MoveTaskToBackgroundBody(scoped_ptr<SyncTaskToken> token,
+  // Non-static version of UpdateBlockingFactor.
+  void UpdateBlockingFactorBody(scoped_ptr<SyncTaskToken> foreground_task_token,
+                                scoped_ptr<SyncTaskToken> background_task_token,
                                 scoped_ptr<BlockingFactor> blocking_factor,
                                 const Continuation& continuation);
 
-  // Returns true if no running background task blocks |blocking_factor|.
-  bool CanRunAsBackgroundTask(const BlockingFactor& blocking_factor);
-
   // This should be called when an async task needs to get a task token.
   scoped_ptr<SyncTaskToken> GetToken(const tracked_objects::Location& from_here,
                                      const SyncStatusCallback& callback);
@@ -145,11 +160,11 @@ class SyncTaskManager
   base::WeakPtr<Client> client_;
 
   // Owns running SyncTask to cancel the task on SyncTaskManager deletion.
-  scoped_ptr<SyncTask> running_task_;
+  scoped_ptr<SyncTask> running_foreground_task_;
 
   // Owns running backgrounded SyncTask to cancel the task on SyncTaskManager
   // deletion.
-  base::ScopedPtrHashMap<int64, SyncTask> running_background_task_;
+  base::ScopedPtrHashMap<int64, SyncTask> running_background_tasks_;
 
   size_t maximum_background_task_;