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