OLD | NEW |
---|---|
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/sync_scheduler.h" | 5 #include "chrome/browser/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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
446 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 446 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
447 PostTask(FROM_HERE, "ScheduleClearUserDataImpl", | 447 PostTask(FROM_HERE, "ScheduleClearUserDataImpl", |
448 base::Bind(&SyncScheduler::ScheduleClearUserDataImpl, | 448 base::Bind(&SyncScheduler::ScheduleClearUserDataImpl, |
449 weak_ptr_factory_.GetWeakPtr())); | 449 weak_ptr_factory_.GetWeakPtr())); |
450 } | 450 } |
451 | 451 |
452 // TODO(sync): Remove the *Impl methods for the other Schedule* | 452 // TODO(sync): Remove the *Impl methods for the other Schedule* |
453 // functions, too. | 453 // functions, too. |
454 void SyncScheduler::ScheduleCleanupDisabledTypes() { | 454 void SyncScheduler::ScheduleCleanupDisabledTypes() { |
455 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 455 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
456 ScheduleSyncSessionJob( | 456 SyncSessionJob job(SyncSessionJob::CLEANUP_DISABLED_TYPES, TimeTicks::Now(), |
457 TimeDelta::FromSeconds(0), SyncSessionJob::CLEANUP_DISABLED_TYPES, | 457 make_linked_ptr(CreateSyncSession(SyncSourceInfo())), |
458 CreateSyncSession(SyncSourceInfo()), FROM_HERE); | 458 false, |
459 FROM_HERE); | |
460 ScheduleSyncSessionJob(job); | |
459 } | 461 } |
460 | 462 |
461 void SyncScheduler::ScheduleNudge( | 463 void SyncScheduler::ScheduleNudge( |
462 const TimeDelta& delay, | 464 const TimeDelta& delay, |
463 NudgeSource source, ModelTypeSet types, | 465 NudgeSource source, ModelTypeSet types, |
464 const tracked_objects::Location& nudge_location) { | 466 const tracked_objects::Location& nudge_location) { |
465 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 467 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
466 SDVLOG_LOC(nudge_location, 2) | 468 SDVLOG_LOC(nudge_location, 2) |
467 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " | 469 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " |
468 << "source " << GetNudgeSourceString(source) << ", " | 470 << "source " << GetNudgeSourceString(source) << ", " |
(...skipping 27 matching lines...) Expand all Loading... | |
496 weak_ptr_factory_.GetWeakPtr(), | 498 weak_ptr_factory_.GetWeakPtr(), |
497 delay, | 499 delay, |
498 GetUpdatesFromNudgeSource(source), | 500 GetUpdatesFromNudgeSource(source), |
499 types_with_payloads, | 501 types_with_payloads, |
500 false, | 502 false, |
501 nudge_location)); | 503 nudge_location)); |
502 } | 504 } |
503 | 505 |
504 void SyncScheduler::ScheduleClearUserDataImpl() { | 506 void SyncScheduler::ScheduleClearUserDataImpl() { |
505 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 507 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
506 ScheduleSyncSessionJob( | 508 SyncSessionJob job(SyncSessionJob::CLEAR_USER_DATA, TimeTicks::Now(), |
507 TimeDelta::FromSeconds(0), SyncSessionJob::CLEAR_USER_DATA, | 509 make_linked_ptr(CreateSyncSession(SyncSourceInfo())), |
508 CreateSyncSession(SyncSourceInfo()), FROM_HERE); | 510 false, |
511 FROM_HERE); | |
512 | |
513 ScheduleSyncSessionJob(job); | |
tim (not reviewing)
2011/12/16 02:52:10
suggestion here and elsewhere, you could just inli
| |
509 } | 514 } |
510 | 515 |
511 void SyncScheduler::ScheduleNudgeImpl( | 516 void SyncScheduler::ScheduleNudgeImpl( |
512 const TimeDelta& delay, | 517 const TimeDelta& delay, |
513 GetUpdatesCallerInfo::GetUpdatesSource source, | 518 GetUpdatesCallerInfo::GetUpdatesSource source, |
514 const ModelTypePayloadMap& types_with_payloads, | 519 const ModelTypePayloadMap& types_with_payloads, |
515 bool is_canary_job, const tracked_objects::Location& nudge_location) { | 520 bool is_canary_job, const tracked_objects::Location& nudge_location) { |
516 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 521 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
517 | 522 |
518 SDVLOG_LOC(nudge_location, 2) | 523 SDVLOG_LOC(nudge_location, 2) |
(...skipping 17 matching lines...) Expand all Loading... | |
536 | 541 |
537 if (pending_nudge_.get()) { | 542 if (pending_nudge_.get()) { |
538 if (IsBackingOff() && delay > TimeDelta::FromSeconds(1)) { | 543 if (IsBackingOff() && delay > TimeDelta::FromSeconds(1)) { |
539 SDVLOG(2) << "Dropping the nudge because we are in backoff"; | 544 SDVLOG(2) << "Dropping the nudge because we are in backoff"; |
540 return; | 545 return; |
541 } | 546 } |
542 | 547 |
543 SDVLOG(2) << "Coalescing pending nudge"; | 548 SDVLOG(2) << "Coalescing pending nudge"; |
544 pending_nudge_->session->Coalesce(*(job.session.get())); | 549 pending_nudge_->session->Coalesce(*(job.session.get())); |
545 | 550 |
546 if (!IsBackingOff()) { | 551 SDVLOG(2) << "Rescheduling pending nudge"; |
547 SDVLOG(2) << "Dropping a nudge because" | 552 SyncSession* s = pending_nudge_->session.get(); |
548 << " we are not in backoff and the job was coalesced"; | 553 job.session.reset(new SyncSession(s->context(), s->delegate(), |
549 return; | 554 s->source(), s->routing_info(), s->workers())); |
550 } else { | 555 |
551 SDVLOG(2) << "Rescheduling pending nudge"; | 556 // Choose the start time as the earliest of the 2. |
552 SyncSession* s = pending_nudge_->session.get(); | 557 job.scheduled_start = std::min(job.scheduled_start, |
553 job.session.reset(new SyncSession(s->context(), s->delegate(), | 558 pending_nudge_->scheduled_start); |
554 s->source(), s->routing_info(), s->workers())); | 559 pending_nudge_.reset(); |
555 pending_nudge_.reset(); | |
556 } | |
557 } | 560 } |
558 | 561 |
559 // TODO(lipalani) - pass the job itself to ScheduleSyncSessionJob. | 562 ScheduleSyncSessionJob(job); |
560 ScheduleSyncSessionJob(delay, SyncSessionJob::NUDGE, job.session.release(), | |
561 nudge_location); | |
562 } | 563 } |
563 | 564 |
564 // Helper to extract the routing info and workers corresponding to types in | 565 // Helper to extract the routing info and workers corresponding to types in |
565 // |types| from |registrar|. | 566 // |types| from |registrar|. |
566 void GetModelSafeParamsForTypes(ModelTypeSet types, | 567 void GetModelSafeParamsForTypes(ModelTypeSet types, |
567 ModelSafeWorkerRegistrar* registrar, ModelSafeRoutingInfo* routes, | 568 ModelSafeWorkerRegistrar* registrar, ModelSafeRoutingInfo* routes, |
568 std::vector<ModelSafeWorker*>* workers) { | 569 std::vector<ModelSafeWorker*>* workers) { |
569 ModelSafeRoutingInfo r_tmp; | 570 ModelSafeRoutingInfo r_tmp; |
570 std::vector<ModelSafeWorker*> w_tmp; | 571 std::vector<ModelSafeWorker*> w_tmp; |
571 registrar->GetModelSafeRoutingInfo(&r_tmp); | 572 registrar->GetModelSafeRoutingInfo(&r_tmp); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
630 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { | 631 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { |
631 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 632 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
632 | 633 |
633 SDVLOG(2) << "In ScheduleConfigImpl"; | 634 SDVLOG(2) << "In ScheduleConfigImpl"; |
634 // TODO(tim): config-specific GetUpdatesCallerInfo value? | 635 // TODO(tim): config-specific GetUpdatesCallerInfo value? |
635 SyncSession* session = new SyncSession(session_context_.get(), this, | 636 SyncSession* session = new SyncSession(session_context_.get(), this, |
636 SyncSourceInfo(source, | 637 SyncSourceInfo(source, |
637 syncable::ModelTypePayloadMapFromRoutingInfo( | 638 syncable::ModelTypePayloadMapFromRoutingInfo( |
638 routing_info, std::string())), | 639 routing_info, std::string())), |
639 routing_info, workers); | 640 routing_info, workers); |
640 ScheduleSyncSessionJob(TimeDelta::FromSeconds(0), | 641 SyncSessionJob job(SyncSessionJob::CONFIGURATION, TimeTicks::Now(), |
641 SyncSessionJob::CONFIGURATION, session, FROM_HERE); | 642 make_linked_ptr(session), |
643 false, | |
644 FROM_HERE); | |
645 ScheduleSyncSessionJob(job); | |
642 } | 646 } |
643 | 647 |
644 const char* SyncScheduler::GetModeString(SyncScheduler::Mode mode) { | 648 const char* SyncScheduler::GetModeString(SyncScheduler::Mode mode) { |
645 switch (mode) { | 649 switch (mode) { |
646 ENUM_CASE(CONFIGURATION_MODE); | 650 ENUM_CASE(CONFIGURATION_MODE); |
647 ENUM_CASE(NORMAL_MODE); | 651 ENUM_CASE(NORMAL_MODE); |
648 } | 652 } |
649 return ""; | 653 return ""; |
650 } | 654 } |
651 | 655 |
(...skipping 25 matching lines...) Expand all Loading... | |
677 SDVLOG_LOC(from_here, 3) << "Posting " << name << " task with " | 681 SDVLOG_LOC(from_here, 3) << "Posting " << name << " task with " |
678 << delay_ms << " ms delay"; | 682 << delay_ms << " ms delay"; |
679 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 683 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
680 if (!started_) { | 684 if (!started_) { |
681 SDVLOG(1) << "Not posting task as scheduler is stopped."; | 685 SDVLOG(1) << "Not posting task as scheduler is stopped."; |
682 return; | 686 return; |
683 } | 687 } |
684 sync_loop_->PostDelayedTask(from_here, task, delay_ms); | 688 sync_loop_->PostDelayedTask(from_here, task, delay_ms); |
685 } | 689 } |
686 | 690 |
687 void SyncScheduler::ScheduleSyncSessionJob( | 691 void SyncScheduler::ScheduleSyncSessionJob(const SyncSessionJob& job) { |
688 const base::TimeDelta& delay, | |
689 SyncSessionJob::SyncSessionJobPurpose purpose, | |
690 sessions::SyncSession* session, | |
691 const tracked_objects::Location& from_here) { | |
692 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 692 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
693 SDVLOG_LOC(from_here, 2) | 693 TimeDelta delay = job.scheduled_start - TimeTicks::Now(); |
694 if (delay < TimeDelta::FromMilliseconds(0)) | |
695 delay = TimeDelta::FromMilliseconds(0); | |
696 SDVLOG_LOC(job.from_here, 2) | |
694 << "In ScheduleSyncSessionJob with " | 697 << "In ScheduleSyncSessionJob with " |
695 << SyncSessionJob::GetPurposeString(purpose) | 698 << SyncSessionJob::GetPurposeString(job.purpose) |
696 << " job and " << delay.InMilliseconds() << " ms delay"; | 699 << " job and " << delay.InMilliseconds() << " ms delay"; |
697 | 700 |
698 SyncSessionJob job(purpose, TimeTicks::Now() + delay, | 701 if (job.purpose == SyncSessionJob::NUDGE) { |
699 make_linked_ptr(session), false, from_here); | 702 SDVLOG_LOC(job.from_here, 2) << "Resetting pending_nudge"; |
700 if (purpose == SyncSessionJob::NUDGE) { | 703 DCHECK(!pending_nudge_.get() || pending_nudge_->session.get() == |
701 SDVLOG_LOC(from_here, 2) << "Resetting pending_nudge"; | 704 job.session); |
702 DCHECK(!pending_nudge_.get() || pending_nudge_->session.get() == session); | |
703 pending_nudge_.reset(new SyncSessionJob(job)); | 705 pending_nudge_.reset(new SyncSessionJob(job)); |
704 } | 706 } |
705 PostDelayedTask(from_here, "DoSyncSessionJob", | 707 PostDelayedTask(job.from_here, "DoSyncSessionJob", |
706 base::Bind(&SyncScheduler::DoSyncSessionJob, | 708 base::Bind(&SyncScheduler::DoSyncSessionJob, |
707 weak_ptr_factory_.GetWeakPtr(), | 709 weak_ptr_factory_.GetWeakPtr(), |
708 job), | 710 job), |
709 delay.InMilliseconds()); | 711 delay.InMilliseconds()); |
710 } | 712 } |
711 | 713 |
712 void SyncScheduler::SetSyncerStepsForPurpose( | 714 void SyncScheduler::SetSyncerStepsForPurpose( |
713 SyncSessionJob::SyncSessionJobPurpose purpose, | 715 SyncSessionJob::SyncSessionJobPurpose purpose, |
714 SyncerStep* start, SyncerStep* end) { | 716 SyncerStep* start, SyncerStep* end) { |
715 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 717 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1075 return session; | 1077 return session; |
1076 } | 1078 } |
1077 | 1079 |
1078 void SyncScheduler::PollTimerCallback() { | 1080 void SyncScheduler::PollTimerCallback() { |
1079 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1081 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1080 ModelSafeRoutingInfo r; | 1082 ModelSafeRoutingInfo r; |
1081 ModelTypePayloadMap types_with_payloads = | 1083 ModelTypePayloadMap types_with_payloads = |
1082 syncable::ModelTypePayloadMapFromRoutingInfo(r, std::string()); | 1084 syncable::ModelTypePayloadMapFromRoutingInfo(r, std::string()); |
1083 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, types_with_payloads); | 1085 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, types_with_payloads); |
1084 SyncSession* s = CreateSyncSession(info); | 1086 SyncSession* s = CreateSyncSession(info); |
1085 ScheduleSyncSessionJob(TimeDelta::FromSeconds(0), SyncSessionJob::POLL, s, | 1087 |
1086 FROM_HERE); | 1088 SyncSessionJob job(SyncSessionJob::POLL, TimeTicks::Now(), |
1089 make_linked_ptr(s), | |
1090 false, | |
1091 FROM_HERE); | |
1092 | |
1093 ScheduleSyncSessionJob(job); | |
1087 } | 1094 } |
1088 | 1095 |
1089 void SyncScheduler::Unthrottle() { | 1096 void SyncScheduler::Unthrottle() { |
1090 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1097 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1091 DCHECK_EQ(WaitInterval::THROTTLED, wait_interval_->mode); | 1098 DCHECK_EQ(WaitInterval::THROTTLED, wait_interval_->mode); |
1092 SDVLOG(2) << "Unthrottled."; | 1099 SDVLOG(2) << "Unthrottled."; |
1093 DoCanaryJob(); | 1100 DoCanaryJob(); |
1094 wait_interval_.reset(); | 1101 wait_interval_.reset(); |
1095 } | 1102 } |
1096 | 1103 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1187 | 1194 |
1188 #undef SDVLOG_LOC | 1195 #undef SDVLOG_LOC |
1189 | 1196 |
1190 #undef SDVLOG | 1197 #undef SDVLOG |
1191 | 1198 |
1192 #undef SLOG | 1199 #undef SLOG |
1193 | 1200 |
1194 #undef ENUM_CASE | 1201 #undef ENUM_CASE |
1195 | 1202 |
1196 } // browser_sync | 1203 } // browser_sync |
OLD | NEW |