Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/sync_task_manager.h

Issue 550903002: [SyncFS] Rename BlockingFactor to TaskBlocker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_TASK_MANAGER_H_ 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_TASK_MANAGER_H_
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_TASK_MANAGER_H_ 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_TASK_MANAGER_H_
7 7
8 #include <queue> 8 #include <queue>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 13 matching lines...) Expand all
24 24
25 namespace tracked_objects { 25 namespace tracked_objects {
26 class Location; 26 class Location;
27 } 27 }
28 28
29 namespace sync_file_system { 29 namespace sync_file_system {
30 namespace drive_backend { 30 namespace drive_backend {
31 31
32 class SyncTask; 32 class SyncTask;
33 class SyncTaskToken; 33 class SyncTaskToken;
34 struct BlockingFactor; 34 struct TaskBlocker;
35 35
36 // This class manages asynchronous tasks for Sync FileSystem. Each task must be 36 // This class manages asynchronous tasks for Sync FileSystem. Each task must be
37 // either a Task or a SyncTask. 37 // either a Task or a SyncTask.
38 // The instance runs single task as the foreground task, and multiple tasks as 38 // The instance runs single task as the foreground task, and multiple tasks as
39 // background tasks. Running background task has a BlockingFactor that 39 // background tasks. Running background task has a TaskBlocker that
40 // describes which task can run in parallel. When a task start running as a 40 // describes which task can run in parallel. When a task start running as a
41 // background task, SyncTaskManager checks if any running background task 41 // background task, SyncTaskManager checks if any running background task
42 // doesn't block the new background task, and queues it up if it can't run. 42 // doesn't block the new background task, and queues it up if it can't run.
43 class SyncTaskManager : public base::SupportsWeakPtr<SyncTaskManager> { 43 class SyncTaskManager : public base::SupportsWeakPtr<SyncTaskManager> {
44 public: 44 public:
45 typedef base::Callback<void(const SyncStatusCallback& callback)> Task; 45 typedef base::Callback<void(const SyncStatusCallback& callback)> Task;
46 typedef base::Callback<void(scoped_ptr<SyncTaskToken> token)> Continuation; 46 typedef base::Callback<void(scoped_ptr<SyncTaskToken> token)> Continuation;
47 47
48 enum Priority { 48 enum Priority {
49 PRIORITY_LOW, 49 PRIORITY_LOW,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 const SyncStatusCallback& callback); 95 const SyncStatusCallback& callback);
96 bool ScheduleSyncTaskIfIdle(const tracked_objects::Location& from_here, 96 bool ScheduleSyncTaskIfIdle(const tracked_objects::Location& from_here,
97 scoped_ptr<SyncTask> task, 97 scoped_ptr<SyncTask> task,
98 const SyncStatusCallback& callback); 98 const SyncStatusCallback& callback);
99 99
100 // Notifies SyncTaskManager that the task associated to |token| has finished 100 // Notifies SyncTaskManager that the task associated to |token| has finished
101 // with |status|. 101 // with |status|.
102 static void NotifyTaskDone(scoped_ptr<SyncTaskToken> token, 102 static void NotifyTaskDone(scoped_ptr<SyncTaskToken> token,
103 SyncStatusCode status); 103 SyncStatusCode status);
104 104
105 // Updates |blocking_factor| associated to the current task by specified 105 // Updates |task_blocker| associated to the current task by specified
106 // |blocking_factor| and turns the current task to a background task if 106 // |task_blocker| and turns the current task to a background task if
107 // the current task is running as a foreground task. 107 // the current task is running as a foreground task.
108 // If specified |blocking_factor| is blocked by any other blocking factor 108 // If specified |task_blocker| is blocked by any other blocking factor
109 // associated to an existing background task, this function waits for the 109 // associated to an existing background task, this function waits for the
110 // existing background task to finish. 110 // existing background task to finish.
111 // Upon the task is ready to run as a background task, calls |continuation| 111 // Upon the task is ready to run as a background task, calls |continuation|
112 // with new SyncTaskToken. 112 // with new SyncTaskToken.
113 // Note that this function once releases previous |blocking_factor| before 113 // Note that this function once releases previous |task_blocker| before
114 // applying new |blocking_factor|. So, any other task may be run before 114 // applying new |task_blocker|. So, any other task may be run before
115 // invocation of |continuation|. 115 // invocation of |continuation|.
116 static void UpdateBlockingFactor(scoped_ptr<SyncTaskToken> current_task_token, 116 static void UpdateTaskBlocker(scoped_ptr<SyncTaskToken> current_task_token,
117 scoped_ptr<BlockingFactor> blocking_factor, 117 scoped_ptr<TaskBlocker> task_blocker,
118 const Continuation& continuation); 118 const Continuation& continuation);
119 119
120 bool IsRunningTask(int64 task_token_id) const; 120 bool IsRunningTask(int64 task_token_id) const;
121 121
122 void DetachFromSequence(); 122 void DetachFromSequence();
123 123
124 private: 124 private:
125 struct PendingTask { 125 struct PendingTask {
126 base::Closure task; 126 base::Closure task;
127 Priority priority; 127 Priority priority;
128 int64 seq; 128 int64 seq;
129 129
130 PendingTask(); 130 PendingTask();
131 PendingTask(const base::Closure& task, Priority pri, int seq); 131 PendingTask(const base::Closure& task, Priority pri, int seq);
132 ~PendingTask(); 132 ~PendingTask();
133 }; 133 };
134 134
135 struct PendingTaskComparator { 135 struct PendingTaskComparator {
136 bool operator()(const PendingTask& left, 136 bool operator()(const PendingTask& left,
137 const PendingTask& right) const; 137 const PendingTask& right) const;
138 }; 138 };
139 139
140 // Non-static version of NotifyTaskDone. 140 // Non-static version of NotifyTaskDone.
141 void NotifyTaskDoneBody(scoped_ptr<SyncTaskToken> token, 141 void NotifyTaskDoneBody(scoped_ptr<SyncTaskToken> token,
142 SyncStatusCode status); 142 SyncStatusCode status);
143 143
144 // Non-static version of UpdateBlockingFactor. 144 // Non-static version of UpdateTaskBlocker.
145 void UpdateBlockingFactorBody(scoped_ptr<SyncTaskToken> foreground_task_token, 145 void UpdateTaskBlockerBody(scoped_ptr<SyncTaskToken> foreground_task_token,
146 scoped_ptr<SyncTaskToken> background_task_token, 146 scoped_ptr<SyncTaskToken> background_task_token,
peria 2014/09/08 08:44:47 nit: fix indent
tzik 2014/09/08 08:58:33 Done.
147 scoped_ptr<TaskLogger::TaskLog> task_log, 147 scoped_ptr<TaskLogger::TaskLog> task_log,
148 scoped_ptr<BlockingFactor> blocking_factor, 148 scoped_ptr<TaskBlocker> task_blocker,
149 const Continuation& continuation); 149 const Continuation& continuation);
150 150
151 // This should be called when an async task needs to get a task token. 151 // This should be called when an async task needs to get a task token.
152 scoped_ptr<SyncTaskToken> GetToken(const tracked_objects::Location& from_here, 152 scoped_ptr<SyncTaskToken> GetToken(const tracked_objects::Location& from_here,
153 const SyncStatusCallback& callback); 153 const SyncStatusCallback& callback);
154 154
155 scoped_ptr<SyncTaskToken> GetTokenForBackgroundTask( 155 scoped_ptr<SyncTaskToken> GetTokenForBackgroundTask(
156 const tracked_objects::Location& from_here, 156 const tracked_objects::Location& from_here,
157 const SyncStatusCallback& callback, 157 const SyncStatusCallback& callback,
158 scoped_ptr<BlockingFactor> blocking_factor); 158 scoped_ptr<TaskBlocker> task_blocker);
159 159
160 void PushPendingTask(const base::Closure& closure, Priority priority); 160 void PushPendingTask(const base::Closure& closure, Priority priority);
161 161
162 void RunTask(scoped_ptr<SyncTaskToken> token, 162 void RunTask(scoped_ptr<SyncTaskToken> token,
163 scoped_ptr<SyncTask> task); 163 scoped_ptr<SyncTask> task);
164 164
165 // Runs a pending task as a foreground task if possible. 165 // Runs a pending task as a foreground task if possible.
166 // If |token| is non-NULL, put |token| back to |token_| beforehand. 166 // If |token| is non-NULL, put |token| back to |token_| beforehand.
167 void MaybeStartNextForegroundTask(scoped_ptr<SyncTaskToken> token); 167 void MaybeStartNextForegroundTask(scoped_ptr<SyncTaskToken> token);
168 168
(...skipping 28 matching lines...) Expand all
197 scoped_refptr<base::SequencedTaskRunner> task_runner_; 197 scoped_refptr<base::SequencedTaskRunner> task_runner_;
198 base::SequenceChecker sequence_checker_; 198 base::SequenceChecker sequence_checker_;
199 199
200 DISALLOW_COPY_AND_ASSIGN(SyncTaskManager); 200 DISALLOW_COPY_AND_ASSIGN(SyncTaskManager);
201 }; 201 };
202 202
203 } // namespace drive_backend 203 } // namespace drive_backend
204 } // namespace sync_file_system 204 } // namespace sync_file_system
205 205
206 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_TASK_MANAGER_H_ 206 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_TASK_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698