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. |
| 351 // crbug.com/133030 |
| 352 browser_sync::ModelSafeRoutingInfo restricted_routes; |
| 353 std::vector<ModelSafeWorker*> restricted_workers; |
| 354 BuildModelSafeParams(params.types_to_download, |
| 355 params.routing_info, |
| 356 session_context_->workers(), |
| 357 &restricted_routes, |
| 358 &restricted_workers); |
| 359 session_context_->set_routing_info(params.routing_info); |
| 360 |
| 361 // We rely on this not failing, so don't need to worry about checking for |
| 362 // success. In addition, this will be removed as part of crbug.com/131433. |
| 363 SyncSessionJob cleanup_job( |
| 364 SyncSessionJob::CLEANUP_DISABLED_TYPES, |
| 365 TimeTicks::Now(), |
| 366 make_linked_ptr(CreateSyncSession(SyncSourceInfo())), |
| 367 false, |
| 368 ConfigurationParams(), |
| 369 FROM_HERE); |
| 370 DoSyncSessionJob(cleanup_job); |
| 371 |
| 372 if (params.keystore_key_status == ConfigurationParams::KEYSTORE_KEY_NEEDED) { |
| 373 // TODO(zea): implement in such a way that we can handle failures and the |
| 374 // subsequent retrys the scheduler might perform. See crbug.com/129665. |
| 375 NOTIMPLEMENTED(); |
| 376 } |
| 377 |
| 378 // Only reconfigure if we have types to download. |
| 379 if (!params.types_to_download.Empty()) { |
| 380 DCHECK(!restricted_routes.empty()); |
| 381 linked_ptr<SyncSession> session(new SyncSession( |
| 382 session_context_, |
| 383 this, |
| 384 SyncSourceInfo(params.source, |
| 385 syncable::ModelTypePayloadMapFromRoutingInfo( |
| 386 restricted_routes, |
| 387 std::string())), |
| 388 restricted_routes, |
| 389 restricted_workers)); |
| 390 SyncSessionJob job(SyncSessionJob::CONFIGURATION, |
| 391 TimeTicks::Now(), |
| 392 session, |
| 393 false, |
| 394 params, |
| 395 FROM_HERE); |
| 396 DoSyncSessionJob(job); |
| 397 |
| 398 // If we failed, the job would have been saved as the pending configure |
| 399 // job and a wait interval would have been set. |
| 400 if (!session->Succeeded()) { |
| 401 DCHECK(wait_interval_.get() && |
| 402 wait_interval_->pending_configure_job.get()); |
| 403 return false; |
| 404 } |
| 405 } else { |
| 406 SDVLOG(2) << "No change in routing info, calling ready task directly."; |
| 407 params.ready_task.Run(); |
| 408 } |
| 409 |
| 410 return true; |
| 411 } |
| 412 |
287 SyncScheduler::JobProcessDecision SyncScheduler::DecideWhileInWaitInterval( | 413 SyncScheduler::JobProcessDecision SyncScheduler::DecideWhileInWaitInterval( |
288 const SyncSessionJob& job) { | 414 const SyncSessionJob& job) { |
289 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 415 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
290 DCHECK(wait_interval_.get()); | 416 DCHECK(wait_interval_.get()); |
291 DCHECK_NE(job.purpose, SyncSessionJob::CLEAR_USER_DATA); | 417 DCHECK_NE(job.purpose, SyncSessionJob::CLEAR_USER_DATA); |
292 DCHECK_NE(job.purpose, SyncSessionJob::CLEANUP_DISABLED_TYPES); | 418 DCHECK_NE(job.purpose, SyncSessionJob::CLEANUP_DISABLED_TYPES); |
293 | 419 |
294 SDVLOG(2) << "DecideWhileInWaitInterval with WaitInterval mode " | 420 SDVLOG(2) << "DecideWhileInWaitInterval with WaitInterval mode " |
295 << WaitInterval::GetModeString(wait_interval_->mode) | 421 << WaitInterval::GetModeString(wait_interval_->mode) |
296 << (wait_interval_->had_nudge ? " (had nudge)" : "") | 422 << (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) { | 501 void SyncScheduler::InitOrCoalescePendingJob(const SyncSessionJob& job) { |
376 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 502 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
377 DCHECK(job.purpose != SyncSessionJob::CONFIGURATION); | 503 DCHECK(job.purpose != SyncSessionJob::CONFIGURATION); |
378 if (pending_nudge_.get() == NULL) { | 504 if (pending_nudge_.get() == NULL) { |
379 SDVLOG(2) << "Creating a pending nudge job"; | 505 SDVLOG(2) << "Creating a pending nudge job"; |
380 SyncSession* s = job.session.get(); | 506 SyncSession* s = job.session.get(); |
381 scoped_ptr<SyncSession> session(new SyncSession(s->context(), | 507 scoped_ptr<SyncSession> session(new SyncSession(s->context(), |
382 s->delegate(), s->source(), s->routing_info(), s->workers())); | 508 s->delegate(), s->source(), s->routing_info(), s->workers())); |
383 | 509 |
384 SyncSessionJob new_job(SyncSessionJob::NUDGE, job.scheduled_start, | 510 SyncSessionJob new_job(SyncSessionJob::NUDGE, job.scheduled_start, |
385 make_linked_ptr(session.release()), false, job.from_here); | 511 make_linked_ptr(session.release()), false, |
| 512 ConfigurationParams(), job.from_here); |
386 pending_nudge_.reset(new SyncSessionJob(new_job)); | 513 pending_nudge_.reset(new SyncSessionJob(new_job)); |
387 | 514 |
388 return; | 515 return; |
389 } | 516 } |
390 | 517 |
391 SDVLOG(2) << "Coalescing a pending nudge"; | 518 SDVLOG(2) << "Coalescing a pending nudge"; |
392 pending_nudge_->session->Coalesce(*(job.session.get())); | 519 pending_nudge_->session->Coalesce(*(job.session.get())); |
393 pending_nudge_->scheduled_start = job.scheduled_start; | 520 pending_nudge_->scheduled_start = job.scheduled_start; |
394 | 521 |
395 // Unfortunately the nudge location cannot be modified. So it stores the | 522 // 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 != | 548 // TODO(sync): Should we also check that job.purpose != |
422 // CLEANUP_DISABLED_TYPES? (See http://crbug.com/90868.) | 549 // CLEANUP_DISABLED_TYPES? (See http://crbug.com/90868.) |
423 if (job.purpose == SyncSessionJob::NUDGE) { | 550 if (job.purpose == SyncSessionJob::NUDGE) { |
424 SDVLOG(2) << "Saving a nudge job"; | 551 SDVLOG(2) << "Saving a nudge job"; |
425 InitOrCoalescePendingJob(job); | 552 InitOrCoalescePendingJob(job); |
426 } else if (job.purpose == SyncSessionJob::CONFIGURATION){ | 553 } else if (job.purpose == SyncSessionJob::CONFIGURATION){ |
427 SDVLOG(2) << "Saving a configuration job"; | 554 SDVLOG(2) << "Saving a configuration job"; |
428 DCHECK(wait_interval_.get()); | 555 DCHECK(wait_interval_.get()); |
429 DCHECK(mode_ == CONFIGURATION_MODE); | 556 DCHECK(mode_ == CONFIGURATION_MODE); |
430 | 557 |
| 558 // Config params should always get set. |
| 559 DCHECK(!job.config_params.ready_task.is_null()); |
431 SyncSession* old = job.session.get(); | 560 SyncSession* old = job.session.get(); |
432 SyncSession* s(new SyncSession(session_context_, this, old->source(), | 561 SyncSession* s(new SyncSession(session_context_, this, old->source(), |
433 old->routing_info(), old->workers())); | 562 old->routing_info(), old->workers())); |
434 SyncSessionJob new_job(job.purpose, TimeTicks::Now(), | 563 SyncSessionJob new_job(job.purpose, |
435 make_linked_ptr(s), false, job.from_here); | 564 TimeTicks::Now(), |
| 565 make_linked_ptr(s), |
| 566 false, |
| 567 job.config_params, |
| 568 job.from_here); |
436 wait_interval_->pending_configure_job.reset(new SyncSessionJob(new_job)); | 569 wait_interval_->pending_configure_job.reset(new SyncSessionJob(new_job)); |
437 } // drop the rest. | 570 } // drop the rest. |
438 // TODO(sync): Is it okay to drop the rest? It's weird that | 571 // TODO(sync): Is it okay to drop the rest? It's weird that |
439 // SaveJob() only does what it says sometimes. (See | 572 // SaveJob() only does what it says sometimes. (See |
440 // http://crbug.com/90868.) | 573 // http://crbug.com/90868.) |
441 } | 574 } |
442 | 575 |
443 // Functor for std::find_if to search by ModelSafeGroup. | 576 // Functor for std::find_if to search by ModelSafeGroup. |
444 struct ModelSafeWorkerGroupIs { | 577 struct ModelSafeWorkerGroupIs { |
445 explicit ModelSafeWorkerGroupIs(ModelSafeGroup group) : group(group) {} | 578 explicit ModelSafeWorkerGroupIs(ModelSafeGroup group) : group(group) {} |
446 bool operator()(ModelSafeWorker* w) { | 579 bool operator()(ModelSafeWorker* w) { |
447 return group == w->GetModelSafeGroup(); | 580 return group == w->GetModelSafeGroup(); |
448 } | 581 } |
449 ModelSafeGroup group; | 582 ModelSafeGroup group; |
450 }; | 583 }; |
451 | 584 |
452 void SyncScheduler::ClearUserData() { | 585 void SyncScheduler::ClearUserData() { |
453 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 586 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
454 SyncSessionJob job(SyncSessionJob::CLEAR_USER_DATA, TimeTicks::Now(), | 587 SyncSessionJob job(SyncSessionJob::CLEAR_USER_DATA, |
| 588 TimeTicks::Now(), |
455 make_linked_ptr(CreateSyncSession(SyncSourceInfo())), | 589 make_linked_ptr(CreateSyncSession(SyncSourceInfo())), |
456 false, | 590 false, |
| 591 ConfigurationParams(), |
457 FROM_HERE); | 592 FROM_HERE); |
458 | 593 |
459 DoSyncSessionJob(job); | 594 DoSyncSessionJob(job); |
460 } | 595 } |
461 | 596 |
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( | 597 void SyncScheduler::ScheduleNudgeAsync( |
472 const TimeDelta& delay, | 598 const TimeDelta& delay, |
473 NudgeSource source, ModelTypeSet types, | 599 NudgeSource source, ModelTypeSet types, |
474 const tracked_objects::Location& nudge_location) { | 600 const tracked_objects::Location& nudge_location) { |
475 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 601 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
476 SDVLOG_LOC(nudge_location, 2) | 602 SDVLOG_LOC(nudge_location, 2) |
477 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " | 603 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " |
478 << "source " << GetNudgeSourceString(source) << ", " | 604 << "source " << GetNudgeSourceString(source) << ", " |
479 << "types " << ModelTypeSetToString(types); | 605 << "types " << ModelTypeSetToString(types); |
480 | 606 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 << "source " << GetUpdatesSourceString(source) << ", " | 644 << "source " << GetUpdatesSourceString(source) << ", " |
519 << "payloads " | 645 << "payloads " |
520 << syncable::ModelTypePayloadMapToString(types_with_payloads) | 646 << syncable::ModelTypePayloadMapToString(types_with_payloads) |
521 << (is_canary_job ? " (canary)" : ""); | 647 << (is_canary_job ? " (canary)" : ""); |
522 | 648 |
523 SyncSourceInfo info(source, types_with_payloads); | 649 SyncSourceInfo info(source, types_with_payloads); |
524 | 650 |
525 SyncSession* session(CreateSyncSession(info)); | 651 SyncSession* session(CreateSyncSession(info)); |
526 SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now() + delay, | 652 SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now() + delay, |
527 make_linked_ptr(session), is_canary_job, | 653 make_linked_ptr(session), is_canary_job, |
528 nudge_location); | 654 ConfigurationParams(), nudge_location); |
529 | 655 |
530 session = NULL; | 656 session = NULL; |
531 if (!ShouldRunJob(job)) | 657 if (!ShouldRunJob(job)) |
532 return; | 658 return; |
533 | 659 |
534 if (pending_nudge_.get()) { | 660 if (pending_nudge_.get()) { |
535 if (IsBackingOff() && delay > TimeDelta::FromSeconds(1)) { | 661 if (IsBackingOff() && delay > TimeDelta::FromSeconds(1)) { |
536 SDVLOG(2) << "Dropping the nudge because we are in backoff"; | 662 SDVLOG(2) << "Dropping the nudge because we are in backoff"; |
537 return; | 663 return; |
538 } | 664 } |
(...skipping 10 matching lines...) Expand all Loading... |
549 job.scheduled_start = std::min(job.scheduled_start, | 675 job.scheduled_start = std::min(job.scheduled_start, |
550 pending_nudge_->scheduled_start); | 676 pending_nudge_->scheduled_start); |
551 pending_nudge_.reset(); | 677 pending_nudge_.reset(); |
552 } | 678 } |
553 | 679 |
554 // TODO(zea): Consider adding separate throttling/backoff for datatype | 680 // TODO(zea): Consider adding separate throttling/backoff for datatype |
555 // refresh requests. | 681 // refresh requests. |
556 ScheduleSyncSessionJob(job); | 682 ScheduleSyncSessionJob(job); |
557 } | 683 } |
558 | 684 |
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) { | 685 const char* SyncScheduler::GetModeString(SyncScheduler::Mode mode) { |
631 switch (mode) { | 686 switch (mode) { |
632 ENUM_CASE(CONFIGURATION_MODE); | 687 ENUM_CASE(CONFIGURATION_MODE); |
633 ENUM_CASE(NORMAL_MODE); | 688 ENUM_CASE(NORMAL_MODE); |
634 } | 689 } |
635 return ""; | 690 return ""; |
636 } | 691 } |
637 | 692 |
638 const char* SyncScheduler::GetDecisionString( | 693 const char* SyncScheduler::GetDecisionString( |
639 SyncScheduler::JobProcessDecision mode) { | 694 SyncScheduler::JobProcessDecision mode) { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 ServerConnectionManager* scm = session_context_->connection_manager(); | 877 ServerConnectionManager* scm = session_context_->connection_manager(); |
823 UpdateServerConnectionManagerStatus(scm->server_status()); | 878 UpdateServerConnectionManagerStatus(scm->server_status()); |
824 | 879 |
825 UpdateCarryoverSessionState(job); | 880 UpdateCarryoverSessionState(job); |
826 if (IsSyncingCurrentlySilenced()) { | 881 if (IsSyncingCurrentlySilenced()) { |
827 SDVLOG(2) << "We are currently throttled; not scheduling the next sync."; | 882 SDVLOG(2) << "We are currently throttled; not scheduling the next sync."; |
828 // TODO(sync): Investigate whether we need to check job.purpose | 883 // TODO(sync): Investigate whether we need to check job.purpose |
829 // here; see DCHECKs in SaveJob(). (See http://crbug.com/90868.) | 884 // here; see DCHECKs in SaveJob(). (See http://crbug.com/90868.) |
830 SaveJob(job); | 885 SaveJob(job); |
831 return; // Nothing to do. | 886 return; // Nothing to do. |
| 887 } else if (job.session->Succeeded() && |
| 888 !job.config_params.ready_task.is_null()) { |
| 889 // If this was a configuration job with a ready task, invoke it now that |
| 890 // we finished successfully. |
| 891 job.config_params.ready_task.Run(); |
832 } | 892 } |
833 | 893 |
834 SDVLOG(2) << "Updating the next polling time after SyncMain"; | 894 SDVLOG(2) << "Updating the next polling time after SyncMain"; |
835 ScheduleNextSync(job); | 895 ScheduleNextSync(job); |
836 } | 896 } |
837 | 897 |
838 void SyncScheduler::ScheduleNextSync(const SyncSessionJob& old_job) { | 898 void SyncScheduler::ScheduleNextSync(const SyncSessionJob& old_job) { |
839 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 899 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
840 DCHECK(!old_job.session->HasMoreToSync()); | 900 DCHECK(!old_job.session->HasMoreToSync()); |
841 | 901 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 | 984 |
925 SDVLOG(2) << "In handle continuation error with " | 985 SDVLOG(2) << "In handle continuation error with " |
926 << SyncSessionJob::GetPurposeString(old_job.purpose) | 986 << SyncSessionJob::GetPurposeString(old_job.purpose) |
927 << " job. The time delta(ms) is " | 987 << " job. The time delta(ms) is " |
928 << length.InMilliseconds(); | 988 << length.InMilliseconds(); |
929 | 989 |
930 // This will reset the had_nudge variable as well. | 990 // This will reset the had_nudge variable as well. |
931 wait_interval_.reset(new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, | 991 wait_interval_.reset(new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, |
932 length)); | 992 length)); |
933 if (old_job.purpose == SyncSessionJob::CONFIGURATION) { | 993 if (old_job.purpose == SyncSessionJob::CONFIGURATION) { |
| 994 SDVLOG(2) << "Configuration did not succeed, scheduling retry."; |
| 995 // Config params should always get set. |
| 996 DCHECK(!old_job.config_params.ready_task.is_null()); |
934 SyncSession* old = old_job.session.get(); | 997 SyncSession* old = old_job.session.get(); |
935 SyncSession* s(new SyncSession(session_context_, this, | 998 SyncSession* s(new SyncSession(session_context_, this, |
936 old->source(), old->routing_info(), old->workers())); | 999 old->source(), old->routing_info(), old->workers())); |
937 SyncSessionJob job(old_job.purpose, TimeTicks::Now() + length, | 1000 SyncSessionJob job(old_job.purpose, TimeTicks::Now() + length, |
938 make_linked_ptr(s), false, FROM_HERE); | 1001 make_linked_ptr(s), false, old_job.config_params, |
| 1002 FROM_HERE); |
939 wait_interval_->pending_configure_job.reset(new SyncSessionJob(job)); | 1003 wait_interval_->pending_configure_job.reset(new SyncSessionJob(job)); |
940 } else { | 1004 } else { |
941 // We are not in configuration mode. So wait_interval's pending job | 1005 // We are not in configuration mode. So wait_interval's pending job |
942 // should be null. | 1006 // should be null. |
943 DCHECK(wait_interval_->pending_configure_job.get() == NULL); | 1007 DCHECK(wait_interval_->pending_configure_job.get() == NULL); |
944 | 1008 |
945 // TODO(lipalani) - handle clear user data. | 1009 // TODO(lipalani) - handle clear user data. |
946 InitOrCoalescePendingJob(old_job); | 1010 InitOrCoalescePendingJob(old_job); |
947 } | 1011 } |
948 RestartWaiting(); | 1012 RestartWaiting(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1114 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1051 ModelSafeRoutingInfo r; | 1115 ModelSafeRoutingInfo r; |
1052 ModelTypePayloadMap types_with_payloads = | 1116 ModelTypePayloadMap types_with_payloads = |
1053 syncable::ModelTypePayloadMapFromRoutingInfo(r, std::string()); | 1117 syncable::ModelTypePayloadMapFromRoutingInfo(r, std::string()); |
1054 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, types_with_payloads); | 1118 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, types_with_payloads); |
1055 SyncSession* s = CreateSyncSession(info); | 1119 SyncSession* s = CreateSyncSession(info); |
1056 | 1120 |
1057 SyncSessionJob job(SyncSessionJob::POLL, TimeTicks::Now(), | 1121 SyncSessionJob job(SyncSessionJob::POLL, TimeTicks::Now(), |
1058 make_linked_ptr(s), | 1122 make_linked_ptr(s), |
1059 false, | 1123 false, |
| 1124 ConfigurationParams(), |
1060 FROM_HERE); | 1125 FROM_HERE); |
1061 | 1126 |
1062 ScheduleSyncSessionJob(job); | 1127 ScheduleSyncSessionJob(job); |
1063 } | 1128 } |
1064 | 1129 |
1065 void SyncScheduler::Unthrottle() { | 1130 void SyncScheduler::Unthrottle() { |
1066 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1131 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1067 DCHECK_EQ(WaitInterval::THROTTLED, wait_interval_->mode); | 1132 DCHECK_EQ(WaitInterval::THROTTLED, wait_interval_->mode); |
1068 SDVLOG(2) << "Unthrottled."; | 1133 SDVLOG(2) << "Unthrottled."; |
1069 DoCanaryJob(); | 1134 DoCanaryJob(); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1152 | 1217 |
1153 #undef SDVLOG_LOC | 1218 #undef SDVLOG_LOC |
1154 | 1219 |
1155 #undef SDVLOG | 1220 #undef SDVLOG |
1156 | 1221 |
1157 #undef SLOG | 1222 #undef SLOG |
1158 | 1223 |
1159 #undef ENUM_CASE | 1224 #undef ENUM_CASE |
1160 | 1225 |
1161 } // browser_sync | 1226 } // browser_sync |
OLD | NEW |