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 <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
8 #include <queue> | 11 #include <queue> |
9 #include <vector> | 12 #include <vector> |
10 | 13 |
11 #include "base/callback.h" | 14 #include "base/callback.h" |
12 #include "base/containers/scoped_ptr_hash_map.h" | 15 #include "base/containers/scoped_ptr_hash_map.h" |
| 16 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
15 #include "base/sequence_checker.h" | 19 #include "base/sequence_checker.h" |
16 #include "base/threading/sequenced_worker_pool.h" | 20 #include "base/threading/sequenced_worker_pool.h" |
17 #include "chrome/browser/sync_file_system/drive_backend/task_dependency_manager.
h" | 21 #include "chrome/browser/sync_file_system/drive_backend/task_dependency_manager.
h" |
18 #include "chrome/browser/sync_file_system/sync_callbacks.h" | 22 #include "chrome/browser/sync_file_system/sync_callbacks.h" |
19 #include "chrome/browser/sync_file_system/sync_status_code.h" | 23 #include "chrome/browser/sync_file_system/sync_status_code.h" |
20 #include "chrome/browser/sync_file_system/task_logger.h" | 24 #include "chrome/browser/sync_file_system/task_logger.h" |
21 | 25 |
22 namespace base { | 26 namespace base { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 // existing background task to finish. | 116 // existing background task to finish. |
113 // Upon the task is ready to run as a background task, calls |continuation| | 117 // Upon the task is ready to run as a background task, calls |continuation| |
114 // with new SyncTaskToken. | 118 // with new SyncTaskToken. |
115 // Note that this function once releases previous |task_blocker| before | 119 // Note that this function once releases previous |task_blocker| before |
116 // applying new |task_blocker|. So, any other task may be run before | 120 // applying new |task_blocker|. So, any other task may be run before |
117 // invocation of |continuation|. | 121 // invocation of |continuation|. |
118 static void UpdateTaskBlocker(scoped_ptr<SyncTaskToken> current_task_token, | 122 static void UpdateTaskBlocker(scoped_ptr<SyncTaskToken> current_task_token, |
119 scoped_ptr<TaskBlocker> task_blocker, | 123 scoped_ptr<TaskBlocker> task_blocker, |
120 const Continuation& continuation); | 124 const Continuation& continuation); |
121 | 125 |
122 bool IsRunningTask(int64 task_token_id) const; | 126 bool IsRunningTask(int64_t task_token_id) const; |
123 | 127 |
124 void DetachFromSequence(); | 128 void DetachFromSequence(); |
125 bool ShouldTrackTaskToken() const; | 129 bool ShouldTrackTaskToken() const; |
126 | 130 |
127 private: | 131 private: |
128 struct PendingTask { | 132 struct PendingTask { |
129 base::Closure task; | 133 base::Closure task; |
130 Priority priority; | 134 Priority priority; |
131 int64 seq; | 135 int64_t seq; |
132 | 136 |
133 PendingTask(); | 137 PendingTask(); |
134 PendingTask(const base::Closure& task, Priority pri, int seq); | 138 PendingTask(const base::Closure& task, Priority pri, int seq); |
135 ~PendingTask(); | 139 ~PendingTask(); |
136 }; | 140 }; |
137 | 141 |
138 struct PendingTaskComparator { | 142 struct PendingTaskComparator { |
139 bool operator()(const PendingTask& left, | 143 bool operator()(const PendingTask& left, |
140 const PendingTask& right) const; | 144 const PendingTask& right) const; |
141 }; | 145 }; |
(...skipping 27 matching lines...) Expand all Loading... |
169 // If |token| is non-nullptr, put |token| back to |token_| beforehand. | 173 // If |token| is non-nullptr, put |token| back to |token_| beforehand. |
170 void MaybeStartNextForegroundTask(scoped_ptr<SyncTaskToken> token); | 174 void MaybeStartNextForegroundTask(scoped_ptr<SyncTaskToken> token); |
171 | 175 |
172 base::WeakPtr<Client> client_; | 176 base::WeakPtr<Client> client_; |
173 | 177 |
174 // Owns running SyncTask to cancel the task on SyncTaskManager deletion. | 178 // Owns running SyncTask to cancel the task on SyncTaskManager deletion. |
175 scoped_ptr<SyncTask> running_foreground_task_; | 179 scoped_ptr<SyncTask> running_foreground_task_; |
176 | 180 |
177 // Owns running backgrounded SyncTask to cancel the task on SyncTaskManager | 181 // Owns running backgrounded SyncTask to cancel the task on SyncTaskManager |
178 // deletion. | 182 // deletion. |
179 base::ScopedPtrHashMap<int64, scoped_ptr<SyncTask>> running_background_tasks_; | 183 base::ScopedPtrHashMap<int64_t, scoped_ptr<SyncTask>> |
| 184 running_background_tasks_; |
180 | 185 |
181 size_t maximum_background_task_; | 186 size_t maximum_background_task_; |
182 | 187 |
183 // Holds pending continuation to move task to background. | 188 // Holds pending continuation to move task to background. |
184 base::Closure pending_backgrounding_task_; | 189 base::Closure pending_backgrounding_task_; |
185 | 190 |
186 std::priority_queue<PendingTask, std::vector<PendingTask>, | 191 std::priority_queue<PendingTask, std::vector<PendingTask>, |
187 PendingTaskComparator> pending_tasks_; | 192 PendingTaskComparator> pending_tasks_; |
188 int64 pending_task_seq_; | 193 int64_t pending_task_seq_; |
189 int64 task_token_seq_; | 194 int64_t task_token_seq_; |
190 | 195 |
191 // Absence of |token_| implies a task is running. Incoming tasks should | 196 // Absence of |token_| implies a task is running. Incoming tasks should |
192 // wait for the task to finish in |pending_tasks_| if |token_| is null. | 197 // wait for the task to finish in |pending_tasks_| if |token_| is null. |
193 // Each task must take TaskToken instance from |token_| and must hold it | 198 // Each task must take TaskToken instance from |token_| and must hold it |
194 // until it finished. And the task must return the instance through | 199 // until it finished. And the task must return the instance through |
195 // NotifyTaskDone when the task finished. | 200 // NotifyTaskDone when the task finished. |
196 scoped_ptr<SyncTaskToken> token_; | 201 scoped_ptr<SyncTaskToken> token_; |
197 | 202 |
198 TaskDependencyManager dependency_manager_; | 203 TaskDependencyManager dependency_manager_; |
199 | 204 |
200 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 205 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
201 scoped_refptr<base::SequencedWorkerPool> worker_pool_; | 206 scoped_refptr<base::SequencedWorkerPool> worker_pool_; |
202 base::SequenceChecker sequence_checker_; | 207 base::SequenceChecker sequence_checker_; |
203 | 208 |
204 base::WeakPtrFactory<SyncTaskManager> weak_ptr_factory_;; | 209 base::WeakPtrFactory<SyncTaskManager> weak_ptr_factory_;; |
205 | 210 |
206 DISALLOW_COPY_AND_ASSIGN(SyncTaskManager); | 211 DISALLOW_COPY_AND_ASSIGN(SyncTaskManager); |
207 }; | 212 }; |
208 | 213 |
209 } // namespace drive_backend | 214 } // namespace drive_backend |
210 } // namespace sync_file_system | 215 } // namespace sync_file_system |
211 | 216 |
212 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_TASK_MANAGER_H_ | 217 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_TASK_MANAGER_H_ |
OLD | NEW |