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

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();
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();
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
180 SyncerThread::JobProcessDecision SyncerThread::DecideOnJob(
181 const SyncSessionJob& job) {
182 if (job.purpose == SyncSessionJob::CLEAR_USER_DATA)
183 return CONTINUE;
184
185 if (wait_interval_.get())
186 return DecideWhileInWaitInterval(job);
187
188 if (mode_ == CONFIGURATION_MODE) {
189 if (job.purpose == SyncSessionJob::NUDGE)
190 return SAVE;
191 else if (job.purpose == SyncSessionJob::CONFIGURATION)
192 return CONTINUE;
193 else
194 return DROP;
159 } 195 }
160 196
161 // Mode / purpose contract (See 'Mode' enum in header). Don't run jobs that 197 // We are in normal mode.
162 // were intended for a normal sync if we are in configuration mode, and vice 198 DCHECK_EQ(mode_, NORMAL_MODE);
163 // versa. 199 DCHECK_NE(job.purpose, SyncSessionJob::CONFIGURATION);
164 switch (mode_) { 200
165 case CONFIGURATION_MODE: 201 // Freshness condition
166 if (purpose != CONFIGURATION) 202 if (job.scheduled_start < last_sync_session_end_time_)
167 return false; 203 return DROP;
168 break; 204
169 case NORMAL_MODE: 205 if (server_connection_ok_)
170 if (purpose == CONFIGURATION) 206 return CONTINUE;
171 return false; 207
172 break; 208 return job.purpose == SyncSessionJob::NUDGE ? SAVE : DROP;
173 default: 209 }
174 NOTREACHED() << "Unknown SyncerThread Mode: " << mode_; 210
175 return false; 211 void SyncerThread::UpdatePendingJob(const SyncSessionJob& job) {
212 DCHECK(job.purpose != SyncSessionJob::CONFIGURATION);
213 if (pending_nudge_.get() == NULL) {
214 SyncSession* s = job.session.get();
215 scoped_ptr<SyncSession> session(new SyncSession(s->context(),
216 s->delegate(), s->source(), s->routing_info(), s->workers()));
217
218 SyncSessionJob new_job(SyncSessionJob::NUDGE, job.scheduled_start,
219 make_linked_ptr(session.release()), false, job.nudge_location);
220 pending_nudge_.reset(new SyncSessionJob(new_job));
221
222 return;
176 } 223 }
177 224
178 // Continuation NUDGE tasks have priority over POLLs because they are the 225 pending_nudge_->session->Coalesce(*(job.session.get()));
179 // only tasks that trigger exponential backoff, so this prevents them from 226 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 227
188 // Freshness condition. 228 // Unfortunately the nudge location cannot be modified. So it stores the
189 if (purpose == NUDGE && 229 // location of the first caller.
190 (scheduled_start < last_sync_session_end_time_)) {
191 return false;
192 }
193
194 return server_connection_ok_;
195 } 230 }
196 231
197 GetUpdatesCallerInfo::GetUpdatesSource GetUpdatesFromNudgeSource( 232 bool SyncerThread::ShouldRunJob(const SyncSessionJob& job) {
198 NudgeSource source) { 233 JobProcessDecision decision = DecideOnJob(job);
199 switch (source) { 234 if (decision != SAVE)
200 case NUDGE_SOURCE_NOTIFICATION: 235 return decision == CONTINUE ? true : false;
tim (not reviewing) 2011/04/12 06:09:29 what I meant before is that this is equivalent to
lipalani1 2011/04/13 00:07:29 Done.
201 return GetUpdatesCallerInfo::NOTIFICATION; 236
202 case NUDGE_SOURCE_LOCAL: 237 DCHECK(job.purpose == SyncSessionJob::NUDGE || job.purpose ==
203 return GetUpdatesCallerInfo::LOCAL; 238 SyncSessionJob::CONFIGURATION);
204 case NUDGE_SOURCE_CONTINUATION: 239
205 return GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION; 240 SaveJob(job);
206 case NUDGE_SOURCE_UNKNOWN: 241 return false;
207 return GetUpdatesCallerInfo::UNKNOWN; 242 }
208 default: 243
209 NOTREACHED(); 244 void SyncerThread::SaveJob(const SyncSessionJob& job) {
210 return GetUpdatesCallerInfo::UNKNOWN; 245 DCHECK(job.purpose != SyncSessionJob::CLEAR_USER_DATA);
246 if (job.purpose == SyncSessionJob::NUDGE || job.purpose ==
247 SyncSessionJob::POLL) {
248 UpdatePendingJob(job);
tim (not reviewing) 2011/04/12 06:09:29 What I was saying before was this might be more re
lipalani1 2011/04/13 00:07:29 Hmm.. this is used in 2 places. SaveJob and Handle
249 } else {
250 DCHECK(wait_interval_.get());
251 DCHECK(mode_ == CONFIGURATION_MODE);
252
253 SyncSession* old = job.session.get();
254 SyncSession* s(new SyncSession(session_context_.get(), this,
255 old->source(), old->routing_info(), old->workers()));
256 SyncSessionJob new_job(job.purpose, TimeTicks::Now(),
257 make_linked_ptr(s), false, job.nudge_location);
258 wait_interval_->pending_configure_job.reset(new SyncSessionJob(new_job));
211 } 259 }
212 } 260 }
213 261
214 // Functor for std::find_if to search by ModelSafeGroup. 262 // Functor for std::find_if to search by ModelSafeGroup.
215 struct ModelSafeWorkerGroupIs { 263 struct ModelSafeWorkerGroupIs {
216 explicit ModelSafeWorkerGroupIs(ModelSafeGroup group) : group(group) {} 264 explicit ModelSafeWorkerGroupIs(ModelSafeGroup group) : group(group) {}
217 bool operator()(ModelSafeWorker* w) { 265 bool operator()(ModelSafeWorker* w) {
218 return group == w->GetModelSafeGroup(); 266 return group == w->GetModelSafeGroup();
219 } 267 }
220 ModelSafeGroup group; 268 ModelSafeGroup group;
(...skipping 12 matching lines...) Expand all
233 NudgeSource source, const ModelTypeBitSet& types, 281 NudgeSource source, const ModelTypeBitSet& types,
234 const tracked_objects::Location& nudge_location) { 282 const tracked_objects::Location& nudge_location) {
235 if (!thread_.IsRunning()) { 283 if (!thread_.IsRunning()) {
236 NOTREACHED(); 284 NOTREACHED();
237 return; 285 return;
238 } 286 }
239 287
240 ModelTypePayloadMap types_with_payloads = 288 ModelTypePayloadMap types_with_payloads =
241 syncable::ModelTypePayloadMapFromBitSet(types, std::string()); 289 syncable::ModelTypePayloadMapFromBitSet(types, std::string());
242 thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod( 290 thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
243 this, &SyncerThread::ScheduleNudgeImpl, delay, source, 291 this, &SyncerThread::ScheduleNudgeImpl, delay,
244 types_with_payloads, nudge_location)); 292 GetUpdatesFromNudgeSource(source), types_with_payloads, false,
293 nudge_location));
245 } 294 }
246 295
247 void SyncerThread::ScheduleNudgeWithPayloads(const TimeDelta& delay, 296 void SyncerThread::ScheduleNudgeWithPayloads(const TimeDelta& delay,
248 NudgeSource source, const ModelTypePayloadMap& types_with_payloads, 297 NudgeSource source, const ModelTypePayloadMap& types_with_payloads,
249 const tracked_objects::Location& nudge_location) { 298 const tracked_objects::Location& nudge_location) {
250 if (!thread_.IsRunning()) { 299 if (!thread_.IsRunning()) {
251 NOTREACHED(); 300 NOTREACHED();
252 return; 301 return;
253 } 302 }
254 303
255 thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod( 304 thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
256 this, &SyncerThread::ScheduleNudgeImpl, delay, source, 305 this, &SyncerThread::ScheduleNudgeImpl, delay,
257 types_with_payloads, nudge_location)); 306 GetUpdatesFromNudgeSource(source), types_with_payloads, false,
307 nudge_location));
258 } 308 }
259 309
260 void SyncerThread::ScheduleClearUserDataImpl() { 310 void SyncerThread::ScheduleClearUserDataImpl() {
261 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 311 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
262 SyncSession* session = new SyncSession(session_context_.get(), this, 312 SyncSession* session = new SyncSession(session_context_.get(), this,
263 SyncSourceInfo(), ModelSafeRoutingInfo(), 313 SyncSourceInfo(), ModelSafeRoutingInfo(),
264 std::vector<ModelSafeWorker*>()); 314 std::vector<ModelSafeWorker*>());
265 ScheduleSyncSessionJob(TimeDelta::FromSeconds(0), CLEAR_USER_DATA, session, 315 ScheduleSyncSessionJob(TimeDelta::FromSeconds(0),
266 FROM_HERE); 316 SyncSessionJob::CLEAR_USER_DATA, session, FROM_HERE);
267 } 317 }
268 318
269 void SyncerThread::ScheduleNudgeImpl(const TimeDelta& delay, 319 void SyncerThread::ScheduleNudgeImpl(const TimeDelta& delay,
270 NudgeSource source, const ModelTypePayloadMap& types_with_payloads, 320 GetUpdatesCallerInfo::GetUpdatesSource source,
271 const tracked_objects::Location& nudge_location) { 321 const ModelTypePayloadMap& types_with_payloads,
322 bool is_canary_job, const tracked_objects::Location& nudge_location) {
272 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 323 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 324
280 // Note we currently nudge for all types regardless of the ones incurring 325 // Note we currently nudge for all types regardless of the ones incurring
281 // the nudge. Doing different would throw off some syncer commands like 326 // the nudge. Doing different would throw off some syncer commands like
282 // CleanupDisabledTypes. We may want to change this in the future. 327 // CleanupDisabledTypes. We may want to change this in the future.
283 ModelSafeRoutingInfo routes; 328 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 329
290 scoped_ptr<SyncSession> session(new SyncSession( 330 SyncSession* session(CreateSyncSession(info));
291 session_context_.get(), this, info, routes, workers)); 331
332 SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now() + delay,
333 make_linked_ptr(session), is_canary_job,
334 nudge_location);
335
336 session = NULL;
337 if (!ShouldRunJob(job))
338 return;
292 339
293 if (pending_nudge_.get()) { 340 if (pending_nudge_.get()) {
294 if (IsBackingOff() && delay > TimeDelta::FromSeconds(1)) 341 if (IsBackingOff() && delay > TimeDelta::FromSeconds(1))
295 return; 342 return;
296 343
297 pending_nudge_->session->Coalesce(*session.get()); 344 pending_nudge_->session->Coalesce(*(job.session.get()));
298 345
299 if (!IsBackingOff()) { 346 if (!IsBackingOff()) {
300 return; 347 return;
301 } else { 348 } else {
302 // Re-schedule the current pending nudge. 349 // Re-schedule the current pending nudge.
303 SyncSession* s = pending_nudge_->session.get(); 350 SyncSession* s = pending_nudge_->session.get();
304 session.reset(new SyncSession(s->context(), s->delegate(), s->source(), 351 job.session.reset(new SyncSession(s->context(), s->delegate(),
305 s->routing_info(), s->workers())); 352 s->source(), s->routing_info(), s->workers()));
306 pending_nudge_.reset(); 353 pending_nudge_.reset();
307 } 354 }
308 } 355 }
309 ScheduleSyncSessionJob(delay, NUDGE, session.release(), nudge_location); 356
357 // TODO(lipalani) - pass the job itself to ScheduleSyncSessionJob.
358 ScheduleSyncSessionJob(delay, SyncSessionJob::NUDGE, job.session.release(),
359 nudge_location);
310 } 360 }
311 361
312 // Helper to extract the routing info and workers corresponding to types in 362 // Helper to extract the routing info and workers corresponding to types in
313 // |types| from |registrar|. 363 // |types| from |registrar|.
314 void GetModelSafeParamsForTypes(const ModelTypeBitSet& types, 364 void GetModelSafeParamsForTypes(const ModelTypeBitSet& types,
315 ModelSafeWorkerRegistrar* registrar, ModelSafeRoutingInfo* routes, 365 ModelSafeWorkerRegistrar* registrar, ModelSafeRoutingInfo* routes,
316 std::vector<ModelSafeWorker*>* workers) { 366 std::vector<ModelSafeWorker*>* workers) {
317 ModelSafeRoutingInfo r_tmp; 367 ModelSafeRoutingInfo r_tmp;
318 std::vector<ModelSafeWorker*> w_tmp; 368 std::vector<ModelSafeWorker*> w_tmp;
319 registrar->GetModelSafeRoutingInfo(&r_tmp); 369 registrar->GetModelSafeRoutingInfo(&r_tmp);
(...skipping 27 matching lines...) Expand all
347 NOTREACHED(); 397 NOTREACHED();
348 return; 398 return;
349 } 399 }
350 400
351 ModelSafeRoutingInfo routes; 401 ModelSafeRoutingInfo routes;
352 std::vector<ModelSafeWorker*> workers; 402 std::vector<ModelSafeWorker*> workers;
353 GetModelSafeParamsForTypes(types, session_context_->registrar(), 403 GetModelSafeParamsForTypes(types, session_context_->registrar(),
354 &routes, &workers); 404 &routes, &workers);
355 405
356 thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod( 406 thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
357 this, &SyncerThread::ScheduleConfigImpl, routes, workers)); 407 this, &SyncerThread::ScheduleConfigImpl, routes, workers,
408 GetUpdatesCallerInfo::FIRST_UPDATE));
358 } 409 }
359 410
360 void SyncerThread::ScheduleConfigImpl(const ModelSafeRoutingInfo& routing_info, 411 void SyncerThread::ScheduleConfigImpl(const ModelSafeRoutingInfo& routing_info,
361 const std::vector<ModelSafeWorker*>& workers) { 412 const std::vector<ModelSafeWorker*>& workers,
413 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) {
362 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 414 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
363 415
364 // TODO(tim): config-specific GetUpdatesCallerInfo value? 416 // TODO(tim): config-specific GetUpdatesCallerInfo value?
365 SyncSession* session = new SyncSession(session_context_.get(), this, 417 SyncSession* session = new SyncSession(session_context_.get(), this,
366 SyncSourceInfo(GetUpdatesCallerInfo::FIRST_UPDATE, 418 SyncSourceInfo(source,
367 syncable::ModelTypePayloadMapFromRoutingInfo( 419 syncable::ModelTypePayloadMapFromRoutingInfo(
368 routing_info, std::string())), 420 routing_info, std::string())),
369 routing_info, workers); 421 routing_info, workers);
370 ScheduleSyncSessionJob(TimeDelta::FromSeconds(0), CONFIGURATION, session, 422 ScheduleSyncSessionJob(TimeDelta::FromSeconds(0),
371 FROM_HERE); 423 SyncSessionJob::CONFIGURATION, session, FROM_HERE);
372 } 424 }
373 425
374 void SyncerThread::ScheduleSyncSessionJob(const base::TimeDelta& delay, 426 void SyncerThread::ScheduleSyncSessionJob(const base::TimeDelta& delay,
375 SyncSessionJobPurpose purpose, sessions::SyncSession* session, 427 SyncSessionJob::SyncSessionJobPurpose purpose,
428 sessions::SyncSession* session,
376 const tracked_objects::Location& nudge_location) { 429 const tracked_objects::Location& nudge_location) {
377 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 430 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
378 431
379 SyncSessionJob job = {purpose, TimeTicks::Now() + delay, 432 SyncSessionJob job(purpose, TimeTicks::Now() + delay,
380 make_linked_ptr(session), nudge_location}; 433 make_linked_ptr(session), false, nudge_location);
381 if (purpose == NUDGE) { 434 if (purpose == SyncSessionJob::NUDGE) {
382 DCHECK(!pending_nudge_.get() || pending_nudge_->session.get() == session); 435 DCHECK(!pending_nudge_.get() || pending_nudge_->session.get() == session);
383 pending_nudge_.reset(new SyncSessionJob(job)); 436 pending_nudge_.reset(new SyncSessionJob(job));
384 } 437 }
385 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod(this, 438 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod(this,
386 &SyncerThread::DoSyncSessionJob, job), 439 &SyncerThread::DoSyncSessionJob, job),
387 delay.InMilliseconds()); 440 delay.InMilliseconds());
388 } 441 }
389 442
390 void SyncerThread::SetSyncerStepsForPurpose(SyncSessionJobPurpose purpose, 443 void SyncerThread::SetSyncerStepsForPurpose(
444 SyncSessionJob::SyncSessionJobPurpose purpose,
391 SyncerStep* start, SyncerStep* end) { 445 SyncerStep* start, SyncerStep* end) {
392 *end = SYNCER_END; 446 *end = SYNCER_END;
393 switch (purpose) { 447 switch (purpose) {
394 case CONFIGURATION: 448 case SyncSessionJob::CONFIGURATION:
395 *start = DOWNLOAD_UPDATES; 449 *start = DOWNLOAD_UPDATES;
396 *end = APPLY_UPDATES; 450 *end = APPLY_UPDATES;
397 return; 451 return;
398 case CLEAR_USER_DATA: 452 case SyncSessionJob::CLEAR_USER_DATA:
399 *start = CLEAR_PRIVATE_DATA; 453 *start = CLEAR_PRIVATE_DATA;
400 return; 454 return;
401 case NUDGE: 455 case SyncSessionJob::NUDGE:
402 case POLL: 456 case SyncSessionJob::POLL:
403 *start = SYNCER_BEGIN; 457 *start = SYNCER_BEGIN;
404 return; 458 return;
405 default: 459 default:
406 NOTREACHED(); 460 NOTREACHED();
407 } 461 }
408 } 462 }
409 463
410 void SyncerThread::DoSyncSessionJob(const SyncSessionJob& job) { 464 void SyncerThread::DoSyncSessionJob(const SyncSessionJob& job) {
411 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 465 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
412 if (!ShouldRunJob(job.purpose, job.scheduled_start)) { 466 if (!ShouldRunJob(job))
413 LOG(WARNING) << "Dropping nudge at DoSyncSessionJob, source = "
414 << job.session->source().updates_source;
415 return; 467 return;
416 }
417 468
418 if (job.purpose == NUDGE) { 469 if (job.purpose == SyncSessionJob::NUDGE) {
419 DCHECK(pending_nudge_.get()); 470 DCHECK(pending_nudge_.get());
420 if (pending_nudge_->session != job.session) 471 if (pending_nudge_->session != job.session)
421 return; // Another nudge must have been scheduled in in the meantime. 472 return; // Another nudge must have been scheduled in in the meantime.
422 pending_nudge_.reset(); 473 pending_nudge_.reset();
423 } 474 }
424 475
425 SyncerStep begin(SYNCER_BEGIN); 476 SyncerStep begin(SYNCER_BEGIN);
426 SyncerStep end(SYNCER_END); 477 SyncerStep end(SYNCER_END);
427 SetSyncerStepsForPurpose(job.purpose, &begin, &end); 478 SetSyncerStepsForPurpose(job.purpose, &begin, &end);
428 479
429 bool has_more_to_sync = true; 480 bool has_more_to_sync = true;
430 while (ShouldRunJob(job.purpose, job.scheduled_start) && has_more_to_sync) { 481 while (ShouldRunJob(job) && has_more_to_sync) {
431 VLOG(1) << "SyncerThread: Calling SyncShare."; 482 VLOG(1) << "SyncerThread: Calling SyncShare.";
432 // Synchronously perform the sync session from this thread. 483 // Synchronously perform the sync session from this thread.
433 syncer_->SyncShare(job.session.get(), begin, end); 484 syncer_->SyncShare(job.session.get(), begin, end);
434 has_more_to_sync = job.session->HasMoreToSync(); 485 has_more_to_sync = job.session->HasMoreToSync();
435 if (has_more_to_sync) 486 if (has_more_to_sync)
436 job.session->ResetTransientState(); 487 job.session->ResetTransientState();
437 } 488 }
438 VLOG(1) << "SyncerThread: Done SyncShare looping."; 489 VLOG(1) << "SyncerThread: Done SyncShare looping.";
439 FinishSyncSessionJob(job); 490 FinishSyncSessionJob(job);
440 } 491 }
441 492
442 void SyncerThread::UpdateCarryoverSessionState(const SyncSessionJob& old_job) { 493 void SyncerThread::UpdateCarryoverSessionState(const SyncSessionJob& old_job) {
443 if (old_job.purpose == CONFIGURATION) { 494 if (old_job.purpose == SyncSessionJob::CONFIGURATION) {
444 // Whatever types were part of a configuration task will have had updates 495 // 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 496 // downloaded. For that reason, we make sure they get recorded in the
446 // event that they get disabled at a later time. 497 // event that they get disabled at a later time.
447 ModelSafeRoutingInfo r(session_context_->previous_session_routing_info()); 498 ModelSafeRoutingInfo r(session_context_->previous_session_routing_info());
448 if (!r.empty()) { 499 if (!r.empty()) {
449 ModelSafeRoutingInfo temp_r; 500 ModelSafeRoutingInfo temp_r;
450 ModelSafeRoutingInfo old_info(old_job.session->routing_info()); 501 ModelSafeRoutingInfo old_info(old_job.session->routing_info());
451 std::set_union(r.begin(), r.end(), old_info.begin(), old_info.end(), 502 std::set_union(r.begin(), r.end(), old_info.begin(), old_info.end(),
452 std::insert_iterator<ModelSafeRoutingInfo>(temp_r, temp_r.begin())); 503 std::insert_iterator<ModelSafeRoutingInfo>(temp_r, temp_r.begin()));
453 session_context_->set_previous_session_routing_info(temp_r); 504 session_context_->set_previous_session_routing_info(temp_r);
(...skipping 12 matching lines...) Expand all
466 ModelTypePayloadMap::const_iterator iter; 517 ModelTypePayloadMap::const_iterator iter;
467 for (iter = job.session->source().types.begin(); 518 for (iter = job.session->source().types.begin();
468 iter != job.session->source().types.end(); 519 iter != job.session->source().types.end();
469 ++iter) { 520 ++iter) {
470 syncable::PostTimeToTypeHistogram(iter->first, 521 syncable::PostTimeToTypeHistogram(iter->first,
471 now - last_sync_session_end_time_); 522 now - last_sync_session_end_time_);
472 } 523 }
473 } 524 }
474 last_sync_session_end_time_ = now; 525 last_sync_session_end_time_ = now;
475 UpdateCarryoverSessionState(job); 526 UpdateCarryoverSessionState(job);
476 if (IsSyncingCurrentlySilenced()) 527 if (IsSyncingCurrentlySilenced()) {
528 // Let us save the job. So when we are unthrottled we can execute it.
529 SaveJob(job);
477 return; // Nothing to do. 530 return; // Nothing to do.
531 }
478 532
479 VLOG(1) << "Updating the next polling time after SyncMain"; 533 VLOG(1) << "Updating the next polling time after SyncMain";
480 ScheduleNextSync(job); 534 ScheduleNextSync(job);
481 } 535 }
482 536
483 void SyncerThread::ScheduleNextSync(const SyncSessionJob& old_job) { 537 void SyncerThread::ScheduleNextSync(const SyncSessionJob& old_job) {
484 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 538 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
485 DCHECK(!old_job.session->HasMoreToSync()); 539 DCHECK(!old_job.session->HasMoreToSync());
486 // Note: |num_server_changes_remaining| > 0 here implies that we received a 540 // Note: |num_server_changes_remaining| > 0 here implies that we received a
487 // broken response while trying to download all updates, because the Syncer 541 // broken response while trying to download all updates, because the Syncer
488 // will loop until this value is exhausted. Also, if unsynced_handles exist 542 // will loop until this value is exhausted. Also, if unsynced_handles exist
489 // but HasMoreToSync is false, this implies that the Syncer determined no 543 // 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 544 // forward progress was possible at this time (an error, such as an HTTP
491 // 500, is likely to have occurred during commit). 545 // 500, is likely to have occurred during commit).
492 const bool work_to_do = 546 const bool work_to_do =
493 old_job.session->status_controller()->num_server_changes_remaining() > 0 547 old_job.session->status_controller()->num_server_changes_remaining() > 0
494 || old_job.session->status_controller()->unsynced_handles().size() > 0; 548 || old_job.session->status_controller()->unsynced_handles().size() > 0;
495 VLOG(1) << "syncer has work to do: " << work_to_do; 549 VLOG(1) << "syncer has work to do: " << work_to_do;
496 550
497 AdjustPolling(&old_job); 551 AdjustPolling(&old_job);
498 552
499 // TODO(tim): Old impl had special code if notifications disabled. Needed? 553 // TODO(tim): Old impl had special code if notifications disabled. Needed?
500 if (!work_to_do) { 554 if (!work_to_do) {
501 // Success implies backoff relief. Note that if this was a "one-off" job 555 // 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 556 // (i.e. purpose == SyncSessionJob::CLEAR_USER_DATA),
503 // ran this wont have changed, as jobs like this don't run a full sync 557 // if there was work_to_do before it ran this wont have changed,
504 // cycle. So we don't need special code here. 558 // as jobs like this don't run a full sync cycle. So we don't need
559 // special code here.
505 wait_interval_.reset(); 560 wait_interval_.reset();
506 return; 561 return;
507 } 562 }
508 563
509 if (old_job.session->source().updates_source == 564 if (old_job.session->source().updates_source ==
510 GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION) { 565 GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION) {
511 // We don't seem to have made forward progress. Start or extend backoff. 566 // We don't seem to have made forward progress. Start or extend backoff.
512 HandleConsecutiveContinuationError(old_job); 567 HandleConsecutiveContinuationError(old_job);
513 } else if (IsBackingOff()) { 568 } else if (IsBackingOff()) {
514 // We weren't continuing but we're in backoff; must have been a nudge. 569 // We weren't continuing but we're in backoff; must have been a nudge.
515 DCHECK_EQ(NUDGE, old_job.purpose); 570 DCHECK_EQ(SyncSessionJob::NUDGE, old_job.purpose);
516 DCHECK(!wait_interval_->had_nudge); 571 DCHECK(!wait_interval_->had_nudge);
517 wait_interval_->had_nudge = true; 572 wait_interval_->had_nudge = true;
518 wait_interval_->timer.Reset(); 573 wait_interval_->timer.Reset();
519 } else { 574 } else {
520 // We weren't continuing and we aren't in backoff. Schedule a normal 575 // We weren't continuing and we aren't in backoff. Schedule a normal
521 // continuation. 576 // continuation.
522 ScheduleNudgeImpl(TimeDelta::FromSeconds(0), NUDGE_SOURCE_CONTINUATION, 577 if (old_job.purpose == SyncSessionJob::CONFIGURATION) {
523 old_job.session->source().types, FROM_HERE); 578 ScheduleConfigImpl(old_job.session->routing_info(),
579 old_job.session->workers(),
580 GetUpdatesFromNudgeSource(NUDGE_SOURCE_CONTINUATION));
581 } else {
582 // For all other purposes(nudge and poll) we schedule a retry nudge.
583 ScheduleNudgeImpl(TimeDelta::FromSeconds(0),
584 GetUpdatesFromNudgeSource(NUDGE_SOURCE_CONTINUATION),
585 old_job.session->source().types, false, FROM_HERE);
586 }
524 } 587 }
525 } 588 }
526 589
527 void SyncerThread::AdjustPolling(const SyncSessionJob* old_job) { 590 void SyncerThread::AdjustPolling(const SyncSessionJob* old_job) {
528 DCHECK(thread_.IsRunning()); 591 DCHECK(thread_.IsRunning());
529 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 592 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
530 593
531 TimeDelta poll = (!session_context_->notifications_enabled()) ? 594 TimeDelta poll = (!session_context_->notifications_enabled()) ?
532 syncer_short_poll_interval_seconds_ : 595 syncer_short_poll_interval_seconds_ :
533 syncer_long_poll_interval_seconds_; 596 syncer_long_poll_interval_seconds_;
534 bool rate_changed = !poll_timer_.IsRunning() || 597 bool rate_changed = !poll_timer_.IsRunning() ||
535 poll != poll_timer_.GetCurrentDelay(); 598 poll != poll_timer_.GetCurrentDelay();
536 599
537 if (old_job && old_job->purpose != POLL && !rate_changed) 600 if (old_job && old_job->purpose != SyncSessionJob::POLL && !rate_changed)
538 poll_timer_.Reset(); 601 poll_timer_.Reset();
539 602
540 if (!rate_changed) 603 if (!rate_changed)
541 return; 604 return;
542 605
543 // Adjust poll rate. 606 // Adjust poll rate.
544 poll_timer_.Stop(); 607 poll_timer_.Stop();
545 poll_timer_.Start(poll, this, &SyncerThread::PollTimerCallback); 608 poll_timer_.Start(poll, this, &SyncerThread::PollTimerCallback);
546 } 609 }
547 610
548 void SyncerThread::HandleConsecutiveContinuationError( 611 void SyncerThread::HandleConsecutiveContinuationError(
549 const SyncSessionJob& old_job) { 612 const SyncSessionJob& old_job) {
550 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 613 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
551 DCHECK(!IsBackingOff() || !wait_interval_->timer.IsRunning()); 614 DCHECK(!IsBackingOff() || wait_interval_.get() != NULL);
tim (not reviewing) 2011/04/12 06:09:29 this appears to be the opposite condition from bef
lipalani1 2011/04/13 00:07:29 What we want to check is if wait interval pointer
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));
557 wait_interval_.reset(new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, 620 wait_interval_.reset(new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF,
558 length)); 621 length));
559 SyncSessionJob job = {NUDGE, TimeTicks::Now() + length, 622 if (old_job.purpose == SyncSessionJob::CONFIGURATION) {
560 make_linked_ptr(s), FROM_HERE}; 623 SyncSessionJob job(old_job.purpose, TimeTicks::Now() + length,
561 pending_nudge_.reset(new SyncSessionJob(job)); 624 make_linked_ptr(s), false, FROM_HERE);
625 wait_interval_->pending_configure_job.reset(new SyncSessionJob(job));
626 } else {
627 // We are not in configuration mode. So wait_interval's pending job
628 // should be null.
629 DCHECK(wait_interval_->pending_configure_job.get() == NULL);
630
631 // No matter what type of job it is.(nudge or poll, it cannot be config)
632 // We are going to treat it as nudge when doing exponential back off
633 // retries.
634 // TODO(lipalani) - handle clear user data.
635 UpdatePendingJob(old_job);
636 }
562 wait_interval_->timer.Start(length, this, &SyncerThread::DoCanaryJob); 637 wait_interval_->timer.Start(length, this, &SyncerThread::DoCanaryJob);
563 } 638 }
564 639
565 // static 640 // static
566 TimeDelta SyncerThread::GetRecommendedDelay(const TimeDelta& last_delay) { 641 TimeDelta SyncerThread::GetRecommendedDelay(const TimeDelta& last_delay) {
567 if (last_delay.InSeconds() >= kMaxBackoffSeconds) 642 if (last_delay.InSeconds() >= kMaxBackoffSeconds)
568 return TimeDelta::FromSeconds(kMaxBackoffSeconds); 643 return TimeDelta::FromSeconds(kMaxBackoffSeconds);
569 644
570 // This calculates approx. base_delay_seconds * 2 +/- base_delay_seconds / 2 645 // This calculates approx. base_delay_seconds * 2 +/- base_delay_seconds / 2
571 int64 backoff_s = 646 int64 backoff_s =
(...skipping 14 matching lines...) Expand all
586 return TimeDelta::FromSeconds(backoff_s); 661 return TimeDelta::FromSeconds(backoff_s);
587 } 662 }
588 663
589 void SyncerThread::Stop() { 664 void SyncerThread::Stop() {
590 syncer_->RequestEarlyExit(); // Safe to call from any thread. 665 syncer_->RequestEarlyExit(); // Safe to call from any thread.
591 session_context_->connection_manager()->RemoveListener(this); 666 session_context_->connection_manager()->RemoveListener(this);
592 thread_.Stop(); 667 thread_.Stop();
593 } 668 }
594 669
595 void SyncerThread::DoCanaryJob() { 670 void SyncerThread::DoCanaryJob() {
596 DCHECK(pending_nudge_.get()); 671 // We should not be here unless wait interval was initialized due to
672 // throttling or backing off.
673 DCHECK(wait_interval_.get());
674
597 wait_interval_->had_nudge = false; 675 wait_interval_->had_nudge = false;
598 SyncSessionJob copy = *pending_nudge_; 676
599 DoSyncSessionJob(copy); 677 // We should have one of 2 things. Otherwise we shouldnt be running the timer.
678 DCHECK(wait_interval_->pending_configure_job.get() || pending_nudge_.get());
679 DoPendingJobIfPossible();
680 }
681
682 void SyncerThread::DoPendingJobIfPossible() {
683 SyncSessionJob* job_to_execute = NULL;
684 if (mode_ == CONFIGURATION_MODE) {
685 if (wait_interval_.get() && wait_interval_->pending_configure_job.get()) {
tim (not reviewing) 2011/04/12 06:09:29 combine this with the above if statement... less n
lipalani1 2011/04/13 00:07:29 Done.
686 job_to_execute = wait_interval_->pending_configure_job.get();
687 }
688 } else {
689 if (pending_nudge_.get()) {
tim (not reviewing) 2011/04/12 06:09:29 move this into 'else if' above.
lipalani1 2011/04/13 00:07:29 Done.
690 // Pending jobs mostly have time from the past. Reset it so this job
691 // will get executed.
692 if (pending_nudge_->scheduled_start < TimeTicks::Now())
693 pending_nudge_->scheduled_start = TimeTicks::Now();
694
695 scoped_ptr<SyncSession> session(CreateSyncSession(
696 pending_nudge_->session->source()));
697
698 // Also the routing info might have been changed since we cached the
699 // pending nudge. Update it by coalescing to the latest.
700 pending_nudge_->session->Coalesce(*(session.get()));
701 // The pending nudge would be cleared in the DoSyncSessionJob function.
702 job_to_execute = pending_nudge_.get();
703 }
704 }
705
706 if (job_to_execute != NULL) {
707 SyncSessionJob copy = *job_to_execute;
708 copy.is_canary_job = true;
709 DoSyncSessionJob(copy);
710 }
711 }
712
713 SyncSession* SyncerThread::CreateSyncSession(const SyncSourceInfo& source) {
tim (not reviewing) 2011/04/12 06:09:29 I think this could be used in 4 (?) more places if
lipalani1 2011/04/13 00:07:29 I have added one more place(polltimer) where this
714 ModelSafeRoutingInfo routes;
715 std::vector<ModelSafeWorker*> workers;
716 session_context_->registrar()->GetModelSafeRoutingInfo(&routes);
717 session_context_->registrar()->GetWorkers(&workers);
718 SyncSourceInfo info(source);
719
720 SyncSession* session(new SyncSession(session_context_.get(), this, info,
721 routes, workers));
722
723 return session;
600 } 724 }
601 725
602 void SyncerThread::PollTimerCallback() { 726 void SyncerThread::PollTimerCallback() {
603 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 727 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
604 ModelSafeRoutingInfo r; 728 ModelSafeRoutingInfo r;
605 std::vector<ModelSafeWorker*> w; 729 std::vector<ModelSafeWorker*> w;
606 session_context_->registrar()->GetModelSafeRoutingInfo(&r); 730 session_context_->registrar()->GetModelSafeRoutingInfo(&r);
607 session_context_->registrar()->GetWorkers(&w); 731 session_context_->registrar()->GetWorkers(&w);
608 ModelTypePayloadMap types_with_payloads = 732 ModelTypePayloadMap types_with_payloads =
609 syncable::ModelTypePayloadMapFromRoutingInfo(r, std::string()); 733 syncable::ModelTypePayloadMapFromRoutingInfo(r, std::string());
610 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, types_with_payloads); 734 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, types_with_payloads);
611 SyncSession* s = new SyncSession(session_context_.get(), this, info, r, w); 735 SyncSession* s = new SyncSession(session_context_.get(), this, info, r, w);
tim (not reviewing) 2011/04/12 06:09:29 can this use CreateSyncSession?
lipalani1 2011/04/13 00:07:29 Done.
612 ScheduleSyncSessionJob(TimeDelta::FromSeconds(0), POLL, s, FROM_HERE); 736 ScheduleSyncSessionJob(TimeDelta::FromSeconds(0), SyncSessionJob::POLL, s,
737 FROM_HERE);
613 } 738 }
614 739
615 void SyncerThread::Unthrottle() { 740 void SyncerThread::Unthrottle() {
616 DCHECK_EQ(WaitInterval::THROTTLED, wait_interval_->mode); 741 DCHECK_EQ(WaitInterval::THROTTLED, wait_interval_->mode);
742 DoCanaryJob();
617 wait_interval_.reset(); 743 wait_interval_.reset();
618 } 744 }
619 745
620 void SyncerThread::Notify(SyncEngineEvent::EventCause cause) { 746 void SyncerThread::Notify(SyncEngineEvent::EventCause cause) {
621 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 747 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
622 session_context_->NotifyListeners(SyncEngineEvent(cause)); 748 session_context_->NotifyListeners(SyncEngineEvent(cause));
623 } 749 }
624 750
625 bool SyncerThread::IsBackingOff() const { 751 bool SyncerThread::IsBackingOff() const {
626 return wait_interval_.get() && wait_interval_->mode == 752 return wait_interval_.get() && wait_interval_->mode ==
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 &SyncerThread::CheckServerConnectionManagerStatus, 788 &SyncerThread::CheckServerConnectionManagerStatus,
663 event.connection_code)); 789 event.connection_code));
664 } 790 }
665 791
666 void SyncerThread::set_notifications_enabled(bool notifications_enabled) { 792 void SyncerThread::set_notifications_enabled(bool notifications_enabled) {
667 session_context_->set_notifications_enabled(notifications_enabled); 793 session_context_->set_notifications_enabled(notifications_enabled);
668 } 794 }
669 795
670 } // s3 796 } // s3
671 } // browser_sync 797 } // browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698