| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 75 } |
| 76 ~TaskManagerClient() override {} | 76 ~TaskManagerClient() override {} |
| 77 | 77 |
| 78 // DriveFileSyncManager::Client overrides. | 78 // DriveFileSyncManager::Client overrides. |
| 79 void MaybeScheduleNextTask() override { ++maybe_schedule_next_task_count_; } | 79 void MaybeScheduleNextTask() override { ++maybe_schedule_next_task_count_; } |
| 80 void NotifyLastOperationStatus(SyncStatusCode last_operation_status, | 80 void NotifyLastOperationStatus(SyncStatusCode last_operation_status, |
| 81 bool last_operation_used_network) override { | 81 bool last_operation_used_network) override { |
| 82 last_operation_status_ = last_operation_status; | 82 last_operation_status_ = last_operation_status; |
| 83 } | 83 } |
| 84 | 84 |
| 85 void RecordTaskLog(scoped_ptr<TaskLogger::TaskLog>) override {} | 85 void RecordTaskLog(std::unique_ptr<TaskLogger::TaskLog>) override {} |
| 86 | 86 |
| 87 void ScheduleTask(SyncStatusCode status_to_return, | 87 void ScheduleTask(SyncStatusCode status_to_return, |
| 88 const SyncStatusCallback& callback) { | 88 const SyncStatusCallback& callback) { |
| 89 task_manager_->ScheduleTask( | 89 task_manager_->ScheduleTask( |
| 90 FROM_HERE, | 90 FROM_HERE, |
| 91 base::Bind(&TaskManagerClient::DoTask, AsWeakPtr(), | 91 base::Bind(&TaskManagerClient::DoTask, AsWeakPtr(), |
| 92 status_to_return, false /* idle */), | 92 status_to_return, false /* idle */), |
| 93 SyncTaskManager::PRIORITY_MED, | 93 SyncTaskManager::PRIORITY_MED, |
| 94 callback); | 94 callback); |
| 95 } | 95 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 115 void DoTask(SyncStatusCode status_to_return, | 115 void DoTask(SyncStatusCode status_to_return, |
| 116 bool is_idle_task, | 116 bool is_idle_task, |
| 117 const SyncStatusCallback& callback) { | 117 const SyncStatusCallback& callback) { |
| 118 ++task_scheduled_count_; | 118 ++task_scheduled_count_; |
| 119 if (is_idle_task) | 119 if (is_idle_task) |
| 120 ++idle_task_scheduled_count_; | 120 ++idle_task_scheduled_count_; |
| 121 base::ThreadTaskRunnerHandle::Get()->PostTask( | 121 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 122 FROM_HERE, base::Bind(callback, status_to_return)); | 122 FROM_HERE, base::Bind(callback, status_to_return)); |
| 123 } | 123 } |
| 124 | 124 |
| 125 scoped_ptr<SyncTaskManager> task_manager_; | 125 std::unique_ptr<SyncTaskManager> task_manager_; |
| 126 | 126 |
| 127 int maybe_schedule_next_task_count_; | 127 int maybe_schedule_next_task_count_; |
| 128 int task_scheduled_count_; | 128 int task_scheduled_count_; |
| 129 int idle_task_scheduled_count_; | 129 int idle_task_scheduled_count_; |
| 130 | 130 |
| 131 SyncStatusCode last_operation_status_; | 131 SyncStatusCode last_operation_status_; |
| 132 | 132 |
| 133 DISALLOW_COPY_AND_ASSIGN(TaskManagerClient); | 133 DISALLOW_COPY_AND_ASSIGN(TaskManagerClient); |
| 134 }; | 134 }; |
| 135 | 135 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 const base::FilePath& path, | 186 const base::FilePath& path, |
| 187 Stats* stats) | 187 Stats* stats) |
| 188 : app_id_(app_id), | 188 : app_id_(app_id), |
| 189 path_(path), | 189 path_(path), |
| 190 stats_(stats), | 190 stats_(stats), |
| 191 weak_ptr_factory_(this) { | 191 weak_ptr_factory_(this) { |
| 192 } | 192 } |
| 193 | 193 |
| 194 ~BackgroundTask() override {} | 194 ~BackgroundTask() override {} |
| 195 | 195 |
| 196 void RunPreflight(scoped_ptr<SyncTaskToken> token) override { | 196 void RunPreflight(std::unique_ptr<SyncTaskToken> token) override { |
| 197 scoped_ptr<TaskBlocker> task_blocker(new TaskBlocker); | 197 std::unique_ptr<TaskBlocker> task_blocker(new TaskBlocker); |
| 198 task_blocker->app_id = app_id_; | 198 task_blocker->app_id = app_id_; |
| 199 task_blocker->paths.push_back(path_); | 199 task_blocker->paths.push_back(path_); |
| 200 | 200 |
| 201 SyncTaskManager::UpdateTaskBlocker( | 201 SyncTaskManager::UpdateTaskBlocker( |
| 202 std::move(token), std::move(task_blocker), | 202 std::move(token), std::move(task_blocker), |
| 203 base::Bind(&BackgroundTask::RunAsBackgroundTask, | 203 base::Bind(&BackgroundTask::RunAsBackgroundTask, |
| 204 weak_ptr_factory_.GetWeakPtr())); | 204 weak_ptr_factory_.GetWeakPtr())); |
| 205 } | 205 } |
| 206 | 206 |
| 207 private: | 207 private: |
| 208 void RunAsBackgroundTask(scoped_ptr<SyncTaskToken> token) { | 208 void RunAsBackgroundTask(std::unique_ptr<SyncTaskToken> token) { |
| 209 ++(stats_->running_background_task); | 209 ++(stats_->running_background_task); |
| 210 if (stats_->max_parallel_task < stats_->running_background_task) | 210 if (stats_->max_parallel_task < stats_->running_background_task) |
| 211 stats_->max_parallel_task = stats_->running_background_task; | 211 stats_->max_parallel_task = stats_->running_background_task; |
| 212 | 212 |
| 213 base::ThreadTaskRunnerHandle::Get()->PostTask( | 213 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 214 FROM_HERE, | 214 FROM_HERE, |
| 215 base::Bind(&BackgroundTask::CompleteTask, | 215 base::Bind(&BackgroundTask::CompleteTask, |
| 216 weak_ptr_factory_.GetWeakPtr(), base::Passed(&token))); | 216 weak_ptr_factory_.GetWeakPtr(), base::Passed(&token))); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void CompleteTask(scoped_ptr<SyncTaskToken> token) { | 219 void CompleteTask(std::unique_ptr<SyncTaskToken> token) { |
| 220 ++(stats_->finished_task); | 220 ++(stats_->finished_task); |
| 221 --(stats_->running_background_task); | 221 --(stats_->running_background_task); |
| 222 SyncTaskManager::NotifyTaskDone(std::move(token), SYNC_STATUS_OK); | 222 SyncTaskManager::NotifyTaskDone(std::move(token), SYNC_STATUS_OK); |
| 223 } | 223 } |
| 224 | 224 |
| 225 std::string app_id_; | 225 std::string app_id_; |
| 226 base::FilePath path_; | 226 base::FilePath path_; |
| 227 Stats* stats_; | 227 Stats* stats_; |
| 228 | 228 |
| 229 base::WeakPtrFactory<BackgroundTask> weak_ptr_factory_; | 229 base::WeakPtrFactory<BackgroundTask> weak_ptr_factory_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 241 Log* log) | 241 Log* log) |
| 242 : name_(name), | 242 : name_(name), |
| 243 app_id_(app_id), | 243 app_id_(app_id), |
| 244 paths_(paths.begin(), paths.end()), | 244 paths_(paths.begin(), paths.end()), |
| 245 log_(log), | 245 log_(log), |
| 246 weak_ptr_factory_(this) { | 246 weak_ptr_factory_(this) { |
| 247 } | 247 } |
| 248 | 248 |
| 249 ~BlockerUpdateTestHelper() override {} | 249 ~BlockerUpdateTestHelper() override {} |
| 250 | 250 |
| 251 void RunPreflight(scoped_ptr<SyncTaskToken> token) override { | 251 void RunPreflight(std::unique_ptr<SyncTaskToken> token) override { |
| 252 UpdateBlocker(std::move(token)); | 252 UpdateBlocker(std::move(token)); |
| 253 } | 253 } |
| 254 | 254 |
| 255 private: | 255 private: |
| 256 void UpdateBlocker(scoped_ptr<SyncTaskToken> token) { | 256 void UpdateBlocker(std::unique_ptr<SyncTaskToken> token) { |
| 257 if (paths_.empty()) { | 257 if (paths_.empty()) { |
| 258 log_->push_back(name_ + ": finished"); | 258 log_->push_back(name_ + ": finished"); |
| 259 SyncTaskManager::NotifyTaskDone(std::move(token), SYNC_STATUS_OK); | 259 SyncTaskManager::NotifyTaskDone(std::move(token), 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<TaskBlocker> task_blocker(new TaskBlocker); | 268 std::unique_ptr<TaskBlocker> task_blocker(new TaskBlocker); |
| 269 task_blocker->app_id = app_id_; | 269 task_blocker->app_id = app_id_; |
| 270 task_blocker->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::UpdateTaskBlocker( | 274 SyncTaskManager::UpdateTaskBlocker( |
| 275 std::move(token), std::move(task_blocker), | 275 std::move(token), std::move(task_blocker), |
| 276 base::Bind(&BlockerUpdateTestHelper::UpdateBlockerSoon, | 276 base::Bind(&BlockerUpdateTestHelper::UpdateBlockerSoon, |
| 277 weak_ptr_factory_.GetWeakPtr(), updating_to)); | 277 weak_ptr_factory_.GetWeakPtr(), updating_to)); |
| 278 } | 278 } |
| 279 | 279 |
| 280 void UpdateBlockerSoon(const std::string& updated_to, | 280 void UpdateBlockerSoon(const std::string& updated_to, |
| 281 scoped_ptr<SyncTaskToken> token) { | 281 std::unique_ptr<SyncTaskToken> token) { |
| 282 log_->push_back(name_ + ": updated to " + updated_to); | 282 log_->push_back(name_ + ": updated to " + updated_to); |
| 283 base::ThreadTaskRunnerHandle::Get()->PostTask( | 283 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 284 FROM_HERE, | 284 FROM_HERE, |
| 285 base::Bind(&BlockerUpdateTestHelper::UpdateBlocker, | 285 base::Bind(&BlockerUpdateTestHelper::UpdateBlocker, |
| 286 weak_ptr_factory_.GetWeakPtr(), base::Passed(&token))); | 286 weak_ptr_factory_.GetWeakPtr(), base::Passed(&token))); |
| 287 } | 287 } |
| 288 | 288 |
| 289 std::string name_; | 289 std::string name_; |
| 290 std::string app_id_; | 290 std::string app_id_; |
| 291 std::deque<std::string> paths_; | 291 std::deque<std::string> paths_; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 bool task_completed = false; | 394 bool task_completed = false; |
| 395 | 395 |
| 396 { | 396 { |
| 397 SyncTaskManager task_manager(base::WeakPtr<SyncTaskManager::Client>(), | 397 SyncTaskManager task_manager(base::WeakPtr<SyncTaskManager::Client>(), |
| 398 0 /* maximum_background_task */, | 398 0 /* maximum_background_task */, |
| 399 base::ThreadTaskRunnerHandle::Get(), | 399 base::ThreadTaskRunnerHandle::Get(), |
| 400 nullptr /* worker_pool */); | 400 nullptr /* worker_pool */); |
| 401 task_manager.Initialize(SYNC_STATUS_OK); | 401 task_manager.Initialize(SYNC_STATUS_OK); |
| 402 message_loop.RunUntilIdle(); | 402 message_loop.RunUntilIdle(); |
| 403 task_manager.ScheduleSyncTask( | 403 task_manager.ScheduleSyncTask( |
| 404 FROM_HERE, | 404 FROM_HERE, std::unique_ptr<SyncTask>( |
| 405 scoped_ptr<SyncTask>(new MultihopSyncTask( | 405 new MultihopSyncTask(&task_started, &task_completed)), |
| 406 &task_started, &task_completed)), | |
| 407 SyncTaskManager::PRIORITY_MED, | 406 SyncTaskManager::PRIORITY_MED, |
| 408 base::Bind(&IncrementAndAssign, 0, &callback_count, &status)); | 407 base::Bind(&IncrementAndAssign, 0, &callback_count, &status)); |
| 409 } | 408 } |
| 410 message_loop.RunUntilIdle(); | 409 message_loop.RunUntilIdle(); |
| 411 | 410 |
| 412 EXPECT_EQ(0, callback_count); | 411 EXPECT_EQ(0, callback_count); |
| 413 EXPECT_EQ(SYNC_STATUS_UNKNOWN, status); | 412 EXPECT_EQ(SYNC_STATUS_UNKNOWN, status); |
| 414 EXPECT_TRUE(task_started); | 413 EXPECT_TRUE(task_started); |
| 415 EXPECT_FALSE(task_completed); | 414 EXPECT_FALSE(task_completed); |
| 416 } | 415 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 base::MessageLoop message_loop; | 480 base::MessageLoop message_loop; |
| 482 SyncTaskManager task_manager(base::WeakPtr<SyncTaskManager::Client>(), | 481 SyncTaskManager task_manager(base::WeakPtr<SyncTaskManager::Client>(), |
| 483 10 /* maximum_background_task */, | 482 10 /* maximum_background_task */, |
| 484 base::ThreadTaskRunnerHandle::Get(), | 483 base::ThreadTaskRunnerHandle::Get(), |
| 485 nullptr /* worker_pool */); | 484 nullptr /* worker_pool */); |
| 486 task_manager.Initialize(SYNC_STATUS_OK); | 485 task_manager.Initialize(SYNC_STATUS_OK); |
| 487 | 486 |
| 488 SyncStatusCode status = SYNC_STATUS_FAILED; | 487 SyncStatusCode status = SYNC_STATUS_FAILED; |
| 489 BackgroundTask::Stats stats; | 488 BackgroundTask::Stats stats; |
| 490 task_manager.ScheduleSyncTask( | 489 task_manager.ScheduleSyncTask( |
| 491 FROM_HERE, | 490 FROM_HERE, std::unique_ptr<SyncTask>(new BackgroundTask( |
| 492 scoped_ptr<SyncTask>(new BackgroundTask( | 491 "app_id", MAKE_PATH("/hoge/fuga"), &stats)), |
| 493 "app_id", MAKE_PATH("/hoge/fuga"), | 492 SyncTaskManager::PRIORITY_MED, CreateResultReceiver(&status)); |
| 494 &stats)), | |
| 495 SyncTaskManager::PRIORITY_MED, | |
| 496 CreateResultReceiver(&status)); | |
| 497 | 493 |
| 498 task_manager.ScheduleSyncTask( | 494 task_manager.ScheduleSyncTask( |
| 499 FROM_HERE, | 495 FROM_HERE, std::unique_ptr<SyncTask>( |
| 500 scoped_ptr<SyncTask>(new BackgroundTask( | 496 new BackgroundTask("app_id", MAKE_PATH("/hoge"), &stats)), |
| 501 "app_id", MAKE_PATH("/hoge"), | 497 SyncTaskManager::PRIORITY_MED, CreateResultReceiver(&status)); |
| 502 &stats)), | |
| 503 SyncTaskManager::PRIORITY_MED, | |
| 504 CreateResultReceiver(&status)); | |
| 505 | 498 |
| 506 task_manager.ScheduleSyncTask( | 499 task_manager.ScheduleSyncTask( |
| 507 FROM_HERE, | 500 FROM_HERE, std::unique_ptr<SyncTask>(new BackgroundTask( |
| 508 scoped_ptr<SyncTask>(new BackgroundTask( | 501 "app_id", MAKE_PATH("/hoge/fuga/piyo"), &stats)), |
| 509 "app_id", MAKE_PATH("/hoge/fuga/piyo"), | 502 SyncTaskManager::PRIORITY_MED, CreateResultReceiver(&status)); |
| 510 &stats)), | |
| 511 SyncTaskManager::PRIORITY_MED, | |
| 512 CreateResultReceiver(&status)); | |
| 513 | 503 |
| 514 message_loop.RunUntilIdle(); | 504 message_loop.RunUntilIdle(); |
| 515 | 505 |
| 516 EXPECT_EQ(SYNC_STATUS_OK, status); | 506 EXPECT_EQ(SYNC_STATUS_OK, status); |
| 517 EXPECT_EQ(0, stats.running_background_task); | 507 EXPECT_EQ(0, stats.running_background_task); |
| 518 EXPECT_EQ(3, stats.finished_task); | 508 EXPECT_EQ(3, stats.finished_task); |
| 519 EXPECT_EQ(1, stats.max_parallel_task); | 509 EXPECT_EQ(1, stats.max_parallel_task); |
| 520 } | 510 } |
| 521 | 511 |
| 522 TEST(SyncTaskManagerTest, BackgroundTask_Parallel) { | 512 TEST(SyncTaskManagerTest, BackgroundTask_Parallel) { |
| 523 base::MessageLoop message_loop; | 513 base::MessageLoop message_loop; |
| 524 SyncTaskManager task_manager(base::WeakPtr<SyncTaskManager::Client>(), | 514 SyncTaskManager task_manager(base::WeakPtr<SyncTaskManager::Client>(), |
| 525 10 /* maximum_background_task */, | 515 10 /* maximum_background_task */, |
| 526 base::ThreadTaskRunnerHandle::Get(), | 516 base::ThreadTaskRunnerHandle::Get(), |
| 527 nullptr /* worker_pool */); | 517 nullptr /* worker_pool */); |
| 528 task_manager.Initialize(SYNC_STATUS_OK); | 518 task_manager.Initialize(SYNC_STATUS_OK); |
| 529 | 519 |
| 530 SyncStatusCode status = SYNC_STATUS_FAILED; | 520 SyncStatusCode status = SYNC_STATUS_FAILED; |
| 531 BackgroundTask::Stats stats; | 521 BackgroundTask::Stats stats; |
| 532 task_manager.ScheduleSyncTask( | 522 task_manager.ScheduleSyncTask( |
| 533 FROM_HERE, | 523 FROM_HERE, std::unique_ptr<SyncTask>( |
| 534 scoped_ptr<SyncTask>(new BackgroundTask( | 524 new BackgroundTask("app_id", MAKE_PATH("/hoge"), &stats)), |
| 535 "app_id", MAKE_PATH("/hoge"), | 525 SyncTaskManager::PRIORITY_MED, CreateResultReceiver(&status)); |
| 536 &stats)), | |
| 537 SyncTaskManager::PRIORITY_MED, | |
| 538 CreateResultReceiver(&status)); | |
| 539 | 526 |
| 540 task_manager.ScheduleSyncTask( | 527 task_manager.ScheduleSyncTask( |
| 541 FROM_HERE, | 528 FROM_HERE, std::unique_ptr<SyncTask>( |
| 542 scoped_ptr<SyncTask>(new BackgroundTask( | 529 new BackgroundTask("app_id", MAKE_PATH("/fuga"), &stats)), |
| 543 "app_id", MAKE_PATH("/fuga"), | 530 SyncTaskManager::PRIORITY_MED, CreateResultReceiver(&status)); |
| 544 &stats)), | |
| 545 SyncTaskManager::PRIORITY_MED, | |
| 546 CreateResultReceiver(&status)); | |
| 547 | 531 |
| 548 task_manager.ScheduleSyncTask( | 532 task_manager.ScheduleSyncTask( |
| 549 FROM_HERE, | 533 FROM_HERE, std::unique_ptr<SyncTask>( |
| 550 scoped_ptr<SyncTask>(new BackgroundTask( | 534 new BackgroundTask("app_id", MAKE_PATH("/piyo"), &stats)), |
| 551 "app_id", MAKE_PATH("/piyo"), | 535 SyncTaskManager::PRIORITY_MED, CreateResultReceiver(&status)); |
| 552 &stats)), | |
| 553 SyncTaskManager::PRIORITY_MED, | |
| 554 CreateResultReceiver(&status)); | |
| 555 | 536 |
| 556 message_loop.RunUntilIdle(); | 537 message_loop.RunUntilIdle(); |
| 557 | 538 |
| 558 EXPECT_EQ(SYNC_STATUS_OK, status); | 539 EXPECT_EQ(SYNC_STATUS_OK, status); |
| 559 EXPECT_EQ(0, stats.running_background_task); | 540 EXPECT_EQ(0, stats.running_background_task); |
| 560 EXPECT_EQ(3, stats.finished_task); | 541 EXPECT_EQ(3, stats.finished_task); |
| 561 EXPECT_EQ(3, stats.max_parallel_task); | 542 EXPECT_EQ(3, stats.max_parallel_task); |
| 562 } | 543 } |
| 563 | 544 |
| 564 TEST(SyncTaskManagerTest, BackgroundTask_Throttled) { | 545 TEST(SyncTaskManagerTest, BackgroundTask_Throttled) { |
| 565 base::MessageLoop message_loop; | 546 base::MessageLoop message_loop; |
| 566 SyncTaskManager task_manager(base::WeakPtr<SyncTaskManager::Client>(), | 547 SyncTaskManager task_manager(base::WeakPtr<SyncTaskManager::Client>(), |
| 567 2 /* maximum_background_task */, | 548 2 /* maximum_background_task */, |
| 568 base::ThreadTaskRunnerHandle::Get(), | 549 base::ThreadTaskRunnerHandle::Get(), |
| 569 nullptr /* worker_pool */); | 550 nullptr /* worker_pool */); |
| 570 task_manager.Initialize(SYNC_STATUS_OK); | 551 task_manager.Initialize(SYNC_STATUS_OK); |
| 571 | 552 |
| 572 SyncStatusCode status = SYNC_STATUS_FAILED; | 553 SyncStatusCode status = SYNC_STATUS_FAILED; |
| 573 BackgroundTask::Stats stats; | 554 BackgroundTask::Stats stats; |
| 574 task_manager.ScheduleSyncTask( | 555 task_manager.ScheduleSyncTask( |
| 575 FROM_HERE, | 556 FROM_HERE, std::unique_ptr<SyncTask>( |
| 576 scoped_ptr<SyncTask>(new BackgroundTask( | 557 new BackgroundTask("app_id", MAKE_PATH("/hoge"), &stats)), |
| 577 "app_id", MAKE_PATH("/hoge"), | 558 SyncTaskManager::PRIORITY_MED, CreateResultReceiver(&status)); |
| 578 &stats)), | |
| 579 SyncTaskManager::PRIORITY_MED, | |
| 580 CreateResultReceiver(&status)); | |
| 581 | 559 |
| 582 task_manager.ScheduleSyncTask( | 560 task_manager.ScheduleSyncTask( |
| 583 FROM_HERE, | 561 FROM_HERE, std::unique_ptr<SyncTask>( |
| 584 scoped_ptr<SyncTask>(new BackgroundTask( | 562 new BackgroundTask("app_id", MAKE_PATH("/fuga"), &stats)), |
| 585 "app_id", MAKE_PATH("/fuga"), | 563 SyncTaskManager::PRIORITY_MED, CreateResultReceiver(&status)); |
| 586 &stats)), | |
| 587 SyncTaskManager::PRIORITY_MED, | |
| 588 CreateResultReceiver(&status)); | |
| 589 | 564 |
| 590 task_manager.ScheduleSyncTask( | 565 task_manager.ScheduleSyncTask( |
| 591 FROM_HERE, | 566 FROM_HERE, std::unique_ptr<SyncTask>( |
| 592 scoped_ptr<SyncTask>(new BackgroundTask( | 567 new BackgroundTask("app_id", MAKE_PATH("/piyo"), &stats)), |
| 593 "app_id", MAKE_PATH("/piyo"), | 568 SyncTaskManager::PRIORITY_MED, CreateResultReceiver(&status)); |
| 594 &stats)), | |
| 595 SyncTaskManager::PRIORITY_MED, | |
| 596 CreateResultReceiver(&status)); | |
| 597 | 569 |
| 598 message_loop.RunUntilIdle(); | 570 message_loop.RunUntilIdle(); |
| 599 | 571 |
| 600 EXPECT_EQ(SYNC_STATUS_OK, status); | 572 EXPECT_EQ(SYNC_STATUS_OK, status); |
| 601 EXPECT_EQ(0, stats.running_background_task); | 573 EXPECT_EQ(0, stats.running_background_task); |
| 602 EXPECT_EQ(3, stats.finished_task); | 574 EXPECT_EQ(3, stats.finished_task); |
| 603 EXPECT_EQ(2, stats.max_parallel_task); | 575 EXPECT_EQ(2, stats.max_parallel_task); |
| 604 } | 576 } |
| 605 | 577 |
| 606 TEST(SyncTaskManagerTest, UpdateTaskBlocker) { | 578 TEST(SyncTaskManagerTest, UpdateTaskBlocker) { |
| 607 base::MessageLoop message_loop; | 579 base::MessageLoop message_loop; |
| 608 SyncTaskManager task_manager(base::WeakPtr<SyncTaskManager::Client>(), | 580 SyncTaskManager task_manager(base::WeakPtr<SyncTaskManager::Client>(), |
| 609 10 /* maximum_background_task */, | 581 10 /* maximum_background_task */, |
| 610 base::ThreadTaskRunnerHandle::Get(), | 582 base::ThreadTaskRunnerHandle::Get(), |
| 611 nullptr /* worker_pool */); | 583 nullptr /* worker_pool */); |
| 612 task_manager.Initialize(SYNC_STATUS_OK); | 584 task_manager.Initialize(SYNC_STATUS_OK); |
| 613 | 585 |
| 614 SyncStatusCode status1 = SYNC_STATUS_FAILED; | 586 SyncStatusCode status1 = SYNC_STATUS_FAILED; |
| 615 SyncStatusCode status2 = SYNC_STATUS_FAILED; | 587 SyncStatusCode status2 = SYNC_STATUS_FAILED; |
| 616 BlockerUpdateTestHelper::Log log; | 588 BlockerUpdateTestHelper::Log log; |
| 617 | 589 |
| 618 { | 590 { |
| 619 std::vector<std::string> paths; | 591 std::vector<std::string> paths; |
| 620 paths.push_back("/foo/bar"); | 592 paths.push_back("/foo/bar"); |
| 621 paths.push_back("/foo"); | 593 paths.push_back("/foo"); |
| 622 paths.push_back("/hoge/fuga/piyo"); | 594 paths.push_back("/hoge/fuga/piyo"); |
| 623 task_manager.ScheduleSyncTask( | 595 task_manager.ScheduleSyncTask( |
| 624 FROM_HERE, | 596 FROM_HERE, std::unique_ptr<SyncTask>(new BlockerUpdateTestHelper( |
| 625 scoped_ptr<SyncTask>(new BlockerUpdateTestHelper( | 597 "task1", "app_id", paths, &log)), |
| 626 "task1", "app_id", paths, &log)), | 598 SyncTaskManager::PRIORITY_MED, CreateResultReceiver(&status1)); |
| 627 SyncTaskManager::PRIORITY_MED, | |
| 628 CreateResultReceiver(&status1)); | |
| 629 } | 599 } |
| 630 | 600 |
| 631 { | 601 { |
| 632 std::vector<std::string> paths; | 602 std::vector<std::string> paths; |
| 633 paths.push_back("/foo"); | 603 paths.push_back("/foo"); |
| 634 paths.push_back("/foo/bar"); | 604 paths.push_back("/foo/bar"); |
| 635 paths.push_back("/hoge/fuga/piyo"); | 605 paths.push_back("/hoge/fuga/piyo"); |
| 636 task_manager.ScheduleSyncTask( | 606 task_manager.ScheduleSyncTask( |
| 637 FROM_HERE, | 607 FROM_HERE, std::unique_ptr<SyncTask>(new BlockerUpdateTestHelper( |
| 638 scoped_ptr<SyncTask>(new BlockerUpdateTestHelper( | 608 "task2", "app_id", paths, &log)), |
| 639 "task2", "app_id", paths, &log)), | 609 SyncTaskManager::PRIORITY_MED, CreateResultReceiver(&status2)); |
| 640 SyncTaskManager::PRIORITY_MED, | |
| 641 CreateResultReceiver(&status2)); | |
| 642 } | 610 } |
| 643 | 611 |
| 644 message_loop.RunUntilIdle(); | 612 message_loop.RunUntilIdle(); |
| 645 | 613 |
| 646 EXPECT_EQ(SYNC_STATUS_OK, status1); | 614 EXPECT_EQ(SYNC_STATUS_OK, status1); |
| 647 EXPECT_EQ(SYNC_STATUS_OK, status2); | 615 EXPECT_EQ(SYNC_STATUS_OK, status2); |
| 648 | 616 |
| 649 ASSERT_EQ(14u, log.size()); | 617 ASSERT_EQ(14u, log.size()); |
| 650 int i = 0; | 618 int i = 0; |
| 651 | 619 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 672 | 640 |
| 673 EXPECT_EQ("task1: finished", log[i++]); | 641 EXPECT_EQ("task1: finished", log[i++]); |
| 674 | 642 |
| 675 EXPECT_EQ("task2: updating to /hoge/fuga/piyo", log[i++]); | 643 EXPECT_EQ("task2: updating to /hoge/fuga/piyo", log[i++]); |
| 676 EXPECT_EQ("task2: updated to /hoge/fuga/piyo", log[i++]); | 644 EXPECT_EQ("task2: updated to /hoge/fuga/piyo", log[i++]); |
| 677 EXPECT_EQ("task2: finished", log[i++]); | 645 EXPECT_EQ("task2: finished", log[i++]); |
| 678 } | 646 } |
| 679 | 647 |
| 680 } // namespace drive_backend | 648 } // namespace drive_backend |
| 681 } // namespace sync_file_system | 649 } // namespace sync_file_system |
| OLD | NEW |