| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/sync/engine_impl/sync_scheduler_impl.h" | 5 #include "components/sync/engine_impl/sync_scheduler_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 std::vector<SyncEngineEventListener*>(), nullptr, | 152 std::vector<SyncEngineEventListener*>(), nullptr, |
| 153 model_type_registry_.get(), | 153 model_type_registry_.get(), |
| 154 true, // enable keystore encryption | 154 true, // enable keystore encryption |
| 155 false, // force enable pre-commit GU avoidance | 155 false, // force enable pre-commit GU avoidance |
| 156 "fake_invalidator_client_id"); | 156 "fake_invalidator_client_id"); |
| 157 context_->SetRoutingInfo(routing_info_); | 157 context_->SetRoutingInfo(routing_info_); |
| 158 context_->set_notifications_enabled(true); | 158 context_->set_notifications_enabled(true); |
| 159 context_->set_account_name("Test"); | 159 context_->set_account_name("Test"); |
| 160 scheduler_ = base::MakeUnique<SyncSchedulerImpl>( | 160 scheduler_ = base::MakeUnique<SyncSchedulerImpl>( |
| 161 "TestSyncScheduler", BackoffDelayProvider::FromDefaults(), context(), | 161 "TestSyncScheduler", BackoffDelayProvider::FromDefaults(), context(), |
| 162 syncer_); | 162 syncer_, false); |
| 163 scheduler_->SetDefaultNudgeDelay(default_delay()); | 163 scheduler_->SetDefaultNudgeDelay(default_delay()); |
| 164 } | 164 } |
| 165 | 165 |
| 166 SyncSchedulerImpl* scheduler() { return scheduler_.get(); } | 166 SyncSchedulerImpl* scheduler() { return scheduler_.get(); } |
| 167 const ModelSafeRoutingInfo& routing_info() { return routing_info_; } | 167 const ModelSafeRoutingInfo& routing_info() { return routing_info_; } |
| 168 MockSyncer* syncer() { return syncer_; } | 168 MockSyncer* syncer() { return syncer_; } |
| 169 MockDelayProvider* delay() { return delay_; } | 169 MockDelayProvider* delay() { return delay_; } |
| 170 MockConnectionManager* connection() { return connection_.get(); } | 170 MockConnectionManager* connection() { return connection_.get(); } |
| 171 TimeDelta default_delay() { return TimeDelta::FromSeconds(0); } | 171 TimeDelta default_delay() { return TimeDelta::FromSeconds(0); } |
| 172 TimeDelta long_delay() { return TimeDelta::FromSeconds(60); } | 172 TimeDelta long_delay() { return TimeDelta::FromSeconds(60); } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 } | 276 } |
| 277 | 277 |
| 278 void SetTypeBlockingMode(ModelType type, WaitInterval::BlockingMode mode) { | 278 void SetTypeBlockingMode(ModelType type, WaitInterval::BlockingMode mode) { |
| 279 NudgeTracker::TypeTrackerMap::const_iterator tracker_it = | 279 NudgeTracker::TypeTrackerMap::const_iterator tracker_it = |
| 280 scheduler_->nudge_tracker_.type_trackers_.find(type); | 280 scheduler_->nudge_tracker_.type_trackers_.find(type); |
| 281 DCHECK(tracker_it != scheduler_->nudge_tracker_.type_trackers_.end()); | 281 DCHECK(tracker_it != scheduler_->nudge_tracker_.type_trackers_.end()); |
| 282 DCHECK(tracker_it->second->wait_interval_.get()); | 282 DCHECK(tracker_it->second->wait_interval_.get()); |
| 283 tracker_it->second->wait_interval_->mode = mode; | 283 tracker_it->second->wait_interval_->mode = mode; |
| 284 } | 284 } |
| 285 | 285 |
| 286 void NewSchedulerForLocalBackend() { |
| 287 // The old syncer is destroyed with the scheduler that owns it. |
| 288 syncer_ = new testing::StrictMock<MockSyncer>(); |
| 289 scheduler_ = base::MakeUnique<SyncSchedulerImpl>( |
| 290 "TestSyncScheduler", BackoffDelayProvider::FromDefaults(), context(), |
| 291 syncer_, true); |
| 292 scheduler_->SetDefaultNudgeDelay(default_delay()); |
| 293 } |
| 294 |
| 286 private: | 295 private: |
| 287 syncable::Directory* directory() { | 296 syncable::Directory* directory() { |
| 288 return test_user_share_.user_share()->directory.get(); | 297 return test_user_share_.user_share()->directory.get(); |
| 289 } | 298 } |
| 290 | 299 |
| 291 base::MessageLoop loop_; | 300 base::MessageLoop loop_; |
| 292 TestUserShare test_user_share_; | 301 TestUserShare test_user_share_; |
| 293 CancelationSignal cancelation_signal_; | 302 CancelationSignal cancelation_signal_; |
| 294 std::unique_ptr<MockConnectionManager> connection_; | 303 std::unique_ptr<MockConnectionManager> connection_; |
| 295 std::unique_ptr<ModelTypeRegistry> model_type_registry_; | 304 std::unique_ptr<ModelTypeRegistry> model_type_registry_; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 GetUpdatesCallerInfo::RECONFIGURATION, model_types, | 470 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 462 TypesToRoutingInfo(model_types), | 471 TypesToRoutingInfo(model_types), |
| 463 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 472 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 464 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 473 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 465 scheduler()->ScheduleConfiguration(params); | 474 scheduler()->ScheduleConfiguration(params); |
| 466 PumpLoop(); | 475 PumpLoop(); |
| 467 ASSERT_EQ(0, ready_counter.times_called()); | 476 ASSERT_EQ(0, ready_counter.times_called()); |
| 468 ASSERT_EQ(0, retry_counter.times_called()); | 477 ASSERT_EQ(0, retry_counter.times_called()); |
| 469 } | 478 } |
| 470 | 479 |
| 480 // Verify that in the absence of valid auth token the command will fail. |
| 481 TEST_F(SyncSchedulerImplTest, ConfigNoAuthToken) { |
| 482 SyncShareTimes times; |
| 483 const ModelTypeSet model_types(THEMES); |
| 484 |
| 485 connection()->ResetAuthToken(); |
| 486 |
| 487 StartSyncConfiguration(); |
| 488 |
| 489 CallbackCounter ready_counter; |
| 490 CallbackCounter retry_counter; |
| 491 ConfigurationParams params( |
| 492 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 493 TypesToRoutingInfo(model_types), |
| 494 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 495 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 496 scheduler()->ScheduleConfiguration(params); |
| 497 PumpLoop(); |
| 498 ASSERT_EQ(0, ready_counter.times_called()); |
| 499 ASSERT_EQ(1, retry_counter.times_called()); |
| 500 } |
| 501 |
| 502 // Verify that in the absence of valid auth token the command will pass if local |
| 503 // sync backend is used. |
| 504 TEST_F(SyncSchedulerImplTest, ConfigNoAuthTokenLocalSync) { |
| 505 SyncShareTimes times; |
| 506 const ModelTypeSet model_types(THEMES); |
| 507 |
| 508 NewSchedulerForLocalBackend(); |
| 509 connection()->ResetAuthToken(); |
| 510 |
| 511 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 512 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), |
| 513 RecordSyncShare(×, true))); |
| 514 |
| 515 StartSyncConfiguration(); |
| 516 |
| 517 CallbackCounter ready_counter; |
| 518 CallbackCounter retry_counter; |
| 519 ConfigurationParams params( |
| 520 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 521 TypesToRoutingInfo(model_types), |
| 522 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 523 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 524 scheduler()->ScheduleConfiguration(params); |
| 525 PumpLoop(); |
| 526 ASSERT_EQ(1, ready_counter.times_called()); |
| 527 ASSERT_EQ(0, retry_counter.times_called()); |
| 528 } |
| 529 |
| 471 // Issue a nudge when the config has failed. Make sure both the config and | 530 // Issue a nudge when the config has failed. Make sure both the config and |
| 472 // nudge are executed. | 531 // nudge are executed. |
| 473 TEST_F(SyncSchedulerImplTest, NudgeWithConfigWithBackingOff) { | 532 TEST_F(SyncSchedulerImplTest, NudgeWithConfigWithBackingOff) { |
| 474 const ModelTypeSet model_types(THEMES); | 533 const ModelTypeSet model_types(THEMES); |
| 475 UseMockDelayProvider(); | 534 UseMockDelayProvider(); |
| 476 EXPECT_CALL(*delay(), GetDelay(_)) | 535 EXPECT_CALL(*delay(), GetDelay(_)) |
| 477 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); | 536 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); |
| 478 SyncShareTimes times; | 537 SyncShareTimes times; |
| 479 | 538 |
| 480 StartSyncConfiguration(); | 539 StartSyncConfiguration(); |
| (...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1719 | 1778 |
| 1720 // The Exponential backoff should be between previous backoff 1.5 and 2.5 | 1779 // The Exponential backoff should be between previous backoff 1.5 and 2.5 |
| 1721 // times. | 1780 // times. |
| 1722 EXPECT_LE(first_blocking_time * 1.5, second_blocking_time); | 1781 EXPECT_LE(first_blocking_time * 1.5, second_blocking_time); |
| 1723 EXPECT_GE(first_blocking_time * 2.5, second_blocking_time); | 1782 EXPECT_GE(first_blocking_time * 2.5, second_blocking_time); |
| 1724 | 1783 |
| 1725 StopSyncScheduler(); | 1784 StopSyncScheduler(); |
| 1726 } | 1785 } |
| 1727 | 1786 |
| 1728 } // namespace syncer | 1787 } // namespace syncer |
| OLD | NEW |