| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/test/test_timeouts.h" | 17 #include "base/test/test_timeouts.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "components/sync/base/cancelation_signal.h" | 19 #include "components/sync/base/cancelation_signal.h" |
| 20 #include "components/sync/base/extensions_activity.h" | 20 #include "components/sync/base/extensions_activity.h" |
| 21 #include "components/sync/base/model_type_test_util.h" | 21 #include "components/sync/base/model_type_test_util.h" |
| 22 #include "components/sync/engine_impl/backoff_delay_provider.h" | 22 #include "components/sync/engine_impl/backoff_delay_provider.h" |
| 23 #include "components/sync/engine_impl/cycle/test_util.h" | 23 #include "components/sync/engine_impl/cycle/test_util.h" |
| 24 #include "components/sync/syncable/test_user_share.h" |
| 24 #include "components/sync/test/callback_counter.h" | 25 #include "components/sync/test/callback_counter.h" |
| 25 #include "components/sync/test/engine/fake_model_worker.h" | 26 #include "components/sync/test/engine/fake_model_worker.h" |
| 26 #include "components/sync/test/engine/mock_connection_manager.h" | 27 #include "components/sync/test/engine/mock_connection_manager.h" |
| 27 #include "components/sync/test/engine/mock_nudge_handler.h" | 28 #include "components/sync/test/engine/mock_nudge_handler.h" |
| 28 #include "components/sync/test/engine/test_directory_setter_upper.h" | |
| 29 #include "components/sync/test/mock_invalidation.h" | 29 #include "components/sync/test/mock_invalidation.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 32 |
| 33 using base::TimeDelta; | 33 using base::TimeDelta; |
| 34 using base::TimeTicks; | 34 using base::TimeTicks; |
| 35 using testing::_; | 35 using testing::_; |
| 36 using testing::AtLeast; | 36 using testing::AtLeast; |
| 37 using testing::DoAll; | 37 using testing::DoAll; |
| 38 using testing::Invoke; | 38 using testing::Invoke; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 public: | 117 public: |
| 118 MockDelayProvider() | 118 MockDelayProvider() |
| 119 : BackoffDelayProvider( | 119 : BackoffDelayProvider( |
| 120 TimeDelta::FromSeconds(kInitialBackoffRetrySeconds), | 120 TimeDelta::FromSeconds(kInitialBackoffRetrySeconds), |
| 121 TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)) {} | 121 TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)) {} |
| 122 | 122 |
| 123 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); | 123 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 void SetUp() override { | 126 void SetUp() override { |
| 127 dir_maker_.SetUp(); | 127 test_user_share_.SetUp(); |
| 128 syncer_ = new testing::StrictMock<MockSyncer>(); | 128 syncer_ = new testing::StrictMock<MockSyncer>(); |
| 129 delay_ = nullptr; | 129 delay_ = nullptr; |
| 130 extensions_activity_ = new ExtensionsActivity(); | 130 extensions_activity_ = new ExtensionsActivity(); |
| 131 | 131 |
| 132 routing_info_[THEMES] = GROUP_UI; | 132 routing_info_[THEMES] = GROUP_UI; |
| 133 routing_info_[TYPED_URLS] = GROUP_DB; | 133 routing_info_[TYPED_URLS] = GROUP_DB; |
| 134 routing_info_[THEMES] = GROUP_UI; | 134 routing_info_[THEMES] = GROUP_UI; |
| 135 routing_info_[NIGORI] = GROUP_PASSIVE; | 135 routing_info_[NIGORI] = GROUP_PASSIVE; |
| 136 | 136 |
| 137 workers_.clear(); | 137 workers_.clear(); |
| 138 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); | 138 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); |
| 139 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); | 139 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); |
| 140 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); | 140 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); |
| 141 | 141 |
| 142 connection_ = base::MakeUnique<MockConnectionManager>(directory(), | 142 connection_ = base::MakeUnique<MockConnectionManager>(directory(), |
| 143 &cancelation_signal_); | 143 &cancelation_signal_); |
| 144 connection_->SetServerReachable(); | 144 connection_->SetServerReachable(); |
| 145 | 145 |
| 146 model_type_registry_ = base::MakeUnique<ModelTypeRegistry>( | 146 model_type_registry_ = base::MakeUnique<ModelTypeRegistry>( |
| 147 workers_, directory(), &mock_nudge_handler_); | 147 workers_, test_user_share_.user_share(), &mock_nudge_handler_, |
| 148 UssMigrator()); |
| 148 | 149 |
| 149 context_ = base::MakeUnique<SyncCycleContext>( | 150 context_ = base::MakeUnique<SyncCycleContext>( |
| 150 connection_.get(), directory(), extensions_activity_.get(), | 151 connection_.get(), directory(), extensions_activity_.get(), |
| 151 std::vector<SyncEngineEventListener*>(), nullptr, | 152 std::vector<SyncEngineEventListener*>(), nullptr, |
| 152 model_type_registry_.get(), | 153 model_type_registry_.get(), |
| 153 true, // enable keystore encryption | 154 true, // enable keystore encryption |
| 154 false, // force enable pre-commit GU avoidance | 155 false, // force enable pre-commit GU avoidance |
| 155 "fake_invalidator_client_id"); | 156 "fake_invalidator_client_id"); |
| 156 context_->SetRoutingInfo(routing_info_); | 157 context_->SetRoutingInfo(routing_info_); |
| 157 context_->set_notifications_enabled(true); | 158 context_->set_notifications_enabled(true); |
| 158 context_->set_account_name("Test"); | 159 context_->set_account_name("Test"); |
| 159 scheduler_ = base::MakeUnique<SyncSchedulerImpl>( | 160 scheduler_ = base::MakeUnique<SyncSchedulerImpl>( |
| 160 "TestSyncScheduler", BackoffDelayProvider::FromDefaults(), context(), | 161 "TestSyncScheduler", BackoffDelayProvider::FromDefaults(), context(), |
| 161 syncer_); | 162 syncer_); |
| 162 scheduler_->SetDefaultNudgeDelay(default_delay()); | 163 scheduler_->SetDefaultNudgeDelay(default_delay()); |
| 163 } | 164 } |
| 164 | 165 |
| 165 SyncSchedulerImpl* scheduler() { return scheduler_.get(); } | 166 SyncSchedulerImpl* scheduler() { return scheduler_.get(); } |
| 166 const ModelSafeRoutingInfo& routing_info() { return routing_info_; } | 167 const ModelSafeRoutingInfo& routing_info() { return routing_info_; } |
| 167 MockSyncer* syncer() { return syncer_; } | 168 MockSyncer* syncer() { return syncer_; } |
| 168 MockDelayProvider* delay() { return delay_; } | 169 MockDelayProvider* delay() { return delay_; } |
| 169 MockConnectionManager* connection() { return connection_.get(); } | 170 MockConnectionManager* connection() { return connection_.get(); } |
| 170 TimeDelta default_delay() { return TimeDelta::FromSeconds(0); } | 171 TimeDelta default_delay() { return TimeDelta::FromSeconds(0); } |
| 171 TimeDelta timeout() { return TestTimeouts::action_timeout(); } | 172 TimeDelta timeout() { return TestTimeouts::action_timeout(); } |
| 172 | 173 |
| 173 void TearDown() override { | 174 void TearDown() override { |
| 174 PumpLoop(); | 175 PumpLoop(); |
| 175 scheduler_.reset(); | 176 scheduler_.reset(); |
| 176 PumpLoop(); | 177 PumpLoop(); |
| 177 dir_maker_.TearDown(); | 178 test_user_share_.TearDown(); |
| 178 } | 179 } |
| 179 | 180 |
| 180 void AnalyzePollRun(const SyncShareTimes& times, | 181 void AnalyzePollRun(const SyncShareTimes& times, |
| 181 size_t min_num_samples, | 182 size_t min_num_samples, |
| 182 const TimeTicks& optimal_start, | 183 const TimeTicks& optimal_start, |
| 183 const TimeDelta& poll_interval) { | 184 const TimeDelta& poll_interval) { |
| 184 EXPECT_GE(times.size(), min_num_samples); | 185 EXPECT_GE(times.size(), min_num_samples); |
| 185 for (size_t i = 0; i < times.size(); i++) { | 186 for (size_t i = 0; i < times.size(); i++) { |
| 186 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); | 187 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); |
| 187 TimeTicks optimal_next_sync = optimal_start + poll_interval * i; | 188 TimeTicks optimal_next_sync = optimal_start + poll_interval * i; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 return scheduler_->retry_timer_.GetCurrentDelay(); | 234 return scheduler_->retry_timer_.GetCurrentDelay(); |
| 234 } | 235 } |
| 235 | 236 |
| 236 static std::unique_ptr<InvalidationInterface> BuildInvalidation( | 237 static std::unique_ptr<InvalidationInterface> BuildInvalidation( |
| 237 int64_t version, | 238 int64_t version, |
| 238 const std::string& payload) { | 239 const std::string& payload) { |
| 239 return MockInvalidation::Build(version, payload); | 240 return MockInvalidation::Build(version, payload); |
| 240 } | 241 } |
| 241 | 242 |
| 242 private: | 243 private: |
| 243 syncable::Directory* directory() { return dir_maker_.directory(); } | 244 syncable::Directory* directory() { |
| 245 return test_user_share_.user_share()->directory.get(); |
| 246 } |
| 244 | 247 |
| 245 base::MessageLoop loop_; | 248 base::MessageLoop loop_; |
| 246 TestDirectorySetterUpper dir_maker_; | 249 TestUserShare test_user_share_; |
| 247 CancelationSignal cancelation_signal_; | 250 CancelationSignal cancelation_signal_; |
| 248 std::unique_ptr<MockConnectionManager> connection_; | 251 std::unique_ptr<MockConnectionManager> connection_; |
| 249 std::unique_ptr<ModelTypeRegistry> model_type_registry_; | 252 std::unique_ptr<ModelTypeRegistry> model_type_registry_; |
| 250 std::unique_ptr<SyncCycleContext> context_; | 253 std::unique_ptr<SyncCycleContext> context_; |
| 251 std::unique_ptr<SyncSchedulerImpl> scheduler_; | 254 std::unique_ptr<SyncSchedulerImpl> scheduler_; |
| 252 MockNudgeHandler mock_nudge_handler_; | 255 MockNudgeHandler mock_nudge_handler_; |
| 253 MockSyncer* syncer_; | 256 MockSyncer* syncer_; |
| 254 MockDelayProvider* delay_; | 257 MockDelayProvider* delay_; |
| 255 std::vector<scoped_refptr<ModelSafeWorker>> workers_; | 258 std::vector<scoped_refptr<ModelSafeWorker>> workers_; |
| 256 scoped_refptr<ExtensionsActivity> extensions_activity_; | 259 scoped_refptr<ExtensionsActivity> extensions_activity_; |
| (...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1430 ASSERT_TRUE(scheduler()->IsBackingOff()); | 1433 ASSERT_TRUE(scheduler()->IsBackingOff()); |
| 1431 | 1434 |
| 1432 // Now succeed. | 1435 // Now succeed. |
| 1433 connection()->SetServerReachable(); | 1436 connection()->SetServerReachable(); |
| 1434 PumpLoopFor(2 * delta); | 1437 PumpLoopFor(2 * delta); |
| 1435 ASSERT_EQ(1, success_counter.times_called()); | 1438 ASSERT_EQ(1, success_counter.times_called()); |
| 1436 ASSERT_FALSE(scheduler()->IsBackingOff()); | 1439 ASSERT_FALSE(scheduler()->IsBackingOff()); |
| 1437 } | 1440 } |
| 1438 | 1441 |
| 1439 } // namespace syncer | 1442 } // namespace syncer |
| OLD | NEW |