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 SyncSessionJob& job, |
96 return scheduler_->DecideOnJob(job); | 96 bool is_canary) { |
| 97 return scheduler_->DecideOnJob(job, is_canary); |
97 } | 98 } |
98 | 99 |
99 void InitializeSyncerOnNormalMode() { | 100 void InitializeSyncerOnNormalMode() { |
100 SetMode(SyncScheduler::NORMAL_MODE); | 101 SetMode(SyncScheduler::NORMAL_MODE); |
101 ResetWaitInterval(); | 102 ResetWaitInterval(); |
102 } | 103 } |
103 | 104 |
104 SyncSchedulerImpl::JobProcessDecision CreateAndDecideJob( | 105 SyncSchedulerImpl::JobProcessDecision CreateAndDecideJob( |
105 SyncSessionJob::Purpose purpose) { | 106 SyncSessionJob::Purpose purpose) { |
106 scoped_ptr<SyncSession> s(scheduler_->CreateSyncSession(SyncSourceInfo())); | 107 scoped_ptr<SyncSession> s(scheduler_->CreateSyncSession(SyncSourceInfo())); |
107 SyncSessionJob job(purpose, TimeTicks::Now(), s.Pass(), | 108 SyncSessionJob job(purpose, TimeTicks::Now(), s.Pass(), |
108 ConfigurationParams(), FROM_HERE); | 109 ConfigurationParams(), FROM_HERE); |
109 return DecideOnJob(job); | 110 return DecideOnJob(job, false); |
110 } | 111 } |
111 | 112 |
112 SyncSessionContext* context() { return context_.get(); } | 113 SyncSessionContext* context() { return context_.get(); } |
113 | 114 |
114 private: | 115 private: |
115 MessageLoop message_loop_; | 116 MessageLoop message_loop_; |
116 scoped_ptr<MockConnectionManager> connection_; | 117 scoped_ptr<MockConnectionManager> connection_; |
117 scoped_ptr<SyncSessionContext> context_; | 118 scoped_ptr<SyncSessionContext> context_; |
118 std::vector<scoped_refptr<FakeModelWorker> > workers_; | 119 std::vector<scoped_refptr<FakeModelWorker> > workers_; |
119 FakeExtensionsActivityMonitor extensions_activity_monitor_; | 120 FakeExtensionsActivityMonitor extensions_activity_monitor_; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 152 |
152 SyncSourceInfo info(GetUpdatesCallerInfo::LOCAL, invalidation_map); | 153 SyncSourceInfo info(GetUpdatesCallerInfo::LOCAL, invalidation_map); |
153 scoped_ptr<SyncSession> s(scheduler_->CreateSyncSession(info)); | 154 scoped_ptr<SyncSession> s(scheduler_->CreateSyncSession(info)); |
154 | 155 |
155 // 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. |
156 SyncSessionJob job(SyncSessionJob::NUDGE, | 157 SyncSessionJob job(SyncSessionJob::NUDGE, |
157 TimeTicks::Now(), | 158 TimeTicks::Now(), |
158 s.Pass(), | 159 s.Pass(), |
159 ConfigurationParams(), | 160 ConfigurationParams(), |
160 FROM_HERE); | 161 FROM_HERE); |
161 SyncSchedulerImpl::JobProcessDecision decision = DecideOnJob(job); | 162 SyncSchedulerImpl::JobProcessDecision decision = DecideOnJob(job, false); |
162 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE); | 163 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE); |
163 } | 164 } |
164 | 165 |
165 TEST_F(SyncSchedulerWhiteboxTest, ContinueNudge) { | 166 TEST_F(SyncSchedulerWhiteboxTest, ContinueNudge) { |
166 InitializeSyncerOnNormalMode(); | 167 InitializeSyncerOnNormalMode(); |
167 | 168 |
168 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( | 169 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( |
169 SyncSessionJob::NUDGE); | 170 SyncSessionJob::NUDGE); |
170 | 171 |
171 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); | 172 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 | 250 |
250 TEST_F(SyncSchedulerWhiteboxTest, ContinueCanaryJobConfig) { | 251 TEST_F(SyncSchedulerWhiteboxTest, ContinueCanaryJobConfig) { |
251 InitializeSyncerOnNormalMode(); | 252 InitializeSyncerOnNormalMode(); |
252 SetMode(SyncScheduler::CONFIGURATION_MODE); | 253 SetMode(SyncScheduler::CONFIGURATION_MODE); |
253 SetWaitIntervalToExponentialBackoff(); | 254 SetWaitIntervalToExponentialBackoff(); |
254 | 255 |
255 SyncSessionJob job(SyncSessionJob::CONFIGURATION, | 256 SyncSessionJob job(SyncSessionJob::CONFIGURATION, |
256 TimeTicks::Now(), scoped_ptr<SyncSession>(), | 257 TimeTicks::Now(), scoped_ptr<SyncSession>(), |
257 ConfigurationParams(), FROM_HERE); | 258 ConfigurationParams(), FROM_HERE); |
258 | 259 |
259 job.GrantCanaryPrivilege(); | 260 SyncSchedulerImpl::JobProcessDecision decision = DecideOnJob(job, true); |
260 SyncSchedulerImpl::JobProcessDecision decision = DecideOnJob(job); | |
261 | 261 |
262 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); | 262 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); |
263 } | 263 } |
264 | 264 |
265 } // namespace syncer | 265 } // namespace syncer |
OLD | NEW |