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 "sync/engine/sync_scheduler.h" | 5 #include "sync/engine/sync_scheduler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 return false; | 61 return false; |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 bool IsActionableError( | 65 bool IsActionableError( |
66 const browser_sync::SyncProtocolError& error) { | 66 const browser_sync::SyncProtocolError& error) { |
67 return (error.action != browser_sync::UNKNOWN_ACTION); | 67 return (error.action != browser_sync::UNKNOWN_ACTION); |
68 } | 68 } |
69 } // namespace | 69 } // namespace |
70 | 70 |
71 ConfigurationParams::ConfigurationParams() | |
72 : source(GetUpdatesCallerInfo::UNKNOWN), | |
73 keystore_key_status(KEYSTORE_KEY_UNNECESSARY) {} | |
74 ConfigurationParams::ConfigurationParams( | |
75 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& source, | |
76 const syncable::ModelTypeSet& types_to_download, | |
77 const browser_sync::ModelSafeRoutingInfo& routing_info, | |
78 KeystoreKeyStatus keystore_key_status, | |
79 const base::Closure& ready_task) | |
80 : source(source), | |
81 types_to_download(types_to_download), | |
82 routing_info(routing_info), | |
83 keystore_key_status(keystore_key_status), | |
84 ready_task(ready_task) { | |
85 DCHECK(!ready_task.is_null()); | |
86 } | |
87 ConfigurationParams::~ConfigurationParams() {} | |
88 | |
71 SyncScheduler::DelayProvider::DelayProvider() {} | 89 SyncScheduler::DelayProvider::DelayProvider() {} |
72 SyncScheduler::DelayProvider::~DelayProvider() {} | 90 SyncScheduler::DelayProvider::~DelayProvider() {} |
73 | 91 |
74 SyncScheduler::WaitInterval::WaitInterval() | 92 SyncScheduler::WaitInterval::WaitInterval() |
75 : mode(UNKNOWN), | 93 : mode(UNKNOWN), |
76 had_nudge(false) { | 94 had_nudge(false) { |
77 } | 95 } |
78 | 96 |
79 SyncScheduler::WaitInterval::~WaitInterval() {} | 97 SyncScheduler::WaitInterval::~WaitInterval() {} |
80 | 98 |
(...skipping 11 matching lines...) Expand all Loading... | |
92 | 110 |
93 SyncScheduler::SyncSessionJob::SyncSessionJob() | 111 SyncScheduler::SyncSessionJob::SyncSessionJob() |
94 : purpose(UNKNOWN), | 112 : purpose(UNKNOWN), |
95 is_canary_job(false) { | 113 is_canary_job(false) { |
96 } | 114 } |
97 | 115 |
98 SyncScheduler::SyncSessionJob::~SyncSessionJob() {} | 116 SyncScheduler::SyncSessionJob::~SyncSessionJob() {} |
99 | 117 |
100 SyncScheduler::SyncSessionJob::SyncSessionJob(SyncSessionJobPurpose purpose, | 118 SyncScheduler::SyncSessionJob::SyncSessionJob(SyncSessionJobPurpose purpose, |
101 base::TimeTicks start, | 119 base::TimeTicks start, |
102 linked_ptr<sessions::SyncSession> session, bool is_canary_job, | 120 linked_ptr<sessions::SyncSession> session, |
103 const tracked_objects::Location& from_here) : purpose(purpose), | 121 bool is_canary_job, |
104 scheduled_start(start), | 122 ConfigurationParams config_params, |
105 session(session), | 123 const tracked_objects::Location& from_here) |
106 is_canary_job(is_canary_job), | 124 : purpose(purpose), |
107 from_here(from_here) { | 125 scheduled_start(start), |
126 session(session), | |
127 is_canary_job(is_canary_job), | |
128 config_params(config_params), | |
129 from_here(from_here) { | |
108 } | 130 } |
109 | 131 |
110 const char* SyncScheduler::SyncSessionJob::GetPurposeString( | 132 const char* SyncScheduler::SyncSessionJob::GetPurposeString( |
111 SyncScheduler::SyncSessionJob::SyncSessionJobPurpose purpose) { | 133 SyncScheduler::SyncSessionJob::SyncSessionJobPurpose purpose) { |
112 switch (purpose) { | 134 switch (purpose) { |
113 ENUM_CASE(UNKNOWN); | 135 ENUM_CASE(UNKNOWN); |
114 ENUM_CASE(POLL); | 136 ENUM_CASE(POLL); |
115 ENUM_CASE(NUDGE); | 137 ENUM_CASE(NUDGE); |
116 ENUM_CASE(CLEAR_USER_DATA); | 138 ENUM_CASE(CLEAR_USER_DATA); |
117 ENUM_CASE(CONFIGURATION); | 139 ENUM_CASE(CONFIGURATION); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 | 262 |
241 void SyncScheduler::UpdateServerConnectionManagerStatus( | 263 void SyncScheduler::UpdateServerConnectionManagerStatus( |
242 HttpResponse::ServerConnectionCode code) { | 264 HttpResponse::ServerConnectionCode code) { |
243 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 265 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
244 SDVLOG(2) << "New server connection code: " | 266 SDVLOG(2) << "New server connection code: " |
245 << HttpResponse::GetServerConnectionCodeString(code); | 267 << HttpResponse::GetServerConnectionCodeString(code); |
246 | 268 |
247 connection_code_ = code; | 269 connection_code_ = code; |
248 } | 270 } |
249 | 271 |
250 void SyncScheduler::Start(Mode mode, const base::Closure& callback) { | 272 void SyncScheduler::Start(Mode mode) { |
251 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 273 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
252 std::string thread_name = MessageLoop::current()->thread_name(); | 274 std::string thread_name = MessageLoop::current()->thread_name(); |
253 if (thread_name.empty()) | 275 if (thread_name.empty()) |
254 thread_name = "<Main thread>"; | 276 thread_name = "<Main thread>"; |
255 SDVLOG(2) << "Start called from thread " | 277 SDVLOG(2) << "Start called from thread " |
256 << thread_name << " with mode " << GetModeString(mode); | 278 << thread_name << " with mode " << GetModeString(mode); |
257 if (!started_) { | 279 if (!started_) { |
258 started_ = true; | 280 started_ = true; |
259 SendInitialSnapshot(); | 281 SendInitialSnapshot(); |
260 } | 282 } |
261 | 283 |
262 DCHECK(!session_context_->account_name().empty()); | 284 DCHECK(!session_context_->account_name().empty()); |
263 DCHECK(syncer_.get()); | 285 DCHECK(syncer_.get()); |
264 Mode old_mode = mode_; | 286 Mode old_mode = mode_; |
265 mode_ = mode; | 287 mode_ = mode; |
266 AdjustPolling(NULL); // Will kick start poll timer if needed. | 288 AdjustPolling(NULL); // Will kick start poll timer if needed. |
267 if (!callback.is_null()) | |
268 callback.Run(); | |
269 | 289 |
270 if (old_mode != mode_) { | 290 if (old_mode != mode_) { |
271 // We just changed our mode. See if there are any pending jobs that we could | 291 // We just changed our mode. See if there are any pending jobs that we could |
272 // execute in the new mode. | 292 // execute in the new mode. |
273 DoPendingJobIfPossible(false); | 293 DoPendingJobIfPossible(false); |
274 } | 294 } |
275 } | 295 } |
276 | 296 |
277 void SyncScheduler::SendInitialSnapshot() { | 297 void SyncScheduler::SendInitialSnapshot() { |
278 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 298 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
279 scoped_ptr<SyncSession> dummy(new SyncSession(session_context_, this, | 299 scoped_ptr<SyncSession> dummy(new SyncSession(session_context_, this, |
280 SyncSourceInfo(), ModelSafeRoutingInfo(), | 300 SyncSourceInfo(), ModelSafeRoutingInfo(), |
281 std::vector<ModelSafeWorker*>())); | 301 std::vector<ModelSafeWorker*>())); |
282 SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED); | 302 SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED); |
283 event.snapshot = dummy->TakeSnapshot(); | 303 event.snapshot = dummy->TakeSnapshot(); |
284 session_context_->NotifyListeners(event); | 304 session_context_->NotifyListeners(event); |
285 } | 305 } |
286 | 306 |
307 namespace { | |
308 | |
309 // Helper to extract the routing info and workers corresponding to types in | |
310 // |types| from |current_routes| and |current_workers|. | |
311 void BuildModelSafeParams( | |
312 const ModelTypeSet& types_to_download, | |
313 const ModelSafeRoutingInfo& current_routes, | |
314 const std::vector<ModelSafeWorker*>& current_workers, | |
315 ModelSafeRoutingInfo* result_routes, | |
316 std::vector<ModelSafeWorker*>* result_workers) { | |
317 std::set<ModelSafeGroup> active_groups; | |
318 active_groups.insert(GROUP_PASSIVE); | |
319 for (ModelTypeSet::Iterator iter = types_to_download.First(); iter.Good(); | |
320 iter.Inc()) { | |
321 syncable::ModelType type = iter.Get(); | |
322 ModelSafeRoutingInfo::const_iterator route = current_routes.find(type); | |
323 DCHECK(route != current_routes.end()); | |
324 ModelSafeGroup group = route->second; | |
325 (*result_routes)[type] = group; | |
326 active_groups.insert(group); | |
327 } | |
328 | |
329 for(std::vector<ModelSafeWorker*>::const_iterator iter = | |
330 current_workers.begin(); iter != current_workers.end(); ++iter) { | |
331 if (active_groups.count((*iter)->GetModelSafeGroup()) > 0) | |
332 result_workers->push_back(*iter); | |
333 } | |
334 } | |
335 | |
336 } // namespace. | |
337 | |
338 bool SyncScheduler::ScheduleConfiguration(const ConfigurationParams& params) { | |
339 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
340 DCHECK(IsConfigRelatedUpdateSourceValue(params.source)); | |
341 DCHECK_EQ(CONFIGURATION_MODE, mode_); | |
342 DCHECK(!params.ready_task.is_null()); | |
343 SDVLOG(2) << "Reconfiguring syncer."; | |
344 | |
345 // Only one configuration is allowed at a time. Verify we're not waiting | |
346 // for a pending configure job. | |
347 DCHECK(!wait_interval_.get() || !wait_interval_->pending_configure_job.get()); | |
348 | |
349 // TODO(sync): now that ModelChanging commands only use those workers within | |
350 // the routing info, we don't really need |restricted_workers|. Remove it. | |
tim (not reviewing)
2012/06/15 14:59:37
Bug would be nice here too!
Nicolas Zea
2012/06/15 21:23:36
Done.
| |
351 browser_sync::ModelSafeRoutingInfo restricted_routes; | |
352 std::vector<ModelSafeWorker*> restricted_workers; | |
353 BuildModelSafeParams(params.types_to_download, | |
354 params.routing_info, | |
355 session_context_->workers(), | |
356 &restricted_routes, | |
357 &restricted_workers); | |
358 session_context_->set_routing_info(params.routing_info); | |
359 | |
360 // We rely on this not failing, so don't need to worry about checking for | |
361 // success. In addition, this will be removed as part of crbug.com/131433. | |
362 SyncSessionJob cleanup_job( | |
363 SyncSessionJob::CLEANUP_DISABLED_TYPES, | |
364 TimeTicks::Now(), | |
365 make_linked_ptr(CreateSyncSession(SyncSourceInfo())), | |
366 false, | |
367 ConfigurationParams(), | |
368 FROM_HERE); | |
369 DoSyncSessionJob(cleanup_job); | |
370 | |
371 if (params.keystore_key_status == ConfigurationParams::KEYSTORE_KEY_NEEDED) { | |
372 // TODO(zea): implement in such a way that we can handle failures and the | |
373 // subsequent retrys the scheduler might perform. See crbug.com/129665. | |
374 NOTIMPLEMENTED(); | |
375 } | |
376 | |
377 // Only reconfigure if we have types to config. | |
tim (not reviewing)
2012/06/15 14:59:37
s/config/download
Nicolas Zea
2012/06/15 21:23:36
Done.
| |
378 if (!params.types_to_download.Empty()) { | |
379 DCHECK(!restricted_routes.empty()); | |
380 linked_ptr<SyncSession> session(new SyncSession( | |
381 session_context_, | |
382 this, | |
383 SyncSourceInfo(params.source, | |
384 syncable::ModelTypePayloadMapFromRoutingInfo( | |
385 restricted_routes, | |
386 std::string())), | |
387 restricted_routes, | |
388 restricted_workers)); | |
389 SyncSessionJob job(SyncSessionJob::CONFIGURATION, | |
390 TimeTicks::Now(), | |
391 session, | |
392 false, | |
393 params, | |
394 FROM_HERE); | |
395 DoSyncSessionJob(job); | |
396 | |
397 // If we failed, the job would have been saved as the pending configure | |
398 // job and a wait interval would have been set. | |
399 if (!session->Succeeded()) { | |
400 DCHECK(wait_interval_.get() && | |
401 wait_interval_->pending_configure_job.get()); | |
402 return false; | |
403 } | |
404 } else { | |
405 SDVLOG(2) << "No change in routing info, calling ready task directly."; | |
406 params.ready_task.Run(); | |
407 } | |
408 | |
409 return true; | |
410 } | |
411 | |
287 SyncScheduler::JobProcessDecision SyncScheduler::DecideWhileInWaitInterval( | 412 SyncScheduler::JobProcessDecision SyncScheduler::DecideWhileInWaitInterval( |
288 const SyncSessionJob& job) { | 413 const SyncSessionJob& job) { |
289 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 414 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
290 DCHECK(wait_interval_.get()); | 415 DCHECK(wait_interval_.get()); |
291 DCHECK_NE(job.purpose, SyncSessionJob::CLEAR_USER_DATA); | 416 DCHECK_NE(job.purpose, SyncSessionJob::CLEAR_USER_DATA); |
292 DCHECK_NE(job.purpose, SyncSessionJob::CLEANUP_DISABLED_TYPES); | 417 DCHECK_NE(job.purpose, SyncSessionJob::CLEANUP_DISABLED_TYPES); |
293 | 418 |
294 SDVLOG(2) << "DecideWhileInWaitInterval with WaitInterval mode " | 419 SDVLOG(2) << "DecideWhileInWaitInterval with WaitInterval mode " |
295 << WaitInterval::GetModeString(wait_interval_->mode) | 420 << WaitInterval::GetModeString(wait_interval_->mode) |
296 << (wait_interval_->had_nudge ? " (had nudge)" : "") | 421 << (wait_interval_->had_nudge ? " (had nudge)" : "") |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 void SyncScheduler::InitOrCoalescePendingJob(const SyncSessionJob& job) { | 500 void SyncScheduler::InitOrCoalescePendingJob(const SyncSessionJob& job) { |
376 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 501 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
377 DCHECK(job.purpose != SyncSessionJob::CONFIGURATION); | 502 DCHECK(job.purpose != SyncSessionJob::CONFIGURATION); |
378 if (pending_nudge_.get() == NULL) { | 503 if (pending_nudge_.get() == NULL) { |
379 SDVLOG(2) << "Creating a pending nudge job"; | 504 SDVLOG(2) << "Creating a pending nudge job"; |
380 SyncSession* s = job.session.get(); | 505 SyncSession* s = job.session.get(); |
381 scoped_ptr<SyncSession> session(new SyncSession(s->context(), | 506 scoped_ptr<SyncSession> session(new SyncSession(s->context(), |
382 s->delegate(), s->source(), s->routing_info(), s->workers())); | 507 s->delegate(), s->source(), s->routing_info(), s->workers())); |
383 | 508 |
384 SyncSessionJob new_job(SyncSessionJob::NUDGE, job.scheduled_start, | 509 SyncSessionJob new_job(SyncSessionJob::NUDGE, job.scheduled_start, |
385 make_linked_ptr(session.release()), false, job.from_here); | 510 make_linked_ptr(session.release()), false, |
511 ConfigurationParams(), job.from_here); | |
386 pending_nudge_.reset(new SyncSessionJob(new_job)); | 512 pending_nudge_.reset(new SyncSessionJob(new_job)); |
387 | 513 |
388 return; | 514 return; |
389 } | 515 } |
390 | 516 |
391 SDVLOG(2) << "Coalescing a pending nudge"; | 517 SDVLOG(2) << "Coalescing a pending nudge"; |
392 pending_nudge_->session->Coalesce(*(job.session.get())); | 518 pending_nudge_->session->Coalesce(*(job.session.get())); |
393 pending_nudge_->scheduled_start = job.scheduled_start; | 519 pending_nudge_->scheduled_start = job.scheduled_start; |
394 | 520 |
395 // Unfortunately the nudge location cannot be modified. So it stores the | 521 // Unfortunately the nudge location cannot be modified. So it stores the |
(...skipping 25 matching lines...) Expand all Loading... | |
421 // TODO(sync): Should we also check that job.purpose != | 547 // TODO(sync): Should we also check that job.purpose != |
422 // CLEANUP_DISABLED_TYPES? (See http://crbug.com/90868.) | 548 // CLEANUP_DISABLED_TYPES? (See http://crbug.com/90868.) |
423 if (job.purpose == SyncSessionJob::NUDGE) { | 549 if (job.purpose == SyncSessionJob::NUDGE) { |
424 SDVLOG(2) << "Saving a nudge job"; | 550 SDVLOG(2) << "Saving a nudge job"; |
425 InitOrCoalescePendingJob(job); | 551 InitOrCoalescePendingJob(job); |
426 } else if (job.purpose == SyncSessionJob::CONFIGURATION){ | 552 } else if (job.purpose == SyncSessionJob::CONFIGURATION){ |
427 SDVLOG(2) << "Saving a configuration job"; | 553 SDVLOG(2) << "Saving a configuration job"; |
428 DCHECK(wait_interval_.get()); | 554 DCHECK(wait_interval_.get()); |
429 DCHECK(mode_ == CONFIGURATION_MODE); | 555 DCHECK(mode_ == CONFIGURATION_MODE); |
430 | 556 |
557 // Config params should always get set. | |
558 DCHECK(!job.config_params.ready_task.is_null()); | |
431 SyncSession* old = job.session.get(); | 559 SyncSession* old = job.session.get(); |
432 SyncSession* s(new SyncSession(session_context_, this, old->source(), | 560 SyncSession* s(new SyncSession(session_context_, this, old->source(), |
433 old->routing_info(), old->workers())); | 561 old->routing_info(), old->workers())); |
434 SyncSessionJob new_job(job.purpose, TimeTicks::Now(), | 562 SyncSessionJob new_job(job.purpose, |
435 make_linked_ptr(s), false, job.from_here); | 563 TimeTicks::Now(), |
564 make_linked_ptr(s), | |
565 false, | |
566 job.config_params, | |
567 job.from_here); | |
436 wait_interval_->pending_configure_job.reset(new SyncSessionJob(new_job)); | 568 wait_interval_->pending_configure_job.reset(new SyncSessionJob(new_job)); |
437 } // drop the rest. | 569 } // drop the rest. |
438 // TODO(sync): Is it okay to drop the rest? It's weird that | 570 // TODO(sync): Is it okay to drop the rest? It's weird that |
439 // SaveJob() only does what it says sometimes. (See | 571 // SaveJob() only does what it says sometimes. (See |
440 // http://crbug.com/90868.) | 572 // http://crbug.com/90868.) |
441 } | 573 } |
442 | 574 |
443 // Functor for std::find_if to search by ModelSafeGroup. | 575 // Functor for std::find_if to search by ModelSafeGroup. |
444 struct ModelSafeWorkerGroupIs { | 576 struct ModelSafeWorkerGroupIs { |
445 explicit ModelSafeWorkerGroupIs(ModelSafeGroup group) : group(group) {} | 577 explicit ModelSafeWorkerGroupIs(ModelSafeGroup group) : group(group) {} |
446 bool operator()(ModelSafeWorker* w) { | 578 bool operator()(ModelSafeWorker* w) { |
447 return group == w->GetModelSafeGroup(); | 579 return group == w->GetModelSafeGroup(); |
448 } | 580 } |
449 ModelSafeGroup group; | 581 ModelSafeGroup group; |
450 }; | 582 }; |
451 | 583 |
452 void SyncScheduler::ClearUserData() { | 584 void SyncScheduler::ClearUserData() { |
453 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 585 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
454 SyncSessionJob job(SyncSessionJob::CLEAR_USER_DATA, TimeTicks::Now(), | 586 SyncSessionJob job(SyncSessionJob::CLEAR_USER_DATA, |
587 TimeTicks::Now(), | |
455 make_linked_ptr(CreateSyncSession(SyncSourceInfo())), | 588 make_linked_ptr(CreateSyncSession(SyncSourceInfo())), |
456 false, | 589 false, |
590 ConfigurationParams(), | |
457 FROM_HERE); | 591 FROM_HERE); |
458 | 592 |
459 DoSyncSessionJob(job); | 593 DoSyncSessionJob(job); |
460 } | 594 } |
461 | 595 |
462 void SyncScheduler::CleanupDisabledTypes() { | |
463 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
464 SyncSessionJob job(SyncSessionJob::CLEANUP_DISABLED_TYPES, TimeTicks::Now(), | |
465 make_linked_ptr(CreateSyncSession(SyncSourceInfo())), | |
466 false, | |
467 FROM_HERE); | |
468 DoSyncSessionJob(job); | |
469 } | |
470 | |
471 void SyncScheduler::ScheduleNudgeAsync( | 596 void SyncScheduler::ScheduleNudgeAsync( |
472 const TimeDelta& delay, | 597 const TimeDelta& delay, |
473 NudgeSource source, ModelTypeSet types, | 598 NudgeSource source, ModelTypeSet types, |
474 const tracked_objects::Location& nudge_location) { | 599 const tracked_objects::Location& nudge_location) { |
475 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 600 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
476 SDVLOG_LOC(nudge_location, 2) | 601 SDVLOG_LOC(nudge_location, 2) |
477 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " | 602 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " |
478 << "source " << GetNudgeSourceString(source) << ", " | 603 << "source " << GetNudgeSourceString(source) << ", " |
479 << "types " << ModelTypeSetToString(types); | 604 << "types " << ModelTypeSetToString(types); |
480 | 605 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 << "source " << GetUpdatesSourceString(source) << ", " | 643 << "source " << GetUpdatesSourceString(source) << ", " |
519 << "payloads " | 644 << "payloads " |
520 << syncable::ModelTypePayloadMapToString(types_with_payloads) | 645 << syncable::ModelTypePayloadMapToString(types_with_payloads) |
521 << (is_canary_job ? " (canary)" : ""); | 646 << (is_canary_job ? " (canary)" : ""); |
522 | 647 |
523 SyncSourceInfo info(source, types_with_payloads); | 648 SyncSourceInfo info(source, types_with_payloads); |
524 | 649 |
525 SyncSession* session(CreateSyncSession(info)); | 650 SyncSession* session(CreateSyncSession(info)); |
526 SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now() + delay, | 651 SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now() + delay, |
527 make_linked_ptr(session), is_canary_job, | 652 make_linked_ptr(session), is_canary_job, |
528 nudge_location); | 653 ConfigurationParams(), nudge_location); |
529 | 654 |
530 session = NULL; | 655 session = NULL; |
531 if (!ShouldRunJob(job)) | 656 if (!ShouldRunJob(job)) |
532 return; | 657 return; |
533 | 658 |
534 if (pending_nudge_.get()) { | 659 if (pending_nudge_.get()) { |
535 if (IsBackingOff() && delay > TimeDelta::FromSeconds(1)) { | 660 if (IsBackingOff() && delay > TimeDelta::FromSeconds(1)) { |
536 SDVLOG(2) << "Dropping the nudge because we are in backoff"; | 661 SDVLOG(2) << "Dropping the nudge because we are in backoff"; |
537 return; | 662 return; |
538 } | 663 } |
(...skipping 10 matching lines...) Expand all Loading... | |
549 job.scheduled_start = std::min(job.scheduled_start, | 674 job.scheduled_start = std::min(job.scheduled_start, |
550 pending_nudge_->scheduled_start); | 675 pending_nudge_->scheduled_start); |
551 pending_nudge_.reset(); | 676 pending_nudge_.reset(); |
552 } | 677 } |
553 | 678 |
554 // TODO(zea): Consider adding separate throttling/backoff for datatype | 679 // TODO(zea): Consider adding separate throttling/backoff for datatype |
555 // refresh requests. | 680 // refresh requests. |
556 ScheduleSyncSessionJob(job); | 681 ScheduleSyncSessionJob(job); |
557 } | 682 } |
558 | 683 |
559 // Helper to extract the routing info and workers corresponding to types in | |
560 // |types| from |current_routes| and |current_workers|. | |
561 void GetModelSafeParamsForTypes(ModelTypeSet types, | |
562 const ModelSafeRoutingInfo& current_routes, | |
563 const std::vector<ModelSafeWorker*>& current_workers, | |
564 ModelSafeRoutingInfo* result_routes, | |
565 std::vector<ModelSafeWorker*>* result_workers) { | |
566 bool passive_group_added = false; | |
567 | |
568 typedef std::vector<ModelSafeWorker*>::const_iterator iter; | |
569 for (ModelTypeSet::Iterator it = types.First(); | |
570 it.Good(); it.Inc()) { | |
571 const syncable::ModelType t = it.Get(); | |
572 ModelSafeRoutingInfo::const_iterator route = current_routes.find(t); | |
573 DCHECK(route != current_routes.end()); | |
574 ModelSafeGroup group = route->second; | |
575 | |
576 (*result_routes)[t] = group; | |
577 iter w_tmp_it = std::find_if(current_workers.begin(), current_workers.end(), | |
578 ModelSafeWorkerGroupIs(group)); | |
579 if (w_tmp_it != current_workers.end()) { | |
580 iter result_workers_it = std::find_if( | |
581 result_workers->begin(), result_workers->end(), | |
582 ModelSafeWorkerGroupIs(group)); | |
583 if (result_workers_it == result_workers->end()) | |
584 result_workers->push_back(*w_tmp_it); | |
585 | |
586 if (group == GROUP_PASSIVE) | |
587 passive_group_added = true; | |
588 } else { | |
589 NOTREACHED(); | |
590 } | |
591 } | |
592 | |
593 // Always add group passive. | |
594 if (passive_group_added == false) { | |
595 iter it = std::find_if(current_workers.begin(), current_workers.end(), | |
596 ModelSafeWorkerGroupIs(GROUP_PASSIVE)); | |
597 if (it != current_workers.end()) | |
598 result_workers->push_back(*it); | |
599 else | |
600 NOTREACHED(); | |
601 } | |
602 } | |
603 | |
604 void SyncScheduler::ScheduleConfiguration( | |
605 ModelTypeSet types, | |
606 GetUpdatesCallerInfo::GetUpdatesSource source) { | |
607 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
608 DCHECK(IsConfigRelatedUpdateSourceValue(source)); | |
609 SDVLOG(2) << "Scheduling a config"; | |
610 | |
611 ModelSafeRoutingInfo routes; | |
612 std::vector<ModelSafeWorker*> workers; | |
613 GetModelSafeParamsForTypes(types, | |
614 session_context_->routing_info(), | |
615 session_context_->workers(), | |
616 &routes, &workers); | |
617 | |
618 SyncSession* session = new SyncSession(session_context_, this, | |
619 SyncSourceInfo(source, | |
620 syncable::ModelTypePayloadMapFromRoutingInfo( | |
621 routes, std::string())), | |
622 routes, workers); | |
623 SyncSessionJob job(SyncSessionJob::CONFIGURATION, TimeTicks::Now(), | |
624 make_linked_ptr(session), | |
625 false, | |
626 FROM_HERE); | |
627 DoSyncSessionJob(job); | |
628 } | |
629 | |
630 const char* SyncScheduler::GetModeString(SyncScheduler::Mode mode) { | 684 const char* SyncScheduler::GetModeString(SyncScheduler::Mode mode) { |
631 switch (mode) { | 685 switch (mode) { |
632 ENUM_CASE(CONFIGURATION_MODE); | 686 ENUM_CASE(CONFIGURATION_MODE); |
633 ENUM_CASE(NORMAL_MODE); | 687 ENUM_CASE(NORMAL_MODE); |
634 } | 688 } |
635 return ""; | 689 return ""; |
636 } | 690 } |
637 | 691 |
638 const char* SyncScheduler::GetDecisionString( | 692 const char* SyncScheduler::GetDecisionString( |
639 SyncScheduler::JobProcessDecision mode) { | 693 SyncScheduler::JobProcessDecision mode) { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
822 ServerConnectionManager* scm = session_context_->connection_manager(); | 876 ServerConnectionManager* scm = session_context_->connection_manager(); |
823 UpdateServerConnectionManagerStatus(scm->server_status()); | 877 UpdateServerConnectionManagerStatus(scm->server_status()); |
824 | 878 |
825 UpdateCarryoverSessionState(job); | 879 UpdateCarryoverSessionState(job); |
826 if (IsSyncingCurrentlySilenced()) { | 880 if (IsSyncingCurrentlySilenced()) { |
827 SDVLOG(2) << "We are currently throttled; not scheduling the next sync."; | 881 SDVLOG(2) << "We are currently throttled; not scheduling the next sync."; |
828 // TODO(sync): Investigate whether we need to check job.purpose | 882 // TODO(sync): Investigate whether we need to check job.purpose |
829 // here; see DCHECKs in SaveJob(). (See http://crbug.com/90868.) | 883 // here; see DCHECKs in SaveJob(). (See http://crbug.com/90868.) |
830 SaveJob(job); | 884 SaveJob(job); |
831 return; // Nothing to do. | 885 return; // Nothing to do. |
886 } else if (job.session->Succeeded() && | |
887 !job.config_params.ready_task.is_null()) { | |
888 // If this was a configuration job with a ready task, invoke it now that | |
889 // we finished successfully. | |
890 job.config_params.ready_task.Run(); | |
832 } | 891 } |
833 | 892 |
834 SDVLOG(2) << "Updating the next polling time after SyncMain"; | 893 SDVLOG(2) << "Updating the next polling time after SyncMain"; |
835 ScheduleNextSync(job); | 894 ScheduleNextSync(job); |
836 } | 895 } |
837 | 896 |
838 void SyncScheduler::ScheduleNextSync(const SyncSessionJob& old_job) { | 897 void SyncScheduler::ScheduleNextSync(const SyncSessionJob& old_job) { |
839 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 898 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
840 DCHECK(!old_job.session->HasMoreToSync()); | 899 DCHECK(!old_job.session->HasMoreToSync()); |
841 | 900 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
924 | 983 |
925 SDVLOG(2) << "In handle continuation error with " | 984 SDVLOG(2) << "In handle continuation error with " |
926 << SyncSessionJob::GetPurposeString(old_job.purpose) | 985 << SyncSessionJob::GetPurposeString(old_job.purpose) |
927 << " job. The time delta(ms) is " | 986 << " job. The time delta(ms) is " |
928 << length.InMilliseconds(); | 987 << length.InMilliseconds(); |
929 | 988 |
930 // This will reset the had_nudge variable as well. | 989 // This will reset the had_nudge variable as well. |
931 wait_interval_.reset(new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, | 990 wait_interval_.reset(new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, |
932 length)); | 991 length)); |
933 if (old_job.purpose == SyncSessionJob::CONFIGURATION) { | 992 if (old_job.purpose == SyncSessionJob::CONFIGURATION) { |
993 SDVLOG(2) << "Configuration did not succeed, scheduling retry."; | |
994 // Config params should always get set. | |
995 DCHECK(!old_job.config_params.ready_task.is_null()); | |
934 SyncSession* old = old_job.session.get(); | 996 SyncSession* old = old_job.session.get(); |
935 SyncSession* s(new SyncSession(session_context_, this, | 997 SyncSession* s(new SyncSession(session_context_, this, |
936 old->source(), old->routing_info(), old->workers())); | 998 old->source(), old->routing_info(), old->workers())); |
937 SyncSessionJob job(old_job.purpose, TimeTicks::Now() + length, | 999 SyncSessionJob job(old_job.purpose, TimeTicks::Now() + length, |
938 make_linked_ptr(s), false, FROM_HERE); | 1000 make_linked_ptr(s), false, old_job.config_params, |
1001 FROM_HERE); | |
939 wait_interval_->pending_configure_job.reset(new SyncSessionJob(job)); | 1002 wait_interval_->pending_configure_job.reset(new SyncSessionJob(job)); |
940 } else { | 1003 } else { |
941 // We are not in configuration mode. So wait_interval's pending job | 1004 // We are not in configuration mode. So wait_interval's pending job |
942 // should be null. | 1005 // should be null. |
943 DCHECK(wait_interval_->pending_configure_job.get() == NULL); | 1006 DCHECK(wait_interval_->pending_configure_job.get() == NULL); |
944 | 1007 |
945 // TODO(lipalani) - handle clear user data. | 1008 // TODO(lipalani) - handle clear user data. |
946 InitOrCoalescePendingJob(old_job); | 1009 InitOrCoalescePendingJob(old_job); |
947 } | 1010 } |
948 RestartWaiting(); | 1011 RestartWaiting(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1050 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1113 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1051 ModelSafeRoutingInfo r; | 1114 ModelSafeRoutingInfo r; |
1052 ModelTypePayloadMap types_with_payloads = | 1115 ModelTypePayloadMap types_with_payloads = |
1053 syncable::ModelTypePayloadMapFromRoutingInfo(r, std::string()); | 1116 syncable::ModelTypePayloadMapFromRoutingInfo(r, std::string()); |
1054 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, types_with_payloads); | 1117 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, types_with_payloads); |
1055 SyncSession* s = CreateSyncSession(info); | 1118 SyncSession* s = CreateSyncSession(info); |
1056 | 1119 |
1057 SyncSessionJob job(SyncSessionJob::POLL, TimeTicks::Now(), | 1120 SyncSessionJob job(SyncSessionJob::POLL, TimeTicks::Now(), |
1058 make_linked_ptr(s), | 1121 make_linked_ptr(s), |
1059 false, | 1122 false, |
1123 ConfigurationParams(), | |
1060 FROM_HERE); | 1124 FROM_HERE); |
1061 | 1125 |
1062 ScheduleSyncSessionJob(job); | 1126 ScheduleSyncSessionJob(job); |
1063 } | 1127 } |
1064 | 1128 |
1065 void SyncScheduler::Unthrottle() { | 1129 void SyncScheduler::Unthrottle() { |
1066 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1130 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1067 DCHECK_EQ(WaitInterval::THROTTLED, wait_interval_->mode); | 1131 DCHECK_EQ(WaitInterval::THROTTLED, wait_interval_->mode); |
1068 SDVLOG(2) << "Unthrottled."; | 1132 SDVLOG(2) << "Unthrottled."; |
1069 DoCanaryJob(); | 1133 DoCanaryJob(); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1152 | 1216 |
1153 #undef SDVLOG_LOC | 1217 #undef SDVLOG_LOC |
1154 | 1218 |
1155 #undef SDVLOG | 1219 #undef SDVLOG |
1156 | 1220 |
1157 #undef SLOG | 1221 #undef SLOG |
1158 | 1222 |
1159 #undef ENUM_CASE | 1223 #undef ENUM_CASE |
1160 | 1224 |
1161 } // browser_sync | 1225 } // browser_sync |
OLD | NEW |