Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/browser/sync/engine/syncer_thread2.cc

Issue 6812004: sync: Make nudge + config jobs reliable in SyncerThread2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing CR feedback. Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/sync/engine/syncer_thread2.h" 5 #include "chrome/browser/sync/engine/syncer_thread2.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 #include "chrome/browser/sync/engine/syncer.h" 10 #include "chrome/browser/sync/engine/syncer.h"
11 11
12 using base::TimeDelta; 12 using base::TimeDelta;
13 using base::TimeTicks; 13 using base::TimeTicks;
14 14
15 namespace browser_sync { 15 namespace browser_sync {
16 16
17 using sessions::SyncSession; 17 using sessions::SyncSession;
18 using sessions::SyncSessionSnapshot; 18 using sessions::SyncSessionSnapshot;
19 using sessions::SyncSourceInfo; 19 using sessions::SyncSourceInfo;
20 using syncable::ModelTypePayloadMap; 20 using syncable::ModelTypePayloadMap;
21 using syncable::ModelTypeBitSet; 21 using syncable::ModelTypeBitSet;
22 using sync_pb::GetUpdatesCallerInfo; 22 using sync_pb::GetUpdatesCallerInfo;
23 23
24 namespace s3 { 24 namespace s3 {
25 25
26 struct SyncerThread::WaitInterval {
27 enum Mode {
28 // A wait interval whose duration has been affected by exponential
29 // backoff.
30 // EXPONENTIAL_BACKOFF intervals are nudge-rate limited to 1 per interval.
31 EXPONENTIAL_BACKOFF,
32 // A server-initiated throttled interval. We do not allow any syncing
33 // during such an interval.
34 THROTTLED,
35 };
36 Mode mode;
37
38 // This bool is set to true if we have observed a nudge during this
39 // interval and mode == EXPONENTIAL_BACKOFF.
40 bool had_nudge;
41 base::TimeDelta length;
42 base::OneShotTimer<SyncerThread> timer;
43 WaitInterval(Mode mode, base::TimeDelta length);
44 };
45
46 struct SyncerThread::SyncSessionJob {
47 SyncSessionJobPurpose purpose;
48 base::TimeTicks scheduled_start;
49 linked_ptr<sessions::SyncSession> session;
50
51 // This is the location the nudge came from. used for debugging purpose.
52 // In case of multiple nudges getting coalesced this stores the first nudge
53 // that came in.
54 tracked_objects::Location nudge_location;
55 };
56
57 SyncerThread::DelayProvider::DelayProvider() {} 26 SyncerThread::DelayProvider::DelayProvider() {}
58 SyncerThread::DelayProvider::~DelayProvider() {} 27 SyncerThread::DelayProvider::~DelayProvider() {}
59 28
29 SyncerThread::WaitInterval::WaitInterval() {}
30 SyncerThread::WaitInterval::~WaitInterval() {}
31
32 SyncerThread::SyncSessionJob::SyncSessionJob() {}
33 SyncerThread::SyncSessionJob::~SyncSessionJob() {}
34
35 SyncerThread::SyncSessionJob::SyncSessionJob(SyncSessionJobPurpose purpose,
36 base::TimeTicks start,
37 linked_ptr<sessions::SyncSession> session, bool is_canary_job,
38 const tracked_objects::Location& nudge_location) : purpose(purpose),
39 scheduled_start(start),
40 session(session),
41 is_canary_job(is_canary_job),
42 nudge_location(nudge_location) {
43 }
44
60 TimeDelta SyncerThread::DelayProvider::GetDelay( 45 TimeDelta SyncerThread::DelayProvider::GetDelay(
61 const base::TimeDelta& last_delay) { 46 const base::TimeDelta& last_delay) {
62 return SyncerThread::GetRecommendedDelay(last_delay); 47 return SyncerThread::GetRecommendedDelay(last_delay);
63 } 48 }
64 49
50 GetUpdatesCallerInfo::GetUpdatesSource GetUpdatesFromNudgeSource(
51 NudgeSource source) {
52 switch (source) {
53 case NUDGE_SOURCE_NOTIFICATION:
54 return GetUpdatesCallerInfo::NOTIFICATION;
55 case NUDGE_SOURCE_LOCAL:
56 return GetUpdatesCallerInfo::LOCAL;
57 case NUDGE_SOURCE_CONTINUATION:
58 return GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION;
59 case NUDGE_SOURCE_UNKNOWN:
60 return GetUpdatesCallerInfo::UNKNOWN;
61 default:
62 NOTREACHED();
63 return GetUpdatesCallerInfo::UNKNOWN;
64 }
65 }
66
65 SyncerThread::WaitInterval::WaitInterval(Mode mode, TimeDelta length) 67 SyncerThread::WaitInterval::WaitInterval(Mode mode, TimeDelta length)
66 : mode(mode), had_nudge(false), length(length) { } 68 : mode(mode), had_nudge(false), length(length) { }
67 69
68 SyncerThread::SyncerThread(sessions::SyncSessionContext* context, 70 SyncerThread::SyncerThread(sessions::SyncSessionContext* context,
69 Syncer* syncer) 71 Syncer* syncer)
70 : thread_("SyncEngine_SyncerThread"), 72 : thread_("SyncEngine_SyncerThread"),
71 syncer_short_poll_interval_seconds_( 73 syncer_short_poll_interval_seconds_(
72 TimeDelta::FromSeconds(kDefaultShortPollIntervalSeconds)), 74 TimeDelta::FromSeconds(kDefaultShortPollIntervalSeconds)),
73 syncer_long_poll_interval_seconds_( 75 syncer_long_poll_interval_seconds_(
74 TimeDelta::FromSeconds(kDefaultLongPollIntervalSeconds)), 76 TimeDelta::FromSeconds(kDefaultLongPollIntervalSeconds)),
(...skipping 14 matching lines...) Expand all
89 // thinks there is no valid connection as determined by this method, it 91 // thinks there is no valid connection as determined by this method, it
90 // will drop out of *all* forward progress sync loops (it won't poll and it 92 // will drop out of *all* forward progress sync loops (it won't poll and it
91 // will queue up Talk notifications but not actually call SyncShare) until 93 // will queue up Talk notifications but not actually call SyncShare) until
92 // some external action causes a ServerConnectionManager to broadcast that 94 // some external action causes a ServerConnectionManager to broadcast that
93 // a valid connection has been re-established. 95 // a valid connection has been re-established.
94 if (HttpResponse::CONNECTION_UNAVAILABLE == code || 96 if (HttpResponse::CONNECTION_UNAVAILABLE == code ||
95 HttpResponse::SYNC_AUTH_ERROR == code) { 97 HttpResponse::SYNC_AUTH_ERROR == code) {
96 server_connection_ok_ = false; 98 server_connection_ok_ = false;
97 } else if (HttpResponse::SERVER_CONNECTION_OK == code) { 99 } else if (HttpResponse::SERVER_CONNECTION_OK == code) {
98 server_connection_ok_ = true; 100 server_connection_ok_ = true;
101 DoPendingJobIfPossible(true); // set canary to true so this wont be dropped.
tim (not reviewing) 2011/04/13 21:40:18 Capitalize 'Set' also, see my comment @ DoCanaryJ
lipalani1 2011/04/13 22:45:14 Done.
99 } 102 }
100 } 103 }
101 104
102 void SyncerThread::Start(Mode mode, ModeChangeCallback* callback) { 105 void SyncerThread::Start(Mode mode, ModeChangeCallback* callback) {
103 if (!thread_.IsRunning()) { 106 if (!thread_.IsRunning()) {
104 if (!thread_.Start()) { 107 if (!thread_.Start()) {
105 NOTREACHED() << "Unable to start SyncerThread."; 108 NOTREACHED() << "Unable to start SyncerThread.";
106 return; 109 return;
107 } 110 }
108 WatchConnectionManager(); 111 WatchConnectionManager();
(...skipping 24 matching lines...) Expand all
133 136
134 void SyncerThread::StartImpl(Mode mode, 137 void SyncerThread::StartImpl(Mode mode,
135 linked_ptr<ModeChangeCallback> callback) { 138 linked_ptr<ModeChangeCallback> callback) {
136 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 139 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
137 DCHECK(!session_context_->account_name().empty()); 140 DCHECK(!session_context_->account_name().empty());
138 DCHECK(syncer_.get()); 141 DCHECK(syncer_.get());
139 mode_ = mode; 142 mode_ = mode;
140 AdjustPolling(NULL); // Will kick start poll timer if needed. 143 AdjustPolling(NULL); // Will kick start poll timer if needed.
141 if (callback.get()) 144 if (callback.get())
142 callback->Run(); 145 callback->Run();
146
147 // We just changed our mode. See if there are any pending jobs that we could
148 // execute in the new mode.
149 DoPendingJobIfPossible(false);
143 } 150 }
144 151
145 bool SyncerThread::ShouldRunJob(SyncSessionJobPurpose purpose, 152 SyncerThread::JobProcessDecision SyncerThread::DecideWhileInWaitInterval(
146 const TimeTicks& scheduled_start) { 153 const SyncSessionJob& job) {
147 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
148 154
149 // Check wait interval. 155 DCHECK(wait_interval_.get());
150 if (wait_interval_.get()) { 156 DCHECK_NE(job.purpose, SyncSessionJob::CLEAR_USER_DATA);
151 // TODO(tim): Consider different handling for CLEAR_USER_DATA (i.e. permit
152 // when throttled).
153 if (wait_interval_->mode == WaitInterval::THROTTLED)
154 return false;
155 157
156 DCHECK_EQ(wait_interval_->mode, WaitInterval::EXPONENTIAL_BACKOFF); 158 if (job.purpose == SyncSessionJob::POLL)
157 if ((purpose != NUDGE) || wait_interval_->had_nudge) 159 return DROP;
158 return false; 160
161 DCHECK(job.purpose == SyncSessionJob::NUDGE ||
162 job.purpose == SyncSessionJob::CONFIGURATION);
163 if (wait_interval_->mode == WaitInterval::THROTTLED)
164 return SAVE;
165
166 DCHECK_EQ(wait_interval_->mode, WaitInterval::EXPONENTIAL_BACKOFF);
167 if (job.purpose == SyncSessionJob::NUDGE) {
168 if (mode_ == CONFIGURATION_MODE)
169 return SAVE;
170
171 // If we already had one nudge then just drop this nudge. We will retry
172 // later when the timer runs out.
173 return wait_interval_->had_nudge ? DROP : CONTINUE;
174 }
175 // This is a config job.
176 return job.is_canary_job ? CONTINUE : SAVE;
177 }
178
179 SyncerThread::JobProcessDecision SyncerThread::DecideOnJob(
180 const SyncSessionJob& job) {
181 if (job.purpose == SyncSessionJob::CLEAR_USER_DATA)
182 return CONTINUE;
183
184 if (wait_interval_.get())
185 return DecideWhileInWaitInterval(job);
186
187 if (mode_ == CONFIGURATION_MODE) {
188 if (job.purpose == SyncSessionJob::NUDGE)
189 return SAVE;
190 else if (job.purpose == SyncSessionJob::CONFIGURATION)
191 return CONTINUE;
192 else
193 return DROP;
159 } 194 }
160 195
161 // Mode / purpose contract (See 'Mode' enum in header). Don't run jobs that 196 // We are in normal mode.
162 // were intended for a normal sync if we are in configuration mode, and vice 197 DCHECK_EQ(mode_, NORMAL_MODE);
163 // versa. 198 DCHECK_NE(job.purpose, SyncSessionJob::CONFIGURATION);
164 switch (mode_) { 199
165 case CONFIGURATION_MODE: 200 // Freshness condition
166 if (purpose != CONFIGURATION) 201 if (job.scheduled_start < last_sync_session_end_time_)
167 return false; 202 return DROP;
168 break; 203
169 case NORMAL_MODE: 204 if (server_connection_ok_)
170 if (purpose == CONFIGURATION) 205 return CONTINUE;
171 return false; 206
172 break; 207 return job.purpose == SyncSessionJob::NUDGE ? SAVE : DROP;
173 default: 208 }
174 NOTREACHED() << "Unknown SyncerThread Mode: " << mode_; 209
175 return false; 210 void SyncerThread::InitOrCoalesceJob(const SyncSessionJob& job) {
211 DCHECK(job.purpose != SyncSessionJob::CONFIGURATION);
212 if (pending_nudge_.get() == NULL) {
213 SyncSession* s = job.session.get();
214 scoped_ptr<SyncSession> session(new SyncSession(s->context(),
215 s->delegate(), s->source(), s->routing_info(), s->workers()));
216
217 SyncSessionJob new_job(SyncSessionJob::NUDGE, job.scheduled_start,
218 make_linked_ptr(session.release()), false, job.nudge_location);
219 pending_nudge_.reset(new SyncSessionJob(new_job));
220
221 return;
176 } 222 }
177 223
178 // Continuation NUDGE tasks have priority over POLLs because they are the 224 pending_nudge_->session->Coalesce(*(job.session.get()));
179 // only tasks that trigger exponential backoff, so this prevents them from 225 pending_nudge_->scheduled_start = job.scheduled_start;
180 // being starved from running (e.g. due to a very, very low poll interval,
181 // such as 0ms). It's rare that this would ever matter in practice.
182 if (purpose == POLL && (pending_nudge_.get() &&
183 pending_nudge_->session->source().updates_source ==
184 GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION)) {
185 return false;
186 }
187 226
188 // Freshness condition. 227 // Unfortunately the nudge location cannot be modified. So it stores the
189 if (purpose == NUDGE && 228 // location of the first caller.
190 (scheduled_start < last_sync_session_end_time_)) {
191 return false;
192 }
193
194 return server_connection_ok_;
195 } 229 }
196 230
197 GetUpdatesCallerInfo::GetUpdatesSource GetUpdatesFromNudgeSource( 231 bool SyncerThread::ShouldRunJob(const SyncSessionJob& job) {
198 NudgeSource source) { 232 JobProcessDecision decision = DecideOnJob(job);
199 switch (source) { 233 if (decision != SAVE)
200 case NUDGE_SOURCE_NOTIFICATION: 234 return decision == CONTINUE;
201 return GetUpdatesCallerInfo::NOTIFICATION; 235
202 case NUDGE_SOURCE_LOCAL: 236 DCHECK(job.purpose == SyncSessionJob::NUDGE || job.purpose ==
203 return GetUpdatesCallerInfo::LOCAL; 237 SyncSessionJob::CONFIGURATION);
204 case NUDGE_SOURCE_CONTINUATION: 238
205 return GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION; 239 SaveJob(job);
206 case NUDGE_SOURCE_UNKNOWN: 240 return false;
207 return GetUpdatesCallerInfo::UNKNOWN; 241 }
208 default: 242
209 NOTREACHED(); 243 void SyncerThread::SaveJob(const SyncSessionJob& job) {
210 return GetUpdatesCallerInfo::UNKNOWN; 244 DCHECK(job.purpose != SyncSessionJob::CLEAR_USER_DATA);
211 } 245 if (job.purpose == SyncSessionJob::NUDGE) {
246 InitOrCoalesceJob(job);
247 } else if (job.purpose == SyncSessionJob::CONFIGURATION){
248 DCHECK(wait_interval_.get());
249 DCHECK(mode_ == CONFIGURATION_MODE);
250
251 SyncSession* old = job.session.get();
252 SyncSession* s(new SyncSession(session_context_.get(), this,
253 old->source(), old->routing_info(), old->workers()));
254 SyncSessionJob new_job(job.purpose, TimeTicks::Now(),
255 make_linked_ptr(s), false, job.nudge_location);
256 wait_interval_->pending_configure_job.reset(new SyncSessionJob(new_job));
257 } // drop the rest.
212 } 258 }
213 259
214 // Functor for std::find_if to search by ModelSafeGroup. 260 // Functor for std::find_if to search by ModelSafeGroup.
215 struct ModelSafeWorkerGroupIs { 261 struct ModelSafeWorkerGroupIs {
216 explicit ModelSafeWorkerGroupIs(ModelSafeGroup group) : group(group) {} 262 explicit ModelSafeWorkerGroupIs(ModelSafeGroup group) : group(group) {}
217 bool operator()(ModelSafeWorker* w) { 263 bool operator()(ModelSafeWorker* w) {
218 return group == w->GetModelSafeGroup(); 264 return group == w->GetModelSafeGroup();
219 } 265 }
220 ModelSafeGroup group; 266 ModelSafeGroup group;
221 }; 267 };
(...skipping 11 matching lines...) Expand all
233 NudgeSource source, const ModelTypeBitSet& types, 279 NudgeSource source, const ModelTypeBitSet& types,
234 const tracked_objects::Location& nudge_location) { 280 const tracked_objects::Location& nudge_location) {
235 if (!thread_.IsRunning()) { 281 if (!thread_.IsRunning()) {
236 NOTREACHED(); 282 NOTREACHED();
237 return; 283 return;
238 } 284 }
239 285
240 ModelTypePayloadMap types_with_payloads = 286 ModelTypePayloadMap types_with_payloads =
241 syncable::ModelTypePayloadMapFromBitSet(types, std::string()); 287 syncable::ModelTypePayloadMapFromBitSet(types, std::string());
242 thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod( 288 thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
243 this, &SyncerThread::ScheduleNudgeImpl, delay, source, 289 this, &SyncerThread::ScheduleNudgeImpl, delay,
244 types_with_payloads, nudge_location)); 290 GetUpdatesFromNudgeSource(source), types_with_payloads, false,
291 nudge_location));
245 } 292 }
246 293
247 void SyncerThread::ScheduleNudgeWithPayloads(const TimeDelta& delay, 294 void SyncerThread::ScheduleNudgeWithPayloads(const TimeDelta& delay,
248 NudgeSource source, const ModelTypePayloadMap& types_with_payloads, 295 NudgeSource source, const ModelTypePayloadMap& types_with_payloads,
249 const tracked_objects::Location& nudge_location) { 296 const tracked_objects::Location& nudge_location) {
250 if (!thread_.IsRunning()) { 297 if (!thread_.IsRunning()) {
251 NOTREACHED(); 298 NOTREACHED();
252 return; 299 return;
253 } 300 }
254 301
255 thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod( 302 thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
256 this, &SyncerThread::ScheduleNudgeImpl, delay, source, 303 this, &SyncerThread::ScheduleNudgeImpl, delay,
257 types_with_payloads, nudge_location)); 304 GetUpdatesFromNudgeSource(source), types_with_payloads, false,
305 nudge_location));
258 } 306 }
259 307
260 void SyncerThread::ScheduleClearUserDataImpl() { 308 void SyncerThread::ScheduleClearUserDataImpl() {
261 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 309 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
262 SyncSession* session = new SyncSession(session_context_.get(), this, 310 SyncSession* session = new SyncSession(session_context_.get(), this,
263 SyncSourceInfo(), ModelSafeRoutingInfo(), 311 SyncSourceInfo(), ModelSafeRoutingInfo(),
264 std::vector<ModelSafeWorker*>()); 312 std::vector<ModelSafeWorker*>());
265 ScheduleSyncSessionJob(TimeDelta::FromSeconds(0), CLEAR_USER_DATA, session, 313 ScheduleSyncSessionJob(TimeDelta::FromSeconds(0),
266 FROM_HERE); 314 SyncSessionJob::CLEAR_USER_DATA, session, FROM_HERE);
267 } 315 }
268 316
269 void SyncerThread::ScheduleNudgeImpl(const TimeDelta& delay, 317 void SyncerThread::ScheduleNudgeImpl(const TimeDelta& delay,
270 NudgeSource source, const ModelTypePayloadMap& types_with_payloads, 318 GetUpdatesCallerInfo::GetUpdatesSource source,
271 const tracked_objects::Location& nudge_location) { 319 const ModelTypePayloadMap& types_with_payloads,
320 bool is_canary_job, const tracked_objects::Location& nudge_location) {
272 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 321 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
273 TimeTicks rough_start = TimeTicks::Now() + delay;
274 if (!ShouldRunJob(NUDGE, rough_start)) {
275 LOG(WARNING) << "Dropping nudge at scheduling time, source = "
276 << source;
277 return;
278 }
279 322
280 // Note we currently nudge for all types regardless of the ones incurring 323 // Note we currently nudge for all types regardless of the ones incurring
281 // the nudge. Doing different would throw off some syncer commands like 324 // the nudge. Doing different would throw off some syncer commands like
282 // CleanupDisabledTypes. We may want to change this in the future. 325 // CleanupDisabledTypes. We may want to change this in the future.
283 ModelSafeRoutingInfo routes; 326 SyncSourceInfo info(source, types_with_payloads);
284 std::vector<ModelSafeWorker*> workers;
285 session_context_->registrar()->GetModelSafeRoutingInfo(&routes);
286 session_context_->registrar()->GetWorkers(&workers);
287 SyncSourceInfo info(GetUpdatesFromNudgeSource(source),
288 types_with_payloads);
289 327
290 scoped_ptr<SyncSession> session(new SyncSession( 328 SyncSession* session(CreateSyncSession(info));
291 session_context_.get(), this, info, routes, workers)); 329
330 SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now() + delay,
331 make_linked_ptr(session), is_canary_job,
332 nudge_location);
333
334 session = NULL;
335 if (!ShouldRunJob(job))
336 return;
292 337
293 if (pending_nudge_.get()) { 338 if (pending_nudge_.get()) {
294 if (IsBackingOff() && delay > TimeDelta::FromSeconds(1)) 339 if (IsBackingOff() && delay > TimeDelta::FromSeconds(1))
295 return; 340 return;
296 341
297 pending_nudge_->session->Coalesce(*session.get()); 342 pending_nudge_->session->Coalesce(*(job.session.get()));
298 343
299 if (!IsBackingOff()) { 344 if (!IsBackingOff()) {
300 return; 345 return;
301 } else { 346 } else {
302 // Re-schedule the current pending nudge. 347 // Re-schedule the current pending nudge.
303 SyncSession* s = pending_nudge_->session.get(); 348 SyncSession* s = pending_nudge_->session.get();
304 session.reset(new SyncSession(s->context(), s->delegate(), s->source(), 349 job.session.reset(new SyncSession(s->context(), s->delegate(),
305 s->routing_info(), s->workers())); 350 s->source(), s->routing_info(), s->workers()));
306 pending_nudge_.reset(); 351 pending_nudge_.reset();
307 } 352 }
308 } 353 }
309 ScheduleSyncSessionJob(delay, NUDGE, session.release(), nudge_location); 354
355 // TODO(lipalani) - pass the job itself to ScheduleSyncSessionJob.
356 ScheduleSyncSessionJob(delay, SyncSessionJob::NUDGE, job.session.release(),
357 nudge_location);
310 } 358 }
311 359
312 // Helper to extract the routing info and workers corresponding to types in 360 // Helper to extract the routing info and workers corresponding to types in
313 // |types| from |registrar|. 361 // |types| from |registrar|.
314 void GetModelSafeParamsForTypes(const ModelTypeBitSet& types, 362 void GetModelSafeParamsForTypes(const ModelTypeBitSet& types,
315 ModelSafeWorkerRegistrar* registrar, ModelSafeRoutingInfo* routes, 363 ModelSafeWorkerRegistrar* registrar, ModelSafeRoutingInfo* routes,
316 std::vector<ModelSafeWorker*>* workers) { 364 std::vector<ModelSafeWorker*>* workers) {
317 ModelSafeRoutingInfo r_tmp; 365 ModelSafeRoutingInfo r_tmp;
318 std::vector<ModelSafeWorker*> w_tmp; 366 std::vector<ModelSafeWorker*> w_tmp;
319 registrar->GetModelSafeRoutingInfo(&r_tmp); 367 registrar->GetModelSafeRoutingInfo(&r_tmp);
(...skipping 27 matching lines...) Expand all
347 NOTREACHED(); 395 NOTREACHED();
348 return; 396 return;
349 } 397 }
350 398
351 ModelSafeRoutingInfo routes; 399 ModelSafeRoutingInfo routes;
352 std::vector<ModelSafeWorker*> workers; 400 std::vector<ModelSafeWorker*> workers;
353 GetModelSafeParamsForTypes(types, session_context_->registrar(), 401 GetModelSafeParamsForTypes(types, session_context_->registrar(),
354 &routes, &workers); 402 &routes, &workers);
355 403
356 thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod( 404 thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
357 this, &SyncerThread::ScheduleConfigImpl, routes, workers)); 405 this, &SyncerThread::ScheduleConfigImpl, routes, workers,
406 GetUpdatesCallerInfo::FIRST_UPDATE));
358 } 407 }
359 408
360 void SyncerThread::ScheduleConfigImpl(const ModelSafeRoutingInfo& routing_info, 409 void SyncerThread::ScheduleConfigImpl(const ModelSafeRoutingInfo& routing_info,
361 const std::vector<ModelSafeWorker*>& workers) { 410 const std::vector<ModelSafeWorker*>& workers,
411 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) {
362 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 412 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
363 413
364 // TODO(tim): config-specific GetUpdatesCallerInfo value? 414 // TODO(tim): config-specific GetUpdatesCallerInfo value?
365 SyncSession* session = new SyncSession(session_context_.get(), this, 415 SyncSession* session = new SyncSession(session_context_.get(), this,
366 SyncSourceInfo(GetUpdatesCallerInfo::FIRST_UPDATE, 416 SyncSourceInfo(source,
367 syncable::ModelTypePayloadMapFromRoutingInfo( 417 syncable::ModelTypePayloadMapFromRoutingInfo(
368 routing_info, std::string())), 418 routing_info, std::string())),
369 routing_info, workers); 419 routing_info, workers);
370 ScheduleSyncSessionJob(TimeDelta::FromSeconds(0), CONFIGURATION, session, 420 ScheduleSyncSessionJob(TimeDelta::FromSeconds(0),
371 FROM_HERE); 421 SyncSessionJob::CONFIGURATION, session, FROM_HERE);
372 } 422 }
373 423
374 void SyncerThread::ScheduleSyncSessionJob(const base::TimeDelta& delay, 424 void SyncerThread::ScheduleSyncSessionJob(const base::TimeDelta& delay,
375 SyncSessionJobPurpose purpose, sessions::SyncSession* session, 425 SyncSessionJob::SyncSessionJobPurpose purpose,
426 sessions::SyncSession* session,
376 const tracked_objects::Location& nudge_location) { 427 const tracked_objects::Location& nudge_location) {
377 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 428 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
378 429
379 SyncSessionJob job = {purpose, TimeTicks::Now() + delay, 430 SyncSessionJob job(purpose, TimeTicks::Now() + delay,
380 make_linked_ptr(session), nudge_location}; 431 make_linked_ptr(session), false, nudge_location);
381 if (purpose == NUDGE) { 432 if (purpose == SyncSessionJob::NUDGE) {
382 DCHECK(!pending_nudge_.get() || pending_nudge_->session.get() == session); 433 DCHECK(!pending_nudge_.get() || pending_nudge_->session.get() == session);
383 pending_nudge_.reset(new SyncSessionJob(job)); 434 pending_nudge_.reset(new SyncSessionJob(job));
384 } 435 }
385 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod(this, 436 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod(this,
386 &SyncerThread::DoSyncSessionJob, job), 437 &SyncerThread::DoSyncSessionJob, job),
387 delay.InMilliseconds()); 438 delay.InMilliseconds());
388 } 439 }
389 440
390 void SyncerThread::SetSyncerStepsForPurpose(SyncSessionJobPurpose purpose, 441 void SyncerThread::SetSyncerStepsForPurpose(
442 SyncSessionJob::SyncSessionJobPurpose purpose,
391 SyncerStep* start, SyncerStep* end) { 443 SyncerStep* start, SyncerStep* end) {
392 *end = SYNCER_END; 444 *end = SYNCER_END;
393 switch (purpose) { 445 switch (purpose) {
394 case CONFIGURATION: 446 case SyncSessionJob::CONFIGURATION:
395 *start = DOWNLOAD_UPDATES; 447 *start = DOWNLOAD_UPDATES;
396 *end = APPLY_UPDATES; 448 *end = APPLY_UPDATES;
397 return; 449 return;
398 case CLEAR_USER_DATA: 450 case SyncSessionJob::CLEAR_USER_DATA:
399 *start = CLEAR_PRIVATE_DATA; 451 *start = CLEAR_PRIVATE_DATA;
400 return; 452 return;
401 case NUDGE: 453 case SyncSessionJob::NUDGE:
402 case POLL: 454 case SyncSessionJob::POLL:
403 *start = SYNCER_BEGIN; 455 *start = SYNCER_BEGIN;
404 return; 456 return;
405 default: 457 default:
406 NOTREACHED(); 458 NOTREACHED();
407 } 459 }
408 } 460 }
409 461
410 void SyncerThread::DoSyncSessionJob(const SyncSessionJob& job) { 462 void SyncerThread::DoSyncSessionJob(const SyncSessionJob& job) {
411 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 463 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
412 if (!ShouldRunJob(job.purpose, job.scheduled_start)) { 464 if (!ShouldRunJob(job))
413 LOG(WARNING) << "Dropping nudge at DoSyncSessionJob, source = "
414 << job.session->source().updates_source;
415 return; 465 return;
416 }
417 466
418 if (job.purpose == NUDGE) { 467 if (job.purpose == SyncSessionJob::NUDGE) {
419 DCHECK(pending_nudge_.get()); 468 DCHECK(pending_nudge_.get());
420 if (pending_nudge_->session != job.session) 469 if (pending_nudge_->session != job.session)
421 return; // Another nudge must have been scheduled in in the meantime. 470 return; // Another nudge must have been scheduled in in the meantime.
422 pending_nudge_.reset(); 471 pending_nudge_.reset();
423 } 472 }
424 473
425 SyncerStep begin(SYNCER_BEGIN); 474 SyncerStep begin(SYNCER_BEGIN);
426 SyncerStep end(SYNCER_END); 475 SyncerStep end(SYNCER_END);
427 SetSyncerStepsForPurpose(job.purpose, &begin, &end); 476 SetSyncerStepsForPurpose(job.purpose, &begin, &end);
428 477
429 bool has_more_to_sync = true; 478 bool has_more_to_sync = true;
430 while (ShouldRunJob(job.purpose, job.scheduled_start) && has_more_to_sync) { 479 while (ShouldRunJob(job) && has_more_to_sync) {
431 VLOG(1) << "SyncerThread: Calling SyncShare."; 480 VLOG(1) << "SyncerThread: Calling SyncShare.";
432 // Synchronously perform the sync session from this thread. 481 // Synchronously perform the sync session from this thread.
433 syncer_->SyncShare(job.session.get(), begin, end); 482 syncer_->SyncShare(job.session.get(), begin, end);
434 has_more_to_sync = job.session->HasMoreToSync(); 483 has_more_to_sync = job.session->HasMoreToSync();
435 if (has_more_to_sync) 484 if (has_more_to_sync)
436 job.session->ResetTransientState(); 485 job.session->ResetTransientState();
437 } 486 }
438 VLOG(1) << "SyncerThread: Done SyncShare looping."; 487 VLOG(1) << "SyncerThread: Done SyncShare looping.";
439 FinishSyncSessionJob(job); 488 FinishSyncSessionJob(job);
440 } 489 }
441 490
442 void SyncerThread::UpdateCarryoverSessionState(const SyncSessionJob& old_job) { 491 void SyncerThread::UpdateCarryoverSessionState(const SyncSessionJob& old_job) {
443 if (old_job.purpose == CONFIGURATION) { 492 if (old_job.purpose == SyncSessionJob::CONFIGURATION) {
444 // Whatever types were part of a configuration task will have had updates 493 // Whatever types were part of a configuration task will have had updates
445 // downloaded. For that reason, we make sure they get recorded in the 494 // downloaded. For that reason, we make sure they get recorded in the
446 // event that they get disabled at a later time. 495 // event that they get disabled at a later time.
447 ModelSafeRoutingInfo r(session_context_->previous_session_routing_info()); 496 ModelSafeRoutingInfo r(session_context_->previous_session_routing_info());
448 if (!r.empty()) { 497 if (!r.empty()) {
449 ModelSafeRoutingInfo temp_r; 498 ModelSafeRoutingInfo temp_r;
450 ModelSafeRoutingInfo old_info(old_job.session->routing_info()); 499 ModelSafeRoutingInfo old_info(old_job.session->routing_info());
451 std::set_union(r.begin(), r.end(), old_info.begin(), old_info.end(), 500 std::set_union(r.begin(), r.end(), old_info.begin(), old_info.end(),
452 std::insert_iterator<ModelSafeRoutingInfo>(temp_r, temp_r.begin())); 501 std::insert_iterator<ModelSafeRoutingInfo>(temp_r, temp_r.begin()));
453 session_context_->set_previous_session_routing_info(temp_r); 502 session_context_->set_previous_session_routing_info(temp_r);
(...skipping 12 matching lines...) Expand all
466 ModelTypePayloadMap::const_iterator iter; 515 ModelTypePayloadMap::const_iterator iter;
467 for (iter = job.session->source().types.begin(); 516 for (iter = job.session->source().types.begin();
468 iter != job.session->source().types.end(); 517 iter != job.session->source().types.end();
469 ++iter) { 518 ++iter) {
470 syncable::PostTimeToTypeHistogram(iter->first, 519 syncable::PostTimeToTypeHistogram(iter->first,
471 now - last_sync_session_end_time_); 520 now - last_sync_session_end_time_);
472 } 521 }
473 } 522 }
474 last_sync_session_end_time_ = now; 523 last_sync_session_end_time_ = now;
475 UpdateCarryoverSessionState(job); 524 UpdateCarryoverSessionState(job);
476 if (IsSyncingCurrentlySilenced()) 525 if (IsSyncingCurrentlySilenced()) {
526 SaveJob(job); // We dont want to save polls.
477 return; // Nothing to do. 527 return; // Nothing to do.
528 }
478 529
479 VLOG(1) << "Updating the next polling time after SyncMain"; 530 VLOG(1) << "Updating the next polling time after SyncMain";
480 ScheduleNextSync(job); 531 ScheduleNextSync(job);
481 } 532 }
482 533
483 void SyncerThread::ScheduleNextSync(const SyncSessionJob& old_job) { 534 void SyncerThread::ScheduleNextSync(const SyncSessionJob& old_job) {
484 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 535 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
485 DCHECK(!old_job.session->HasMoreToSync()); 536 DCHECK(!old_job.session->HasMoreToSync());
486 // Note: |num_server_changes_remaining| > 0 here implies that we received a 537 // Note: |num_server_changes_remaining| > 0 here implies that we received a
487 // broken response while trying to download all updates, because the Syncer 538 // broken response while trying to download all updates, because the Syncer
488 // will loop until this value is exhausted. Also, if unsynced_handles exist 539 // will loop until this value is exhausted. Also, if unsynced_handles exist
489 // but HasMoreToSync is false, this implies that the Syncer determined no 540 // but HasMoreToSync is false, this implies that the Syncer determined no
490 // forward progress was possible at this time (an error, such as an HTTP 541 // forward progress was possible at this time (an error, such as an HTTP
491 // 500, is likely to have occurred during commit). 542 // 500, is likely to have occurred during commit).
492 const bool work_to_do = 543 const bool work_to_do =
493 old_job.session->status_controller()->num_server_changes_remaining() > 0 544 old_job.session->status_controller()->num_server_changes_remaining() > 0
494 || old_job.session->status_controller()->unsynced_handles().size() > 0; 545 || old_job.session->status_controller()->unsynced_handles().size() > 0;
495 VLOG(1) << "syncer has work to do: " << work_to_do; 546 VLOG(1) << "syncer has work to do: " << work_to_do;
496 547
497 AdjustPolling(&old_job); 548 AdjustPolling(&old_job);
498 549
499 // TODO(tim): Old impl had special code if notifications disabled. Needed? 550 // TODO(tim): Old impl had special code if notifications disabled. Needed?
500 if (!work_to_do) { 551 if (!work_to_do) {
501 // Success implies backoff relief. Note that if this was a "one-off" job 552 // Success implies backoff relief. Note that if this was a "one-off" job
502 // (i.e. purpose == CLEAR_USER_DATA), if there was work_to_do before it 553 // (i.e. purpose == SyncSessionJob::CLEAR_USER_DATA),
503 // ran this wont have changed, as jobs like this don't run a full sync 554 // if there was work_to_do before it ran this wont have changed,
504 // cycle. So we don't need special code here. 555 // as jobs like this don't run a full sync cycle. So we don't need
556 // special code here.
505 wait_interval_.reset(); 557 wait_interval_.reset();
506 return; 558 return;
507 } 559 }
508 560
509 if (old_job.session->source().updates_source == 561 if (old_job.session->source().updates_source ==
510 GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION) { 562 GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION) {
511 // We don't seem to have made forward progress. Start or extend backoff. 563 // We don't seem to have made forward progress. Start or extend backoff.
512 HandleConsecutiveContinuationError(old_job); 564 HandleConsecutiveContinuationError(old_job);
513 } else if (IsBackingOff()) { 565 } else if (IsBackingOff()) {
514 // We weren't continuing but we're in backoff; must have been a nudge. 566 // We weren't continuing but we're in backoff; must have been a nudge.
515 DCHECK_EQ(NUDGE, old_job.purpose); 567 DCHECK_EQ(SyncSessionJob::NUDGE, old_job.purpose);
516 DCHECK(!wait_interval_->had_nudge); 568 DCHECK(!wait_interval_->had_nudge);
517 wait_interval_->had_nudge = true; 569 wait_interval_->had_nudge = true;
518 wait_interval_->timer.Reset(); 570 wait_interval_->timer.Reset();
519 } else { 571 } else {
520 // We weren't continuing and we aren't in backoff. Schedule a normal 572 // We weren't continuing and we aren't in backoff. Schedule a normal
521 // continuation. 573 // continuation.
522 ScheduleNudgeImpl(TimeDelta::FromSeconds(0), NUDGE_SOURCE_CONTINUATION, 574 if (old_job.purpose == SyncSessionJob::CONFIGURATION) {
523 old_job.session->source().types, FROM_HERE); 575 ScheduleConfigImpl(old_job.session->routing_info(),
576 old_job.session->workers(),
577 GetUpdatesFromNudgeSource(NUDGE_SOURCE_CONTINUATION));
578 } else {
579 // For all other purposes(nudge and poll) we schedule a retry nudge.
580 ScheduleNudgeImpl(TimeDelta::FromSeconds(0),
581 GetUpdatesFromNudgeSource(NUDGE_SOURCE_CONTINUATION),
582 old_job.session->source().types, false, FROM_HERE);
583 }
524 } 584 }
525 } 585 }
526 586
527 void SyncerThread::AdjustPolling(const SyncSessionJob* old_job) { 587 void SyncerThread::AdjustPolling(const SyncSessionJob* old_job) {
528 DCHECK(thread_.IsRunning()); 588 DCHECK(thread_.IsRunning());
529 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 589 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
530 590
531 TimeDelta poll = (!session_context_->notifications_enabled()) ? 591 TimeDelta poll = (!session_context_->notifications_enabled()) ?
532 syncer_short_poll_interval_seconds_ : 592 syncer_short_poll_interval_seconds_ :
533 syncer_long_poll_interval_seconds_; 593 syncer_long_poll_interval_seconds_;
534 bool rate_changed = !poll_timer_.IsRunning() || 594 bool rate_changed = !poll_timer_.IsRunning() ||
535 poll != poll_timer_.GetCurrentDelay(); 595 poll != poll_timer_.GetCurrentDelay();
536 596
537 if (old_job && old_job->purpose != POLL && !rate_changed) 597 if (old_job && old_job->purpose != SyncSessionJob::POLL && !rate_changed)
538 poll_timer_.Reset(); 598 poll_timer_.Reset();
539 599
540 if (!rate_changed) 600 if (!rate_changed)
541 return; 601 return;
542 602
543 // Adjust poll rate. 603 // Adjust poll rate.
544 poll_timer_.Stop(); 604 poll_timer_.Stop();
545 poll_timer_.Start(poll, this, &SyncerThread::PollTimerCallback); 605 poll_timer_.Start(poll, this, &SyncerThread::PollTimerCallback);
546 } 606 }
547 607
548 void SyncerThread::HandleConsecutiveContinuationError( 608 void SyncerThread::HandleConsecutiveContinuationError(
549 const SyncSessionJob& old_job) { 609 const SyncSessionJob& old_job) {
550 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 610 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
551 DCHECK(!IsBackingOff() || !wait_interval_->timer.IsRunning()); 611 // This if conditions should be compiled out in retail builds.
612 if (IsBackingOff()) {
613 DCHECK(wait_interval_->timer.IsRunning() || old_job.is_canary_job);
614 }
552 SyncSession* old = old_job.session.get(); 615 SyncSession* old = old_job.session.get();
553 SyncSession* s(new SyncSession(session_context_.get(), this, 616 SyncSession* s(new SyncSession(session_context_.get(), this,
554 old->source(), old->routing_info(), old->workers())); 617 old->source(), old->routing_info(), old->workers()));
555 TimeDelta length = delay_provider_->GetDelay( 618 TimeDelta length = delay_provider_->GetDelay(
556 IsBackingOff() ? wait_interval_->length : TimeDelta::FromSeconds(1)); 619 IsBackingOff() ? wait_interval_->length : TimeDelta::FromSeconds(1));
620
621 // This will reset the had_nudge variable as well.
557 wait_interval_.reset(new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, 622 wait_interval_.reset(new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF,
558 length)); 623 length));
559 SyncSessionJob job = {NUDGE, TimeTicks::Now() + length, 624 if (old_job.purpose == SyncSessionJob::CONFIGURATION) {
560 make_linked_ptr(s), FROM_HERE}; 625 SyncSessionJob job(old_job.purpose, TimeTicks::Now() + length,
561 pending_nudge_.reset(new SyncSessionJob(job)); 626 make_linked_ptr(s), false, FROM_HERE);
627 wait_interval_->pending_configure_job.reset(new SyncSessionJob(job));
628 } else {
629 // We are not in configuration mode. So wait_interval's pending job
630 // should be null.
631 DCHECK(wait_interval_->pending_configure_job.get() == NULL);
632
633 // TODO(lipalani) - handle clear user data.
634 InitOrCoalesceJob(old_job);
tim (not reviewing) 2011/04/13 21:40:18 should include the word 'pending'Job, otherwise 'I
lipalani1 2011/04/13 22:45:14 Done.
635 }
562 wait_interval_->timer.Start(length, this, &SyncerThread::DoCanaryJob); 636 wait_interval_->timer.Start(length, this, &SyncerThread::DoCanaryJob);
563 } 637 }
564 638
565 // static 639 // static
566 TimeDelta SyncerThread::GetRecommendedDelay(const TimeDelta& last_delay) { 640 TimeDelta SyncerThread::GetRecommendedDelay(const TimeDelta& last_delay) {
567 if (last_delay.InSeconds() >= kMaxBackoffSeconds) 641 if (last_delay.InSeconds() >= kMaxBackoffSeconds)
568 return TimeDelta::FromSeconds(kMaxBackoffSeconds); 642 return TimeDelta::FromSeconds(kMaxBackoffSeconds);
569 643
570 // This calculates approx. base_delay_seconds * 2 +/- base_delay_seconds / 2 644 // This calculates approx. base_delay_seconds * 2 +/- base_delay_seconds / 2
571 int64 backoff_s = 645 int64 backoff_s =
(...skipping 14 matching lines...) Expand all
586 return TimeDelta::FromSeconds(backoff_s); 660 return TimeDelta::FromSeconds(backoff_s);
587 } 661 }
588 662
589 void SyncerThread::Stop() { 663 void SyncerThread::Stop() {
590 syncer_->RequestEarlyExit(); // Safe to call from any thread. 664 syncer_->RequestEarlyExit(); // Safe to call from any thread.
591 session_context_->connection_manager()->RemoveListener(this); 665 session_context_->connection_manager()->RemoveListener(this);
592 thread_.Stop(); 666 thread_.Stop();
593 } 667 }
594 668
595 void SyncerThread::DoCanaryJob() { 669 void SyncerThread::DoCanaryJob() {
596 DCHECK(pending_nudge_.get()); 670 // We should not be here unless wait interval was initialized due to
597 wait_interval_->had_nudge = false; 671 // throttling or backing off.
598 SyncSessionJob copy = *pending_nudge_; 672 DCHECK(wait_interval_.get());
599 DoSyncSessionJob(copy); 673
674 DoPendingJobIfPossible(true);
tim (not reviewing) 2011/04/13 21:40:18 Well, now I think we should just eliminate this me
lipalani1 2011/04/13 22:45:14 Implemented it as discussed. Regarding your point
675 }
676
677 void SyncerThread::DoPendingJobIfPossible(bool is_canary_job) {
678 SyncSessionJob* job_to_execute = NULL;
679 if (mode_ == CONFIGURATION_MODE && wait_interval_.get()
680 && wait_interval_->pending_configure_job.get()) {
681 job_to_execute = wait_interval_->pending_configure_job.get();
682 } else if (pending_nudge_.get()) {
683 // Pending jobs mostly have time from the past. Reset it so this job
684 // will get executed.
685 if (pending_nudge_->scheduled_start < TimeTicks::Now())
686 pending_nudge_->scheduled_start = TimeTicks::Now();
687
688 scoped_ptr<SyncSession> session(CreateSyncSession(
689 pending_nudge_->session->source()));
690
691 // Also the routing info might have been changed since we cached the
692 // pending nudge. Update it by coalescing to the latest.
693 pending_nudge_->session->Coalesce(*(session.get()));
694 // The pending nudge would be cleared in the DoSyncSessionJob function.
695 job_to_execute = pending_nudge_.get();
696 }
697
698 if (job_to_execute != NULL) {
699 SyncSessionJob copy = *job_to_execute;
700 copy.is_canary_job = is_canary_job;
701 DoSyncSessionJob(copy);
702 }
703 }
704
705 SyncSession* SyncerThread::CreateSyncSession(const SyncSourceInfo& source) {
706 ModelSafeRoutingInfo routes;
707 std::vector<ModelSafeWorker*> workers;
708 session_context_->registrar()->GetModelSafeRoutingInfo(&routes);
709 session_context_->registrar()->GetWorkers(&workers);
710 SyncSourceInfo info(source);
711
712 SyncSession* session(new SyncSession(session_context_.get(), this, info,
713 routes, workers));
714
715 return session;
600 } 716 }
601 717
602 void SyncerThread::PollTimerCallback() { 718 void SyncerThread::PollTimerCallback() {
603 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 719 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
604 ModelSafeRoutingInfo r; 720 ModelSafeRoutingInfo r;
605 std::vector<ModelSafeWorker*> w;
606 session_context_->registrar()->GetModelSafeRoutingInfo(&r);
607 session_context_->registrar()->GetWorkers(&w);
608 ModelTypePayloadMap types_with_payloads = 721 ModelTypePayloadMap types_with_payloads =
609 syncable::ModelTypePayloadMapFromRoutingInfo(r, std::string()); 722 syncable::ModelTypePayloadMapFromRoutingInfo(r, std::string());
610 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, types_with_payloads); 723 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, types_with_payloads);
611 SyncSession* s = new SyncSession(session_context_.get(), this, info, r, w); 724 SyncSession* s = CreateSyncSession(info);
612 ScheduleSyncSessionJob(TimeDelta::FromSeconds(0), POLL, s, FROM_HERE); 725 ScheduleSyncSessionJob(TimeDelta::FromSeconds(0), SyncSessionJob::POLL, s,
726 FROM_HERE);
613 } 727 }
614 728
615 void SyncerThread::Unthrottle() { 729 void SyncerThread::Unthrottle() {
616 DCHECK_EQ(WaitInterval::THROTTLED, wait_interval_->mode); 730 DCHECK_EQ(WaitInterval::THROTTLED, wait_interval_->mode);
731 DoCanaryJob();
617 wait_interval_.reset(); 732 wait_interval_.reset();
618 } 733 }
619 734
620 void SyncerThread::Notify(SyncEngineEvent::EventCause cause) { 735 void SyncerThread::Notify(SyncEngineEvent::EventCause cause) {
621 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 736 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
622 session_context_->NotifyListeners(SyncEngineEvent(cause)); 737 session_context_->NotifyListeners(SyncEngineEvent(cause));
623 } 738 }
624 739
625 bool SyncerThread::IsBackingOff() const { 740 bool SyncerThread::IsBackingOff() const {
626 return wait_interval_.get() && wait_interval_->mode == 741 return wait_interval_.get() && wait_interval_->mode ==
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 &SyncerThread::CheckServerConnectionManagerStatus, 777 &SyncerThread::CheckServerConnectionManagerStatus,
663 event.connection_code)); 778 event.connection_code));
664 } 779 }
665 780
666 void SyncerThread::set_notifications_enabled(bool notifications_enabled) { 781 void SyncerThread::set_notifications_enabled(bool notifications_enabled) {
667 session_context_->set_notifications_enabled(notifications_enabled); 782 session_context_->set_notifications_enabled(notifications_enabled);
668 } 783 }
669 784
670 } // s3 785 } // s3
671 } // browser_sync 786 } // browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698