| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 : app_id_(app_id), | 185 : app_id_(app_id), |
| 186 path_(path), | 186 path_(path), |
| 187 stats_(stats), | 187 stats_(stats), |
| 188 weak_ptr_factory_(this) { | 188 weak_ptr_factory_(this) { |
| 189 } | 189 } |
| 190 | 190 |
| 191 virtual ~BackgroundTask() { | 191 virtual ~BackgroundTask() { |
| 192 } | 192 } |
| 193 | 193 |
| 194 virtual void RunPreflight(scoped_ptr<SyncTaskToken> token) OVERRIDE { | 194 virtual void RunPreflight(scoped_ptr<SyncTaskToken> token) OVERRIDE { |
| 195 scoped_ptr<BlockingFactor> blocking_factor(new BlockingFactor); | 195 scoped_ptr<TaskBlocker> task_blocker(new TaskBlocker); |
| 196 blocking_factor->app_id = app_id_; | 196 task_blocker->app_id = app_id_; |
| 197 blocking_factor->paths.push_back(path_); | 197 task_blocker->paths.push_back(path_); |
| 198 | 198 |
| 199 SyncTaskManager::UpdateBlockingFactor( | 199 SyncTaskManager::UpdateTaskBlocker( |
| 200 token.Pass(), blocking_factor.Pass(), | 200 token.Pass(), task_blocker.Pass(), |
| 201 base::Bind(&BackgroundTask::RunAsBackgroundTask, | 201 base::Bind(&BackgroundTask::RunAsBackgroundTask, |
| 202 weak_ptr_factory_.GetWeakPtr())); | 202 weak_ptr_factory_.GetWeakPtr())); |
| 203 } | 203 } |
| 204 | 204 |
| 205 private: | 205 private: |
| 206 void RunAsBackgroundTask(scoped_ptr<SyncTaskToken> token) { | 206 void RunAsBackgroundTask(scoped_ptr<SyncTaskToken> token) { |
| 207 ++(stats_->running_background_task); | 207 ++(stats_->running_background_task); |
| 208 if (stats_->max_parallel_task < stats_->running_background_task) | 208 if (stats_->max_parallel_task < stats_->running_background_task) |
| 209 stats_->max_parallel_task = stats_->running_background_task; | 209 stats_->max_parallel_task = stats_->running_background_task; |
| 210 | 210 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 log_->push_back(name_ + ": finished"); | 258 log_->push_back(name_ + ": finished"); |
| 259 SyncTaskManager::NotifyTaskDone(token.Pass(), SYNC_STATUS_OK); | 259 SyncTaskManager::NotifyTaskDone(token.Pass(), SYNC_STATUS_OK); |
| 260 return; | 260 return; |
| 261 } | 261 } |
| 262 | 262 |
| 263 std::string updating_to = paths_.front(); | 263 std::string updating_to = paths_.front(); |
| 264 paths_.pop_front(); | 264 paths_.pop_front(); |
| 265 | 265 |
| 266 log_->push_back(name_ + ": updating to " + updating_to); | 266 log_->push_back(name_ + ": updating to " + updating_to); |
| 267 | 267 |
| 268 scoped_ptr<BlockingFactor> blocking_factor(new BlockingFactor); | 268 scoped_ptr<TaskBlocker> task_blocker(new TaskBlocker); |
| 269 blocking_factor->app_id = app_id_; | 269 task_blocker->app_id = app_id_; |
| 270 blocking_factor->paths.push_back( | 270 task_blocker->paths.push_back( |
| 271 base::FilePath(storage::VirtualPath::GetNormalizedFilePath( | 271 base::FilePath(storage::VirtualPath::GetNormalizedFilePath( |
| 272 base::FilePath::FromUTF8Unsafe(updating_to)))); | 272 base::FilePath::FromUTF8Unsafe(updating_to)))); |
| 273 | 273 |
| 274 SyncTaskManager::UpdateBlockingFactor( | 274 SyncTaskManager::UpdateTaskBlocker( |
| 275 token.Pass(), blocking_factor.Pass(), | 275 token.Pass(), task_blocker.Pass(), |
| 276 base::Bind(&BlockerUpdateTestHelper::UpdateBlockerSoon, | 276 base::Bind(&BlockerUpdateTestHelper::UpdateBlockerSoon, |
| 277 weak_ptr_factory_.GetWeakPtr(), | 277 weak_ptr_factory_.GetWeakPtr(), |
| 278 updating_to)); | 278 updating_to)); |
| 279 } | 279 } |
| 280 | 280 |
| 281 void UpdateBlockerSoon(const std::string& updated_to, | 281 void UpdateBlockerSoon(const std::string& updated_to, |
| 282 scoped_ptr<SyncTaskToken> token) { | 282 scoped_ptr<SyncTaskToken> token) { |
| 283 log_->push_back(name_ + ": updated to " + updated_to); | 283 log_->push_back(name_ + ": updated to " + updated_to); |
| 284 base::MessageLoop::current()->PostTask( | 284 base::MessageLoop::current()->PostTask( |
| 285 FROM_HERE, | 285 FROM_HERE, |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 CreateResultReceiver(&status)); | 592 CreateResultReceiver(&status)); |
| 593 | 593 |
| 594 message_loop.RunUntilIdle(); | 594 message_loop.RunUntilIdle(); |
| 595 | 595 |
| 596 EXPECT_EQ(SYNC_STATUS_OK, status); | 596 EXPECT_EQ(SYNC_STATUS_OK, status); |
| 597 EXPECT_EQ(0, stats.running_background_task); | 597 EXPECT_EQ(0, stats.running_background_task); |
| 598 EXPECT_EQ(3, stats.finished_task); | 598 EXPECT_EQ(3, stats.finished_task); |
| 599 EXPECT_EQ(2, stats.max_parallel_task); | 599 EXPECT_EQ(2, stats.max_parallel_task); |
| 600 } | 600 } |
| 601 | 601 |
| 602 TEST(SyncTaskManagerTest, UpdateBlockingFactor) { | 602 TEST(SyncTaskManagerTest, UpdateTaskBlocker) { |
| 603 base::MessageLoop message_loop; | 603 base::MessageLoop message_loop; |
| 604 SyncTaskManager task_manager(base::WeakPtr<SyncTaskManager::Client>(), | 604 SyncTaskManager task_manager(base::WeakPtr<SyncTaskManager::Client>(), |
| 605 10 /* maximum_background_task */, | 605 10 /* maximum_background_task */, |
| 606 base::ThreadTaskRunnerHandle::Get()); | 606 base::ThreadTaskRunnerHandle::Get()); |
| 607 task_manager.Initialize(SYNC_STATUS_OK); | 607 task_manager.Initialize(SYNC_STATUS_OK); |
| 608 | 608 |
| 609 SyncStatusCode status1 = SYNC_STATUS_FAILED; | 609 SyncStatusCode status1 = SYNC_STATUS_FAILED; |
| 610 SyncStatusCode status2 = SYNC_STATUS_FAILED; | 610 SyncStatusCode status2 = SYNC_STATUS_FAILED; |
| 611 BlockerUpdateTestHelper::Log log; | 611 BlockerUpdateTestHelper::Log log; |
| 612 | 612 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 | 667 |
| 668 EXPECT_EQ("task1: finished", log[i++]); | 668 EXPECT_EQ("task1: finished", log[i++]); |
| 669 | 669 |
| 670 EXPECT_EQ("task2: updating to /hoge/fuga/piyo", log[i++]); | 670 EXPECT_EQ("task2: updating to /hoge/fuga/piyo", log[i++]); |
| 671 EXPECT_EQ("task2: updated to /hoge/fuga/piyo", log[i++]); | 671 EXPECT_EQ("task2: updated to /hoge/fuga/piyo", log[i++]); |
| 672 EXPECT_EQ("task2: finished", log[i++]); | 672 EXPECT_EQ("task2: finished", log[i++]); |
| 673 } | 673 } |
| 674 | 674 |
| 675 } // namespace drive_backend | 675 } // namespace drive_backend |
| 676 } // namespace sync_file_system | 676 } // namespace sync_file_system |
| OLD | NEW |