| 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/time.h" | 6 #include "base/time.h" |
| 7 #include "sync/engine/backoff_delay_provider.h" | 7 #include "sync/engine/backoff_delay_provider.h" |
| 8 #include "sync/engine/sync_scheduler_impl.h" | 8 #include "sync/engine/sync_scheduler_impl.h" |
| 9 #include "sync/engine/throttled_data_type_tracker.h" | 9 #include "sync/engine/throttled_data_type_tracker.h" |
| 10 #include "sync/internal_api/public/engine/polling_constants.h" | 10 #include "sync/internal_api/public/engine/polling_constants.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 new SyncSchedulerImpl::WaitInterval( | 85 new SyncSchedulerImpl::WaitInterval( |
| 86 SyncSchedulerImpl::WaitInterval::EXPONENTIAL_BACKOFF, | 86 SyncSchedulerImpl::WaitInterval::EXPONENTIAL_BACKOFF, |
| 87 TimeDelta::FromSeconds(1))); | 87 TimeDelta::FromSeconds(1))); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void SetWaitIntervalHadNudge(bool had_nudge) { | 90 void SetWaitIntervalHadNudge(bool had_nudge) { |
| 91 scheduler_->wait_interval_->had_nudge = had_nudge; | 91 scheduler_->wait_interval_->had_nudge = had_nudge; |
| 92 } | 92 } |
| 93 | 93 |
| 94 SyncSchedulerImpl::JobProcessDecision DecideOnJob( | 94 SyncSchedulerImpl::JobProcessDecision DecideOnJob( |
| 95 const SyncSessionJob& job) { | 95 const SyncSchedulerImpl::SyncSessionJob& job) { |
| 96 return scheduler_->DecideOnJob(job); | 96 return scheduler_->DecideOnJob(job); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void InitializeSyncerOnNormalMode() { | 99 void InitializeSyncerOnNormalMode() { |
| 100 SetMode(SyncScheduler::NORMAL_MODE); | 100 SetMode(SyncScheduler::NORMAL_MODE); |
| 101 ResetWaitInterval(); | 101 ResetWaitInterval(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 SyncSchedulerImpl::JobProcessDecision CreateAndDecideJob( | 104 SyncSchedulerImpl::JobProcessDecision CreateAndDecideJob( |
| 105 SyncSessionJob::Purpose purpose) { | 105 SyncSchedulerImpl::SyncSessionJob::SyncSessionJobPurpose purpose) { |
| 106 scoped_ptr<SyncSession> s(scheduler_->CreateSyncSession(SyncSourceInfo())); | 106 SyncSession* s = scheduler_->CreateSyncSession(SyncSourceInfo()); |
| 107 SyncSessionJob job(purpose, TimeTicks::Now(), s.Pass(), | 107 SyncSchedulerImpl::SyncSessionJob job(purpose, TimeTicks::Now(), |
| 108 ConfigurationParams(), FROM_HERE); | 108 make_linked_ptr(s), |
| 109 false, |
| 110 ConfigurationParams(), |
| 111 FROM_HERE); |
| 109 return DecideOnJob(job); | 112 return DecideOnJob(job); |
| 110 } | 113 } |
| 111 | 114 |
| 112 SyncSessionContext* context() { return context_.get(); } | 115 SyncSessionContext* context() { return context_.get(); } |
| 113 | 116 |
| 114 private: | 117 private: |
| 115 MessageLoop message_loop_; | 118 MessageLoop message_loop_; |
| 116 scoped_ptr<MockConnectionManager> connection_; | 119 scoped_ptr<MockConnectionManager> connection_; |
| 117 scoped_ptr<SyncSessionContext> context_; | 120 scoped_ptr<SyncSessionContext> context_; |
| 118 std::vector<scoped_refptr<FakeModelWorker> > workers_; | 121 std::vector<scoped_refptr<FakeModelWorker> > workers_; |
| 119 FakeExtensionsActivityMonitor extensions_activity_monitor_; | 122 FakeExtensionsActivityMonitor extensions_activity_monitor_; |
| 120 scoped_ptr<ThrottledDataTypeTracker> throttled_data_type_tracker_; | 123 scoped_ptr<ThrottledDataTypeTracker> throttled_data_type_tracker_; |
| 121 TestDirectorySetterUpper dir_maker_; | 124 TestDirectorySetterUpper dir_maker_; |
| 122 | 125 |
| 123 protected: | 126 protected: |
| 124 // Declared here to ensure it is destructed before the objects it references. | 127 // Declared here to ensure it is destructed before the objects it references. |
| 125 scoped_ptr<SyncSchedulerImpl> scheduler_; | 128 scoped_ptr<SyncSchedulerImpl> scheduler_; |
| 126 }; | 129 }; |
| 127 | 130 |
| 128 TEST_F(SyncSchedulerWhiteboxTest, SaveNudge) { | 131 TEST_F(SyncSchedulerWhiteboxTest, SaveNudge) { |
| 129 InitializeSyncerOnNormalMode(); | 132 InitializeSyncerOnNormalMode(); |
| 130 | 133 |
| 131 // Now set the mode to configure. | 134 // Now set the mode to configure. |
| 132 SetMode(SyncScheduler::CONFIGURATION_MODE); | 135 SetMode(SyncScheduler::CONFIGURATION_MODE); |
| 133 | 136 |
| 134 SyncSchedulerImpl::JobProcessDecision decision = | 137 SyncSchedulerImpl::JobProcessDecision decision = |
| 135 CreateAndDecideJob(SyncSessionJob::NUDGE); | 138 CreateAndDecideJob(SyncSchedulerImpl::SyncSessionJob::NUDGE); |
| 136 | 139 |
| 137 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE); | 140 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE); |
| 138 } | 141 } |
| 139 | 142 |
| 140 TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileTypeThrottled) { | 143 TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileTypeThrottled) { |
| 141 InitializeSyncerOnNormalMode(); | 144 InitializeSyncerOnNormalMode(); |
| 142 | 145 |
| 143 const ModelTypeSet types(BOOKMARKS); | 146 const ModelTypeSet types(BOOKMARKS); |
| 144 | 147 |
| 145 // Mark bookmarks as throttled. | 148 // Mark bookmarks as throttled. |
| 146 context()->throttled_data_type_tracker()->SetUnthrottleTime( | 149 context()->throttled_data_type_tracker()->SetUnthrottleTime( |
| 147 types, base::TimeTicks::Now() + base::TimeDelta::FromHours(2)); | 150 types, base::TimeTicks::Now() + base::TimeDelta::FromHours(2)); |
| 148 | 151 |
| 149 const ModelTypeInvalidationMap& invalidation_map = | 152 const ModelTypeInvalidationMap& invalidation_map = |
| 150 ModelTypeSetToInvalidationMap(types, std::string()); | 153 ModelTypeSetToInvalidationMap(types, std::string()); |
| 151 | 154 |
| 152 SyncSourceInfo info(GetUpdatesCallerInfo::LOCAL, invalidation_map); | 155 SyncSourceInfo info(GetUpdatesCallerInfo::LOCAL, invalidation_map); |
| 153 scoped_ptr<SyncSession> s(scheduler_->CreateSyncSession(info)); | 156 SyncSession* s = scheduler_->CreateSyncSession(info); |
| 154 | 157 |
| 155 // Now schedule a nudge with just bookmarks and the change is local. | 158 // Now schedule a nudge with just bookmarks and the change is local. |
| 156 SyncSessionJob job(SyncSessionJob::NUDGE, | 159 SyncSchedulerImpl::SyncSessionJob job( |
| 157 TimeTicks::Now(), | 160 SyncSchedulerImpl::SyncSessionJob::NUDGE, |
| 158 s.Pass(), | 161 TimeTicks::Now(), |
| 159 ConfigurationParams(), | 162 make_linked_ptr(s), |
| 160 FROM_HERE); | 163 false, |
| 164 ConfigurationParams(), |
| 165 FROM_HERE); |
| 166 |
| 161 SyncSchedulerImpl::JobProcessDecision decision = DecideOnJob(job); | 167 SyncSchedulerImpl::JobProcessDecision decision = DecideOnJob(job); |
| 162 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE); | 168 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE); |
| 163 } | 169 } |
| 164 | 170 |
| 165 TEST_F(SyncSchedulerWhiteboxTest, ContinueNudge) { | 171 TEST_F(SyncSchedulerWhiteboxTest, ContinueNudge) { |
| 166 InitializeSyncerOnNormalMode(); | 172 InitializeSyncerOnNormalMode(); |
| 167 | 173 |
| 168 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( | 174 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( |
| 169 SyncSessionJob::NUDGE); | 175 SyncSchedulerImpl::SyncSessionJob::NUDGE); |
| 170 | 176 |
| 171 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); | 177 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); |
| 172 } | 178 } |
| 173 | 179 |
| 174 TEST_F(SyncSchedulerWhiteboxTest, DropPoll) { | 180 TEST_F(SyncSchedulerWhiteboxTest, DropPoll) { |
| 175 InitializeSyncerOnNormalMode(); | 181 InitializeSyncerOnNormalMode(); |
| 176 SetMode(SyncScheduler::CONFIGURATION_MODE); | 182 SetMode(SyncScheduler::CONFIGURATION_MODE); |
| 177 | 183 |
| 178 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( | 184 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( |
| 179 SyncSessionJob::POLL); | 185 SyncSchedulerImpl::SyncSessionJob::POLL); |
| 180 | 186 |
| 181 EXPECT_EQ(decision, SyncSchedulerImpl::DROP); | 187 EXPECT_EQ(decision, SyncSchedulerImpl::DROP); |
| 182 } | 188 } |
| 183 | 189 |
| 184 TEST_F(SyncSchedulerWhiteboxTest, ContinuePoll) { | 190 TEST_F(SyncSchedulerWhiteboxTest, ContinuePoll) { |
| 185 InitializeSyncerOnNormalMode(); | 191 InitializeSyncerOnNormalMode(); |
| 186 | 192 |
| 187 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( | 193 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( |
| 188 SyncSessionJob::POLL); | 194 SyncSchedulerImpl::SyncSessionJob::POLL); |
| 189 | 195 |
| 190 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); | 196 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); |
| 191 } | 197 } |
| 192 | 198 |
| 193 TEST_F(SyncSchedulerWhiteboxTest, ContinueConfiguration) { | 199 TEST_F(SyncSchedulerWhiteboxTest, ContinueConfiguration) { |
| 194 InitializeSyncerOnNormalMode(); | 200 InitializeSyncerOnNormalMode(); |
| 195 SetMode(SyncScheduler::CONFIGURATION_MODE); | 201 SetMode(SyncScheduler::CONFIGURATION_MODE); |
| 196 | 202 |
| 197 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( | 203 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( |
| 198 SyncSessionJob::CONFIGURATION); | 204 SyncSchedulerImpl::SyncSessionJob::CONFIGURATION); |
| 199 | 205 |
| 200 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); | 206 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); |
| 201 } | 207 } |
| 202 | 208 |
| 203 TEST_F(SyncSchedulerWhiteboxTest, SaveConfigurationWhileThrottled) { | 209 TEST_F(SyncSchedulerWhiteboxTest, SaveConfigurationWhileThrottled) { |
| 204 InitializeSyncerOnNormalMode(); | 210 InitializeSyncerOnNormalMode(); |
| 205 SetMode(SyncScheduler::CONFIGURATION_MODE); | 211 SetMode(SyncScheduler::CONFIGURATION_MODE); |
| 206 | 212 |
| 207 SetWaitIntervalToThrottled(); | 213 SetWaitIntervalToThrottled(); |
| 208 | 214 |
| 209 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( | 215 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( |
| 210 SyncSessionJob::CONFIGURATION); | 216 SyncSchedulerImpl::SyncSessionJob::CONFIGURATION); |
| 211 | 217 |
| 212 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE); | 218 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE); |
| 213 } | 219 } |
| 214 | 220 |
| 215 TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileThrottled) { | 221 TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileThrottled) { |
| 216 InitializeSyncerOnNormalMode(); | 222 InitializeSyncerOnNormalMode(); |
| 217 SetMode(SyncScheduler::CONFIGURATION_MODE); | 223 SetMode(SyncScheduler::CONFIGURATION_MODE); |
| 218 | 224 |
| 219 SetWaitIntervalToThrottled(); | 225 SetWaitIntervalToThrottled(); |
| 220 | 226 |
| 221 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( | 227 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( |
| 222 SyncSessionJob::NUDGE); | 228 SyncSchedulerImpl::SyncSessionJob::NUDGE); |
| 223 | 229 |
| 224 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE); | 230 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE); |
| 225 } | 231 } |
| 226 | 232 |
| 227 TEST_F(SyncSchedulerWhiteboxTest, ContinueNudgeWhileExponentialBackOff) { | 233 TEST_F(SyncSchedulerWhiteboxTest, ContinueNudgeWhileExponentialBackOff) { |
| 228 InitializeSyncerOnNormalMode(); | 234 InitializeSyncerOnNormalMode(); |
| 229 SetMode(SyncScheduler::NORMAL_MODE); | 235 SetMode(SyncScheduler::NORMAL_MODE); |
| 230 SetWaitIntervalToExponentialBackoff(); | 236 SetWaitIntervalToExponentialBackoff(); |
| 231 | 237 |
| 232 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( | 238 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( |
| 233 SyncSessionJob::NUDGE); | 239 SyncSchedulerImpl::SyncSessionJob::NUDGE); |
| 234 | 240 |
| 235 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); | 241 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); |
| 236 } | 242 } |
| 237 | 243 |
| 238 TEST_F(SyncSchedulerWhiteboxTest, DropNudgeWhileExponentialBackOff) { | 244 TEST_F(SyncSchedulerWhiteboxTest, DropNudgeWhileExponentialBackOff) { |
| 239 InitializeSyncerOnNormalMode(); | 245 InitializeSyncerOnNormalMode(); |
| 240 SetMode(SyncScheduler::NORMAL_MODE); | 246 SetMode(SyncScheduler::NORMAL_MODE); |
| 241 SetWaitIntervalToExponentialBackoff(); | 247 SetWaitIntervalToExponentialBackoff(); |
| 242 SetWaitIntervalHadNudge(true); | 248 SetWaitIntervalHadNudge(true); |
| 243 | 249 |
| 244 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( | 250 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( |
| 245 SyncSessionJob::NUDGE); | 251 SyncSchedulerImpl::SyncSessionJob::NUDGE); |
| 246 | 252 |
| 247 EXPECT_EQ(decision, SyncSchedulerImpl::DROP); | 253 EXPECT_EQ(decision, SyncSchedulerImpl::DROP); |
| 248 } | 254 } |
| 249 | 255 |
| 250 TEST_F(SyncSchedulerWhiteboxTest, ContinueCanaryJobConfig) { | 256 TEST_F(SyncSchedulerWhiteboxTest, ContinueCanaryJobConfig) { |
| 251 InitializeSyncerOnNormalMode(); | 257 InitializeSyncerOnNormalMode(); |
| 252 SetMode(SyncScheduler::CONFIGURATION_MODE); | 258 SetMode(SyncScheduler::CONFIGURATION_MODE); |
| 253 SetWaitIntervalToExponentialBackoff(); | 259 SetWaitIntervalToExponentialBackoff(); |
| 254 | 260 |
| 255 SyncSessionJob job(SyncSessionJob::CONFIGURATION, | 261 struct SyncSchedulerImpl::SyncSessionJob job; |
| 256 TimeTicks::Now(), scoped_ptr<SyncSession>(), | 262 job.purpose = SyncSchedulerImpl::SyncSessionJob::CONFIGURATION; |
| 257 ConfigurationParams(), FROM_HERE); | 263 job.scheduled_start = TimeTicks::Now(); |
| 258 | 264 job.is_canary_job = true; |
| 259 job.GrantCanaryPrivilege(); | |
| 260 SyncSchedulerImpl::JobProcessDecision decision = DecideOnJob(job); | 265 SyncSchedulerImpl::JobProcessDecision decision = DecideOnJob(job); |
| 261 | 266 |
| 262 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); | 267 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); |
| 263 } | 268 } |
| 264 | 269 |
| 265 } // namespace syncer | 270 } // namespace syncer |
| OLD | NEW |