| 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/location.h" |
| 10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/single_thread_task_runner.h" |
| 13 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 14 #include "chrome/browser/sync_file_system/drive_backend/sync_task.h" | 16 #include "chrome/browser/sync_file_system/drive_backend/sync_task.h" |
| 15 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" | 17 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" |
| 16 #include "chrome/browser/sync_file_system/drive_backend/sync_task_token.h" | 18 #include "chrome/browser/sync_file_system/drive_backend/sync_task_token.h" |
| 17 #include "chrome/browser/sync_file_system/sync_file_system_test_util.h" | 19 #include "chrome/browser/sync_file_system/sync_file_system_test_util.h" |
| 18 #include "storage/common/fileapi/file_system_util.h" | 20 #include "storage/common/fileapi/file_system_util.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 22 |
| 21 #define MAKE_PATH(path) \ | 23 #define MAKE_PATH(path) \ |
| 22 base::FilePath(storage::VirtualPath::GetNormalizedFilePath( \ | 24 base::FilePath(storage::VirtualPath::GetNormalizedFilePath( \ |
| 23 base::FilePath(FILE_PATH_LITERAL(path)))) | 25 base::FilePath(FILE_PATH_LITERAL(path)))) |
| 24 | 26 |
| 25 namespace sync_file_system { | 27 namespace sync_file_system { |
| 26 namespace drive_backend { | 28 namespace drive_backend { |
| 27 | 29 |
| 28 namespace { | 30 namespace { |
| 29 | 31 |
| 30 void DumbTask(SyncStatusCode status, | 32 void DumbTask(SyncStatusCode status, |
| 31 const SyncStatusCallback& callback) { | 33 const SyncStatusCallback& callback) { |
| 32 base::MessageLoop::current()->PostTask( | 34 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 33 FROM_HERE, base::Bind(callback, status)); | 35 base::Bind(callback, status)); |
| 34 } | 36 } |
| 35 | 37 |
| 36 void IncrementAndAssign(int expected_before_counter, | 38 void IncrementAndAssign(int expected_before_counter, |
| 37 int* counter, | 39 int* counter, |
| 38 SyncStatusCode* status_out, | 40 SyncStatusCode* status_out, |
| 39 SyncStatusCode status) { | 41 SyncStatusCode status) { |
| 40 EXPECT_EQ(expected_before_counter, *counter); | 42 EXPECT_EQ(expected_before_counter, *counter); |
| 41 ++(*counter); | 43 ++(*counter); |
| 42 *status_out = status; | 44 *status_out = status; |
| 43 } | 45 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 return last_operation_status_; | 108 return last_operation_status_; |
| 107 } | 109 } |
| 108 | 110 |
| 109 private: | 111 private: |
| 110 void DoTask(SyncStatusCode status_to_return, | 112 void DoTask(SyncStatusCode status_to_return, |
| 111 bool is_idle_task, | 113 bool is_idle_task, |
| 112 const SyncStatusCallback& callback) { | 114 const SyncStatusCallback& callback) { |
| 113 ++task_scheduled_count_; | 115 ++task_scheduled_count_; |
| 114 if (is_idle_task) | 116 if (is_idle_task) |
| 115 ++idle_task_scheduled_count_; | 117 ++idle_task_scheduled_count_; |
| 116 base::MessageLoop::current()->PostTask( | 118 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 117 FROM_HERE, base::Bind(callback, status_to_return)); | 119 FROM_HERE, base::Bind(callback, status_to_return)); |
| 118 } | 120 } |
| 119 | 121 |
| 120 scoped_ptr<SyncTaskManager> task_manager_; | 122 scoped_ptr<SyncTaskManager> task_manager_; |
| 121 | 123 |
| 122 int maybe_schedule_next_task_count_; | 124 int maybe_schedule_next_task_count_; |
| 123 int task_scheduled_count_; | 125 int task_scheduled_count_; |
| 124 int idle_task_scheduled_count_; | 126 int idle_task_scheduled_count_; |
| 125 | 127 |
| 126 SyncStatusCode last_operation_status_; | 128 SyncStatusCode last_operation_status_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 137 weak_ptr_factory_(this) { | 139 weak_ptr_factory_(this) { |
| 138 DCHECK(task_started_); | 140 DCHECK(task_started_); |
| 139 DCHECK(task_completed_); | 141 DCHECK(task_completed_); |
| 140 } | 142 } |
| 141 | 143 |
| 142 ~MultihopSyncTask() override {} | 144 ~MultihopSyncTask() override {} |
| 143 | 145 |
| 144 void RunExclusive(const SyncStatusCallback& callback) override { | 146 void RunExclusive(const SyncStatusCallback& callback) override { |
| 145 DCHECK(!*task_started_); | 147 DCHECK(!*task_started_); |
| 146 *task_started_ = true; | 148 *task_started_ = true; |
| 147 base::MessageLoop::current()->PostTask( | 149 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 148 FROM_HERE, base::Bind(&MultihopSyncTask::CompleteTask, | 150 FROM_HERE, base::Bind(&MultihopSyncTask::CompleteTask, |
| 149 weak_ptr_factory_.GetWeakPtr(), callback)); | 151 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 150 } | 152 } |
| 151 | 153 |
| 152 private: | 154 private: |
| 153 void CompleteTask(const SyncStatusCallback& callback) { | 155 void CompleteTask(const SyncStatusCallback& callback) { |
| 154 DCHECK(*task_started_); | 156 DCHECK(*task_started_); |
| 155 DCHECK(!*task_completed_); | 157 DCHECK(!*task_completed_); |
| 156 *task_completed_ = true; | 158 *task_completed_ = true; |
| 157 callback.Run(SYNC_STATUS_OK); | 159 callback.Run(SYNC_STATUS_OK); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 base::Bind(&BackgroundTask::RunAsBackgroundTask, | 200 base::Bind(&BackgroundTask::RunAsBackgroundTask, |
| 199 weak_ptr_factory_.GetWeakPtr())); | 201 weak_ptr_factory_.GetWeakPtr())); |
| 200 } | 202 } |
| 201 | 203 |
| 202 private: | 204 private: |
| 203 void RunAsBackgroundTask(scoped_ptr<SyncTaskToken> token) { | 205 void RunAsBackgroundTask(scoped_ptr<SyncTaskToken> token) { |
| 204 ++(stats_->running_background_task); | 206 ++(stats_->running_background_task); |
| 205 if (stats_->max_parallel_task < stats_->running_background_task) | 207 if (stats_->max_parallel_task < stats_->running_background_task) |
| 206 stats_->max_parallel_task = stats_->running_background_task; | 208 stats_->max_parallel_task = stats_->running_background_task; |
| 207 | 209 |
| 208 base::MessageLoop::current()->PostTask( | 210 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 209 FROM_HERE, | 211 FROM_HERE, |
| 210 base::Bind(&BackgroundTask::CompleteTask, | 212 base::Bind(&BackgroundTask::CompleteTask, |
| 211 weak_ptr_factory_.GetWeakPtr(), | 213 weak_ptr_factory_.GetWeakPtr(), base::Passed(&token))); |
| 212 base::Passed(&token))); | |
| 213 } | 214 } |
| 214 | 215 |
| 215 void CompleteTask(scoped_ptr<SyncTaskToken> token) { | 216 void CompleteTask(scoped_ptr<SyncTaskToken> token) { |
| 216 ++(stats_->finished_task); | 217 ++(stats_->finished_task); |
| 217 --(stats_->running_background_task); | 218 --(stats_->running_background_task); |
| 218 SyncTaskManager::NotifyTaskDone(token.Pass(), SYNC_STATUS_OK); | 219 SyncTaskManager::NotifyTaskDone(token.Pass(), SYNC_STATUS_OK); |
| 219 } | 220 } |
| 220 | 221 |
| 221 std::string app_id_; | 222 std::string app_id_; |
| 222 base::FilePath path_; | 223 base::FilePath path_; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 SyncTaskManager::UpdateTaskBlocker( | 271 SyncTaskManager::UpdateTaskBlocker( |
| 271 token.Pass(), task_blocker.Pass(), | 272 token.Pass(), task_blocker.Pass(), |
| 272 base::Bind(&BlockerUpdateTestHelper::UpdateBlockerSoon, | 273 base::Bind(&BlockerUpdateTestHelper::UpdateBlockerSoon, |
| 273 weak_ptr_factory_.GetWeakPtr(), | 274 weak_ptr_factory_.GetWeakPtr(), |
| 274 updating_to)); | 275 updating_to)); |
| 275 } | 276 } |
| 276 | 277 |
| 277 void UpdateBlockerSoon(const std::string& updated_to, | 278 void UpdateBlockerSoon(const std::string& updated_to, |
| 278 scoped_ptr<SyncTaskToken> token) { | 279 scoped_ptr<SyncTaskToken> token) { |
| 279 log_->push_back(name_ + ": updated to " + updated_to); | 280 log_->push_back(name_ + ": updated to " + updated_to); |
| 280 base::MessageLoop::current()->PostTask( | 281 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 281 FROM_HERE, | 282 FROM_HERE, |
| 282 base::Bind(&BlockerUpdateTestHelper::UpdateBlocker, | 283 base::Bind(&BlockerUpdateTestHelper::UpdateBlocker, |
| 283 weak_ptr_factory_.GetWeakPtr(), base::Passed(&token))); | 284 weak_ptr_factory_.GetWeakPtr(), base::Passed(&token))); |
| 284 } | 285 } |
| 285 | 286 |
| 286 std::string name_; | 287 std::string name_; |
| 287 std::string app_id_; | 288 std::string app_id_; |
| 288 std::deque<std::string> paths_; | 289 std::deque<std::string> paths_; |
| 289 Log* log_; | 290 Log* log_; |
| 290 | 291 |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 | 670 |
| 670 EXPECT_EQ("task1: finished", log[i++]); | 671 EXPECT_EQ("task1: finished", log[i++]); |
| 671 | 672 |
| 672 EXPECT_EQ("task2: updating to /hoge/fuga/piyo", log[i++]); | 673 EXPECT_EQ("task2: updating to /hoge/fuga/piyo", log[i++]); |
| 673 EXPECT_EQ("task2: updated to /hoge/fuga/piyo", log[i++]); | 674 EXPECT_EQ("task2: updated to /hoge/fuga/piyo", log[i++]); |
| 674 EXPECT_EQ("task2: finished", log[i++]); | 675 EXPECT_EQ("task2: finished", log[i++]); |
| 675 } | 676 } |
| 676 | 677 |
| 677 } // namespace drive_backend | 678 } // namespace drive_backend |
| 678 } // namespace sync_file_system | 679 } // namespace sync_file_system |
| OLD | NEW |