| 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 <deque> | 5 #include <deque> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 task_scheduled_count_(0), | 60 task_scheduled_count_(0), |
| 61 idle_task_scheduled_count_(0), | 61 idle_task_scheduled_count_(0), |
| 62 last_operation_status_(SYNC_STATUS_OK) { | 62 last_operation_status_(SYNC_STATUS_OK) { |
| 63 task_manager_.reset(new SyncTaskManager( | 63 task_manager_.reset(new SyncTaskManager( |
| 64 AsWeakPtr(), maximum_background_task, | 64 AsWeakPtr(), maximum_background_task, |
| 65 base::ThreadTaskRunnerHandle::Get())); | 65 base::ThreadTaskRunnerHandle::Get())); |
| 66 task_manager_->Initialize(SYNC_STATUS_OK); | 66 task_manager_->Initialize(SYNC_STATUS_OK); |
| 67 base::MessageLoop::current()->RunUntilIdle(); | 67 base::MessageLoop::current()->RunUntilIdle(); |
| 68 maybe_schedule_next_task_count_ = 0; | 68 maybe_schedule_next_task_count_ = 0; |
| 69 } | 69 } |
| 70 virtual ~TaskManagerClient() {} | 70 ~TaskManagerClient() override {} |
| 71 | 71 |
| 72 // DriveFileSyncManager::Client overrides. | 72 // DriveFileSyncManager::Client overrides. |
| 73 virtual void MaybeScheduleNextTask() override { | 73 void MaybeScheduleNextTask() override { ++maybe_schedule_next_task_count_; } |
| 74 ++maybe_schedule_next_task_count_; | 74 void NotifyLastOperationStatus(SyncStatusCode last_operation_status, |
| 75 } | 75 bool last_operation_used_network) override { |
| 76 virtual void NotifyLastOperationStatus( | |
| 77 SyncStatusCode last_operation_status, | |
| 78 bool last_operation_used_network) override { | |
| 79 last_operation_status_ = last_operation_status; | 76 last_operation_status_ = last_operation_status; |
| 80 } | 77 } |
| 81 | 78 |
| 82 virtual void RecordTaskLog(scoped_ptr<TaskLogger::TaskLog>) override {} | 79 void RecordTaskLog(scoped_ptr<TaskLogger::TaskLog>) override {} |
| 83 | 80 |
| 84 void ScheduleTask(SyncStatusCode status_to_return, | 81 void ScheduleTask(SyncStatusCode status_to_return, |
| 85 const SyncStatusCallback& callback) { | 82 const SyncStatusCallback& callback) { |
| 86 task_manager_->ScheduleTask( | 83 task_manager_->ScheduleTask( |
| 87 FROM_HERE, | 84 FROM_HERE, |
| 88 base::Bind(&TaskManagerClient::DoTask, AsWeakPtr(), | 85 base::Bind(&TaskManagerClient::DoTask, AsWeakPtr(), |
| 89 status_to_return, false /* idle */), | 86 status_to_return, false /* idle */), |
| 90 SyncTaskManager::PRIORITY_MED, | 87 SyncTaskManager::PRIORITY_MED, |
| 91 callback); | 88 callback); |
| 92 } | 89 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 public: | 131 public: |
| 135 MultihopSyncTask(bool* task_started, | 132 MultihopSyncTask(bool* task_started, |
| 136 bool* task_completed) | 133 bool* task_completed) |
| 137 : task_started_(task_started), | 134 : task_started_(task_started), |
| 138 task_completed_(task_completed), | 135 task_completed_(task_completed), |
| 139 weak_ptr_factory_(this) { | 136 weak_ptr_factory_(this) { |
| 140 DCHECK(task_started_); | 137 DCHECK(task_started_); |
| 141 DCHECK(task_completed_); | 138 DCHECK(task_completed_); |
| 142 } | 139 } |
| 143 | 140 |
| 144 virtual ~MultihopSyncTask() {} | 141 ~MultihopSyncTask() override {} |
| 145 | 142 |
| 146 virtual void RunExclusive(const SyncStatusCallback& callback) override { | 143 void RunExclusive(const SyncStatusCallback& callback) override { |
| 147 DCHECK(!*task_started_); | 144 DCHECK(!*task_started_); |
| 148 *task_started_ = true; | 145 *task_started_ = true; |
| 149 base::MessageLoop::current()->PostTask( | 146 base::MessageLoop::current()->PostTask( |
| 150 FROM_HERE, base::Bind(&MultihopSyncTask::CompleteTask, | 147 FROM_HERE, base::Bind(&MultihopSyncTask::CompleteTask, |
| 151 weak_ptr_factory_.GetWeakPtr(), callback)); | 148 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 152 } | 149 } |
| 153 | 150 |
| 154 private: | 151 private: |
| 155 void CompleteTask(const SyncStatusCallback& callback) { | 152 void CompleteTask(const SyncStatusCallback& callback) { |
| 156 DCHECK(*task_started_); | 153 DCHECK(*task_started_); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 181 | 178 |
| 182 BackgroundTask(const std::string& app_id, | 179 BackgroundTask(const std::string& app_id, |
| 183 const base::FilePath& path, | 180 const base::FilePath& path, |
| 184 Stats* stats) | 181 Stats* stats) |
| 185 : app_id_(app_id), | 182 : app_id_(app_id), |
| 186 path_(path), | 183 path_(path), |
| 187 stats_(stats), | 184 stats_(stats), |
| 188 weak_ptr_factory_(this) { | 185 weak_ptr_factory_(this) { |
| 189 } | 186 } |
| 190 | 187 |
| 191 virtual ~BackgroundTask() { | 188 ~BackgroundTask() override {} |
| 192 } | |
| 193 | 189 |
| 194 virtual void RunPreflight(scoped_ptr<SyncTaskToken> token) override { | 190 void RunPreflight(scoped_ptr<SyncTaskToken> token) override { |
| 195 scoped_ptr<TaskBlocker> task_blocker(new TaskBlocker); | 191 scoped_ptr<TaskBlocker> task_blocker(new TaskBlocker); |
| 196 task_blocker->app_id = app_id_; | 192 task_blocker->app_id = app_id_; |
| 197 task_blocker->paths.push_back(path_); | 193 task_blocker->paths.push_back(path_); |
| 198 | 194 |
| 199 SyncTaskManager::UpdateTaskBlocker( | 195 SyncTaskManager::UpdateTaskBlocker( |
| 200 token.Pass(), task_blocker.Pass(), | 196 token.Pass(), task_blocker.Pass(), |
| 201 base::Bind(&BackgroundTask::RunAsBackgroundTask, | 197 base::Bind(&BackgroundTask::RunAsBackgroundTask, |
| 202 weak_ptr_factory_.GetWeakPtr())); | 198 weak_ptr_factory_.GetWeakPtr())); |
| 203 } | 199 } |
| 204 | 200 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 const std::string& app_id, | 234 const std::string& app_id, |
| 239 const std::vector<std::string>& paths, | 235 const std::vector<std::string>& paths, |
| 240 Log* log) | 236 Log* log) |
| 241 : name_(name), | 237 : name_(name), |
| 242 app_id_(app_id), | 238 app_id_(app_id), |
| 243 paths_(paths.begin(), paths.end()), | 239 paths_(paths.begin(), paths.end()), |
| 244 log_(log), | 240 log_(log), |
| 245 weak_ptr_factory_(this) { | 241 weak_ptr_factory_(this) { |
| 246 } | 242 } |
| 247 | 243 |
| 248 virtual ~BlockerUpdateTestHelper() { | 244 ~BlockerUpdateTestHelper() override {} |
| 249 } | |
| 250 | 245 |
| 251 virtual void RunPreflight(scoped_ptr<SyncTaskToken> token) override { | 246 void RunPreflight(scoped_ptr<SyncTaskToken> token) override { |
| 252 UpdateBlocker(token.Pass()); | 247 UpdateBlocker(token.Pass()); |
| 253 } | 248 } |
| 254 | 249 |
| 255 private: | 250 private: |
| 256 void UpdateBlocker(scoped_ptr<SyncTaskToken> token) { | 251 void UpdateBlocker(scoped_ptr<SyncTaskToken> token) { |
| 257 if (paths_.empty()) { | 252 if (paths_.empty()) { |
| 258 log_->push_back(name_ + ": finished"); | 253 log_->push_back(name_ + ": finished"); |
| 259 SyncTaskManager::NotifyTaskDone(token.Pass(), SYNC_STATUS_OK); | 254 SyncTaskManager::NotifyTaskDone(token.Pass(), SYNC_STATUS_OK); |
| 260 return; | 255 return; |
| 261 } | 256 } |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 | 662 |
| 668 EXPECT_EQ("task1: finished", log[i++]); | 663 EXPECT_EQ("task1: finished", log[i++]); |
| 669 | 664 |
| 670 EXPECT_EQ("task2: updating to /hoge/fuga/piyo", log[i++]); | 665 EXPECT_EQ("task2: updating to /hoge/fuga/piyo", log[i++]); |
| 671 EXPECT_EQ("task2: updated to /hoge/fuga/piyo", log[i++]); | 666 EXPECT_EQ("task2: updated to /hoge/fuga/piyo", log[i++]); |
| 672 EXPECT_EQ("task2: finished", log[i++]); | 667 EXPECT_EQ("task2: finished", log[i++]); |
| 673 } | 668 } |
| 674 | 669 |
| 675 } // namespace drive_backend | 670 } // namespace drive_backend |
| 676 } // namespace sync_file_system | 671 } // namespace sync_file_system |
| OLD | NEW |