OLD | NEW |
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 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/containers/scoped_ptr_hash_map.h" | 12 #include "base/containers/scoped_ptr_hash_map.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/sequence_checker.h" | 15 #include "base/sequence_checker.h" |
16 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
17 #include "chrome/browser/sync_file_system/drive_backend/task_dependency_manager.
h" | 17 #include "chrome/browser/sync_file_system/drive_backend/task_dependency_manager.
h" |
18 #include "chrome/browser/sync_file_system/sync_callbacks.h" | 18 #include "chrome/browser/sync_file_system/sync_callbacks.h" |
19 #include "chrome/browser/sync_file_system/sync_status_code.h" | 19 #include "chrome/browser/sync_file_system/sync_status_code.h" |
20 #include "chrome/browser/sync_file_system/task_logger.h" | 20 #include "chrome/browser/sync_file_system/task_logger.h" |
21 | 21 |
| 22 namespace base { |
| 23 class SequencedTaskRunner; |
| 24 } |
| 25 |
22 namespace tracked_objects { | 26 namespace tracked_objects { |
23 class Location; | 27 class Location; |
24 } | 28 } |
25 | 29 |
26 namespace sync_file_system { | 30 namespace sync_file_system { |
27 namespace drive_backend { | 31 namespace drive_backend { |
28 | 32 |
29 class SyncTask; | 33 class SyncTask; |
30 class SyncTaskToken; | 34 class SyncTaskToken; |
31 struct BlockingFactor; | 35 struct BlockingFactor; |
(...skipping 29 matching lines...) Expand all Loading... |
61 virtual void NotifyLastOperationStatus( | 65 virtual void NotifyLastOperationStatus( |
62 SyncStatusCode last_operation_status, | 66 SyncStatusCode last_operation_status, |
63 bool last_operation_used_network) = 0; | 67 bool last_operation_used_network) = 0; |
64 | 68 |
65 virtual void RecordTaskLog(scoped_ptr<TaskLogger::TaskLog> task_log) = 0; | 69 virtual void RecordTaskLog(scoped_ptr<TaskLogger::TaskLog> task_log) = 0; |
66 }; | 70 }; |
67 | 71 |
68 // Runs at most |maximum_background_tasks| parallel as background tasks. | 72 // Runs at most |maximum_background_tasks| parallel as background tasks. |
69 // If |maximum_background_tasks| is zero, all task runs as foreground task. | 73 // If |maximum_background_tasks| is zero, all task runs as foreground task. |
70 SyncTaskManager(base::WeakPtr<Client> client, | 74 SyncTaskManager(base::WeakPtr<Client> client, |
71 size_t maximum_background_task); | 75 size_t maximum_background_task, |
| 76 base::SequencedTaskRunner* task_runner); |
72 virtual ~SyncTaskManager(); | 77 virtual ~SyncTaskManager(); |
73 | 78 |
74 // This needs to be called to start task scheduling. | 79 // This needs to be called to start task scheduling. |
75 // If |status| is not SYNC_STATUS_OK calling this may change the | 80 // If |status| is not SYNC_STATUS_OK calling this may change the |
76 // service status. This should not be called more than once. | 81 // service status. This should not be called more than once. |
77 void Initialize(SyncStatusCode status); | 82 void Initialize(SyncStatusCode status); |
78 | 83 |
79 // Schedules a task at the given priority. | 84 // Schedules a task at the given priority. |
80 void ScheduleTask(const tracked_objects::Location& from_here, | 85 void ScheduleTask(const tracked_objects::Location& from_here, |
81 const Task& task, | 86 const Task& task, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 scoped_ptr<SyncTaskToken> GetTokenForBackgroundTask( | 158 scoped_ptr<SyncTaskToken> GetTokenForBackgroundTask( |
154 const tracked_objects::Location& from_here, | 159 const tracked_objects::Location& from_here, |
155 const SyncStatusCallback& callback, | 160 const SyncStatusCallback& callback, |
156 scoped_ptr<BlockingFactor> blocking_factor); | 161 scoped_ptr<BlockingFactor> blocking_factor); |
157 | 162 |
158 void PushPendingTask(const base::Closure& closure, Priority priority); | 163 void PushPendingTask(const base::Closure& closure, Priority priority); |
159 | 164 |
160 void RunTask(scoped_ptr<SyncTaskToken> token, | 165 void RunTask(scoped_ptr<SyncTaskToken> token, |
161 scoped_ptr<SyncTask> task); | 166 scoped_ptr<SyncTask> task); |
162 | 167 |
163 void StartNextTask(); | 168 // Runs a pending task as a foreground task if possible. |
| 169 // If |token| is non-NULL, put |token| back to |token_| beforehand. |
| 170 void MaybeStartNextForegroundTask(scoped_ptr<SyncTaskToken> token); |
164 | 171 |
165 base::WeakPtr<Client> client_; | 172 base::WeakPtr<Client> client_; |
166 | 173 |
167 // Owns running SyncTask to cancel the task on SyncTaskManager deletion. | 174 // Owns running SyncTask to cancel the task on SyncTaskManager deletion. |
168 scoped_ptr<SyncTask> running_foreground_task_; | 175 scoped_ptr<SyncTask> running_foreground_task_; |
169 | 176 |
170 // Owns running backgrounded SyncTask to cancel the task on SyncTaskManager | 177 // Owns running backgrounded SyncTask to cancel the task on SyncTaskManager |
171 // deletion. | 178 // deletion. |
172 base::ScopedPtrHashMap<int64, SyncTask> running_background_tasks_; | 179 base::ScopedPtrHashMap<int64, SyncTask> running_background_tasks_; |
173 | 180 |
174 size_t maximum_background_task_; | 181 size_t maximum_background_task_; |
175 | 182 |
176 // Holds pending continuation to move task to background. | 183 // Holds pending continuation to move task to background. |
177 base::Closure pending_backgrounding_task_; | 184 base::Closure pending_backgrounding_task_; |
178 | 185 |
179 std::priority_queue<PendingTask, std::vector<PendingTask>, | 186 std::priority_queue<PendingTask, std::vector<PendingTask>, |
180 PendingTaskComparator> pending_tasks_; | 187 PendingTaskComparator> pending_tasks_; |
181 int64 pending_task_seq_; | 188 int64 pending_task_seq_; |
182 int64 task_token_seq_; | 189 int64 task_token_seq_; |
183 | 190 |
184 // Absence of |token_| implies a task is running. Incoming tasks should | 191 // Absence of |token_| implies a task is running. Incoming tasks should |
185 // wait for the task to finish in |pending_tasks_| if |token_| is null. | 192 // wait for the task to finish in |pending_tasks_| if |token_| is null. |
186 // Each task must take TaskToken instance from |token_| and must hold it | 193 // Each task must take TaskToken instance from |token_| and must hold it |
187 // until it finished. And the task must return the instance through | 194 // until it finished. And the task must return the instance through |
188 // NotifyTaskDone when the task finished. | 195 // NotifyTaskDone when the task finished. |
189 scoped_ptr<SyncTaskToken> token_; | 196 scoped_ptr<SyncTaskToken> token_; |
190 | 197 |
191 TaskDependencyManager dependency_manager_; | 198 TaskDependencyManager dependency_manager_; |
192 | 199 |
| 200 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
193 base::SequenceChecker sequence_checker_; | 201 base::SequenceChecker sequence_checker_; |
194 | 202 |
195 DISALLOW_COPY_AND_ASSIGN(SyncTaskManager); | 203 DISALLOW_COPY_AND_ASSIGN(SyncTaskManager); |
196 }; | 204 }; |
197 | 205 |
198 } // namespace drive_backend | 206 } // namespace drive_backend |
199 } // namespace sync_file_system | 207 } // namespace sync_file_system |
200 | 208 |
201 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_TASK_MANAGER_H_ | 209 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_TASK_MANAGER_H_ |
OLD | NEW |