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 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" | 5 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <deque> | 8 #include <deque> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 16 matching lines...) Expand all Loading... |
27 base::FilePath(storage::VirtualPath::GetNormalizedFilePath( \ | 27 base::FilePath(storage::VirtualPath::GetNormalizedFilePath( \ |
28 base::FilePath(FILE_PATH_LITERAL(path)))) | 28 base::FilePath(FILE_PATH_LITERAL(path)))) |
29 | 29 |
30 namespace sync_file_system { | 30 namespace sync_file_system { |
31 namespace drive_backend { | 31 namespace drive_backend { |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 void DumbTask(SyncStatusCode status, | 35 void DumbTask(SyncStatusCode status, |
36 const SyncStatusCallback& callback) { | 36 const SyncStatusCallback& callback) { |
37 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 37 base::ThreadTaskRunnerHandle::Get()->PostTask( |
38 base::Bind(callback, status)); | 38 FROM_HERE, base::BindOnce(callback, status)); |
39 } | 39 } |
40 | 40 |
41 void IncrementAndAssign(int expected_before_counter, | 41 void IncrementAndAssign(int expected_before_counter, |
42 int* counter, | 42 int* counter, |
43 SyncStatusCode* status_out, | 43 SyncStatusCode* status_out, |
44 SyncStatusCode status) { | 44 SyncStatusCode status) { |
45 EXPECT_EQ(expected_before_counter, *counter); | 45 EXPECT_EQ(expected_before_counter, *counter); |
46 ++(*counter); | 46 ++(*counter); |
47 *status_out = status; | 47 *status_out = status; |
48 } | 48 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 103 } |
104 | 104 |
105 private: | 105 private: |
106 void DoTask(SyncStatusCode status_to_return, | 106 void DoTask(SyncStatusCode status_to_return, |
107 bool is_idle_task, | 107 bool is_idle_task, |
108 const SyncStatusCallback& callback) { | 108 const SyncStatusCallback& callback) { |
109 ++task_scheduled_count_; | 109 ++task_scheduled_count_; |
110 if (is_idle_task) | 110 if (is_idle_task) |
111 ++idle_task_scheduled_count_; | 111 ++idle_task_scheduled_count_; |
112 base::ThreadTaskRunnerHandle::Get()->PostTask( | 112 base::ThreadTaskRunnerHandle::Get()->PostTask( |
113 FROM_HERE, base::Bind(callback, status_to_return)); | 113 FROM_HERE, base::BindOnce(callback, status_to_return)); |
114 } | 114 } |
115 | 115 |
116 std::unique_ptr<SyncTaskManager> task_manager_; | 116 std::unique_ptr<SyncTaskManager> task_manager_; |
117 | 117 |
118 int maybe_schedule_next_task_count_; | 118 int maybe_schedule_next_task_count_; |
119 int task_scheduled_count_; | 119 int task_scheduled_count_; |
120 int idle_task_scheduled_count_; | 120 int idle_task_scheduled_count_; |
121 | 121 |
122 SyncStatusCode last_operation_status_; | 122 SyncStatusCode last_operation_status_; |
123 | 123 |
(...skipping 10 matching lines...) Expand all Loading... |
134 DCHECK(task_started_); | 134 DCHECK(task_started_); |
135 DCHECK(task_completed_); | 135 DCHECK(task_completed_); |
136 } | 136 } |
137 | 137 |
138 ~MultihopSyncTask() override {} | 138 ~MultihopSyncTask() override {} |
139 | 139 |
140 void RunExclusive(const SyncStatusCallback& callback) override { | 140 void RunExclusive(const SyncStatusCallback& callback) override { |
141 DCHECK(!*task_started_); | 141 DCHECK(!*task_started_); |
142 *task_started_ = true; | 142 *task_started_ = true; |
143 base::ThreadTaskRunnerHandle::Get()->PostTask( | 143 base::ThreadTaskRunnerHandle::Get()->PostTask( |
144 FROM_HERE, base::Bind(&MultihopSyncTask::CompleteTask, | 144 FROM_HERE, base::BindOnce(&MultihopSyncTask::CompleteTask, |
145 weak_ptr_factory_.GetWeakPtr(), callback)); | 145 weak_ptr_factory_.GetWeakPtr(), callback)); |
146 } | 146 } |
147 | 147 |
148 private: | 148 private: |
149 void CompleteTask(const SyncStatusCallback& callback) { | 149 void CompleteTask(const SyncStatusCallback& callback) { |
150 DCHECK(*task_started_); | 150 DCHECK(*task_started_); |
151 DCHECK(!*task_completed_); | 151 DCHECK(!*task_completed_); |
152 *task_completed_ = true; | 152 *task_completed_ = true; |
153 callback.Run(SYNC_STATUS_OK); | 153 callback.Run(SYNC_STATUS_OK); |
154 } | 154 } |
155 | 155 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } | 196 } |
197 | 197 |
198 private: | 198 private: |
199 void RunAsBackgroundTask(std::unique_ptr<SyncTaskToken> token) { | 199 void RunAsBackgroundTask(std::unique_ptr<SyncTaskToken> token) { |
200 ++(stats_->running_background_task); | 200 ++(stats_->running_background_task); |
201 if (stats_->max_parallel_task < stats_->running_background_task) | 201 if (stats_->max_parallel_task < stats_->running_background_task) |
202 stats_->max_parallel_task = stats_->running_background_task; | 202 stats_->max_parallel_task = stats_->running_background_task; |
203 | 203 |
204 base::ThreadTaskRunnerHandle::Get()->PostTask( | 204 base::ThreadTaskRunnerHandle::Get()->PostTask( |
205 FROM_HERE, | 205 FROM_HERE, |
206 base::Bind(&BackgroundTask::CompleteTask, | 206 base::BindOnce(&BackgroundTask::CompleteTask, |
207 weak_ptr_factory_.GetWeakPtr(), base::Passed(&token))); | 207 weak_ptr_factory_.GetWeakPtr(), base::Passed(&token))); |
208 } | 208 } |
209 | 209 |
210 void CompleteTask(std::unique_ptr<SyncTaskToken> token) { | 210 void CompleteTask(std::unique_ptr<SyncTaskToken> token) { |
211 ++(stats_->finished_task); | 211 ++(stats_->finished_task); |
212 --(stats_->running_background_task); | 212 --(stats_->running_background_task); |
213 SyncTaskManager::NotifyTaskDone(std::move(token), SYNC_STATUS_OK); | 213 SyncTaskManager::NotifyTaskDone(std::move(token), SYNC_STATUS_OK); |
214 } | 214 } |
215 | 215 |
216 std::string app_id_; | 216 std::string app_id_; |
217 base::FilePath path_; | 217 base::FilePath path_; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 std::move(token), std::move(task_blocker), | 266 std::move(token), std::move(task_blocker), |
267 base::Bind(&BlockerUpdateTestHelper::UpdateBlockerSoon, | 267 base::Bind(&BlockerUpdateTestHelper::UpdateBlockerSoon, |
268 weak_ptr_factory_.GetWeakPtr(), updating_to)); | 268 weak_ptr_factory_.GetWeakPtr(), updating_to)); |
269 } | 269 } |
270 | 270 |
271 void UpdateBlockerSoon(const std::string& updated_to, | 271 void UpdateBlockerSoon(const std::string& updated_to, |
272 std::unique_ptr<SyncTaskToken> token) { | 272 std::unique_ptr<SyncTaskToken> token) { |
273 log_->push_back(name_ + ": updated to " + updated_to); | 273 log_->push_back(name_ + ": updated to " + updated_to); |
274 base::ThreadTaskRunnerHandle::Get()->PostTask( | 274 base::ThreadTaskRunnerHandle::Get()->PostTask( |
275 FROM_HERE, | 275 FROM_HERE, |
276 base::Bind(&BlockerUpdateTestHelper::UpdateBlocker, | 276 base::BindOnce(&BlockerUpdateTestHelper::UpdateBlocker, |
277 weak_ptr_factory_.GetWeakPtr(), base::Passed(&token))); | 277 weak_ptr_factory_.GetWeakPtr(), base::Passed(&token))); |
278 } | 278 } |
279 | 279 |
280 std::string name_; | 280 std::string name_; |
281 std::string app_id_; | 281 std::string app_id_; |
282 std::deque<std::string> paths_; | 282 std::deque<std::string> paths_; |
283 Log* log_; | 283 Log* log_; |
284 | 284 |
285 base::WeakPtrFactory<BlockerUpdateTestHelper> weak_ptr_factory_; | 285 base::WeakPtrFactory<BlockerUpdateTestHelper> weak_ptr_factory_; |
286 | 286 |
287 DISALLOW_COPY_AND_ASSIGN(BlockerUpdateTestHelper); | 287 DISALLOW_COPY_AND_ASSIGN(BlockerUpdateTestHelper); |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 | 631 |
632 EXPECT_EQ("task1: finished", log[i++]); | 632 EXPECT_EQ("task1: finished", log[i++]); |
633 | 633 |
634 EXPECT_EQ("task2: updating to /hoge/fuga/piyo", log[i++]); | 634 EXPECT_EQ("task2: updating to /hoge/fuga/piyo", log[i++]); |
635 EXPECT_EQ("task2: updated to /hoge/fuga/piyo", log[i++]); | 635 EXPECT_EQ("task2: updated to /hoge/fuga/piyo", log[i++]); |
636 EXPECT_EQ("task2: finished", log[i++]); | 636 EXPECT_EQ("task2: finished", log[i++]); |
637 } | 637 } |
638 | 638 |
639 } // namespace drive_backend | 639 } // namespace drive_backend |
640 } // namespace sync_file_system | 640 } // namespace sync_file_system |
OLD | NEW |