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_impl.h" | 5 #include "sync/engine/sync_scheduler_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 session_context_, | 340 session_context_, |
341 this, | 341 this, |
342 SyncSourceInfo(params.source, | 342 SyncSourceInfo(params.source, |
343 ModelSafeRoutingInfoToInvalidationMap( | 343 ModelSafeRoutingInfoToInvalidationMap( |
344 restricted_routes, | 344 restricted_routes, |
345 std::string())))); | 345 std::string())))); |
346 scoped_ptr<SyncSessionJob> job(new SyncSessionJob( | 346 scoped_ptr<SyncSessionJob> job(new SyncSessionJob( |
347 SyncSessionJob::CONFIGURATION, | 347 SyncSessionJob::CONFIGURATION, |
348 TimeTicks::Now(), | 348 TimeTicks::Now(), |
349 session.Pass(), | 349 session.Pass(), |
350 params, | 350 params)); |
351 FROM_HERE)); | |
352 job->set_destruction_observer(weak_ptr_factory_.GetWeakPtr()); | 351 job->set_destruction_observer(weak_ptr_factory_.GetWeakPtr()); |
353 bool succeeded = DoSyncSessionJob(job.Pass()); | 352 bool succeeded = DoSyncSessionJob(job.Pass()); |
354 | 353 |
355 // If we failed, the job would have been saved as the pending configure | 354 // If we failed, the job would have been saved as the pending configure |
356 // job and a wait interval would have been set. | 355 // job and a wait interval would have been set. |
357 if (!succeeded) { | 356 if (!succeeded) { |
358 DCHECK(wait_interval_.get() && wait_interval_->pending_configure_job); | 357 DCHECK(wait_interval_.get() && wait_interval_->pending_configure_job); |
359 return false; | 358 return false; |
360 } | 359 } |
361 } else { | 360 } else { |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 << "payloads " | 611 << "payloads " |
613 << ModelTypeInvalidationMapToString(invalidation_map); | 612 << ModelTypeInvalidationMapToString(invalidation_map); |
614 | 613 |
615 SyncSourceInfo info(source, invalidation_map); | 614 SyncSourceInfo info(source, invalidation_map); |
616 UpdateNudgeTimeRecords(info); | 615 UpdateNudgeTimeRecords(info); |
617 | 616 |
618 scoped_ptr<SyncSessionJob> job(new SyncSessionJob( | 617 scoped_ptr<SyncSessionJob> job(new SyncSessionJob( |
619 SyncSessionJob::NUDGE, | 618 SyncSessionJob::NUDGE, |
620 TimeTicks::Now() + delay, | 619 TimeTicks::Now() + delay, |
621 CreateSyncSession(info).Pass(), | 620 CreateSyncSession(info).Pass(), |
622 ConfigurationParams(), | 621 ConfigurationParams())); |
623 nudge_location)); | |
624 job->set_destruction_observer(weak_ptr_factory_.GetWeakPtr()); | 622 job->set_destruction_observer(weak_ptr_factory_.GetWeakPtr()); |
625 JobProcessDecision decision = DecideOnJob(*job); | 623 JobProcessDecision decision = DecideOnJob(*job); |
626 SDVLOG(2) << "Should run " | 624 SDVLOG(2) << "Should run " |
627 << SyncSessionJob::GetPurposeString(job->purpose()) | 625 << SyncSessionJob::GetPurposeString(job->purpose()) |
628 << " job " << job->session() | 626 << " job " << job->session() |
629 << " in mode " << GetModeString(mode_) | 627 << " in mode " << GetModeString(mode_) |
630 << ": " << GetDecisionString(decision); | 628 << ": " << GetDecisionString(decision); |
631 if (decision != CONTINUE) { | 629 if (decision != CONTINUE) { |
632 // End of the line, though we may save the job for later. | 630 // End of the line, though we may save the job for later. |
633 if (decision == SAVE) { | 631 if (decision == SAVE) { |
(...skipping 21 matching lines...) Expand all Loading... |
655 job = pending_nudge_->CloneAndAbandon(); | 653 job = pending_nudge_->CloneAndAbandon(); |
656 pending_nudge_ = NULL; | 654 pending_nudge_ = NULL; |
657 unscheduled_nudge_storage_.reset(); | 655 unscheduled_nudge_storage_.reset(); |
658 // It's also possible we took a canary job, since we allow one nudge | 656 // It's also possible we took a canary job, since we allow one nudge |
659 // per backoff interval. | 657 // per backoff interval. |
660 DCHECK(!wait_interval_ || !wait_interval_->had_nudge); | 658 DCHECK(!wait_interval_ || !wait_interval_->had_nudge); |
661 } | 659 } |
662 | 660 |
663 // TODO(zea): Consider adding separate throttling/backoff for datatype | 661 // TODO(zea): Consider adding separate throttling/backoff for datatype |
664 // refresh requests. | 662 // refresh requests. |
665 ScheduleSyncSessionJob(job.Pass()); | 663 ScheduleSyncSessionJob(nudge_location, job.Pass()); |
666 } | 664 } |
667 | 665 |
668 const char* SyncSchedulerImpl::GetModeString(SyncScheduler::Mode mode) { | 666 const char* SyncSchedulerImpl::GetModeString(SyncScheduler::Mode mode) { |
669 switch (mode) { | 667 switch (mode) { |
670 ENUM_CASE(CONFIGURATION_MODE); | 668 ENUM_CASE(CONFIGURATION_MODE); |
671 ENUM_CASE(NORMAL_MODE); | 669 ENUM_CASE(NORMAL_MODE); |
672 } | 670 } |
673 return ""; | 671 return ""; |
674 } | 672 } |
675 | 673 |
(...skipping 26 matching lines...) Expand all Loading... |
702 << delay.InMilliseconds() << " ms delay"; | 700 << delay.InMilliseconds() << " ms delay"; |
703 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 701 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
704 if (!started_) { | 702 if (!started_) { |
705 SDVLOG(1) << "Not posting task as scheduler is stopped."; | 703 SDVLOG(1) << "Not posting task as scheduler is stopped."; |
706 return; | 704 return; |
707 } | 705 } |
708 sync_loop_->PostDelayedTask(from_here, task, delay); | 706 sync_loop_->PostDelayedTask(from_here, task, delay); |
709 } | 707 } |
710 | 708 |
711 void SyncSchedulerImpl::ScheduleSyncSessionJob( | 709 void SyncSchedulerImpl::ScheduleSyncSessionJob( |
| 710 const tracked_objects::Location& loc, |
712 scoped_ptr<SyncSessionJob> job) { | 711 scoped_ptr<SyncSessionJob> job) { |
713 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 712 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
714 if (no_scheduling_allowed_) { | 713 if (no_scheduling_allowed_) { |
715 NOTREACHED() << "Illegal to schedule job while session in progress."; | 714 NOTREACHED() << "Illegal to schedule job while session in progress."; |
716 return; | 715 return; |
717 } | 716 } |
718 | 717 |
719 TimeDelta delay = job->scheduled_start() - TimeTicks::Now(); | 718 TimeDelta delay = job->scheduled_start() - TimeTicks::Now(); |
720 tracked_objects::Location loc(job->from_location()); | |
721 if (delay < TimeDelta::FromMilliseconds(0)) | 719 if (delay < TimeDelta::FromMilliseconds(0)) |
722 delay = TimeDelta::FromMilliseconds(0); | 720 delay = TimeDelta::FromMilliseconds(0); |
723 SDVLOG_LOC(loc, 2) | 721 SDVLOG_LOC(loc, 2) |
724 << "In ScheduleSyncSessionJob with " | 722 << "In ScheduleSyncSessionJob with " |
725 << SyncSessionJob::GetPurposeString(job->purpose()) | 723 << SyncSessionJob::GetPurposeString(job->purpose()) |
726 << " job and " << delay.InMilliseconds() << " ms delay"; | 724 << " job and " << delay.InMilliseconds() << " ms delay"; |
727 | 725 |
728 DCHECK(job->purpose() == SyncSessionJob::NUDGE || | 726 DCHECK(job->purpose() == SyncSessionJob::NUDGE || |
729 job->purpose() == SyncSessionJob::POLL); | 727 job->purpose() == SyncSessionJob::POLL); |
730 if (job->purpose() == SyncSessionJob::NUDGE) { | 728 if (job->purpose() == SyncSessionJob::NUDGE) { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 | 958 |
961 SDVLOG(2) << "In handle continuation error with " | 959 SDVLOG(2) << "In handle continuation error with " |
962 << SyncSessionJob::GetPurposeString(old_job->purpose()) | 960 << SyncSessionJob::GetPurposeString(old_job->purpose()) |
963 << " job. The time delta(ms) is " | 961 << " job. The time delta(ms) is " |
964 << length.InMilliseconds(); | 962 << length.InMilliseconds(); |
965 | 963 |
966 // This will reset the had_nudge variable as well. | 964 // This will reset the had_nudge variable as well. |
967 wait_interval_.reset(new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, | 965 wait_interval_.reset(new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, |
968 length)); | 966 length)); |
969 NotifyRetryTime(base::Time::Now() + length); | 967 NotifyRetryTime(base::Time::Now() + length); |
970 scoped_ptr<SyncSessionJob> new_job(old_job->CloneFromLocation(FROM_HERE)); | 968 scoped_ptr<SyncSessionJob> new_job(old_job->Clone()); |
971 new_job->set_scheduled_start(TimeTicks::Now() + length); | 969 new_job->set_scheduled_start(TimeTicks::Now() + length); |
972 if (old_job->purpose() == SyncSessionJob::CONFIGURATION) { | 970 if (old_job->purpose() == SyncSessionJob::CONFIGURATION) { |
973 SDVLOG(2) << "Configuration did not succeed, scheduling retry."; | 971 SDVLOG(2) << "Configuration did not succeed, scheduling retry."; |
974 // Config params should always get set. | 972 // Config params should always get set. |
975 DCHECK(!old_job->config_params().ready_task.is_null()); | 973 DCHECK(!old_job->config_params().ready_task.is_null()); |
976 wait_interval_->pending_configure_job = new_job.get(); | 974 wait_interval_->pending_configure_job = new_job.get(); |
977 } else { | 975 } else { |
978 // We are not in configuration mode. So wait_interval's pending job | 976 // We are not in configuration mode. So wait_interval's pending job |
979 // should be null. | 977 // should be null. |
980 DCHECK(wait_interval_->pending_configure_job == NULL); | 978 DCHECK(wait_interval_->pending_configure_job == NULL); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 void SyncSchedulerImpl::PollTimerCallback() { | 1070 void SyncSchedulerImpl::PollTimerCallback() { |
1073 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1071 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1074 ModelSafeRoutingInfo r; | 1072 ModelSafeRoutingInfo r; |
1075 ModelTypeInvalidationMap invalidation_map = | 1073 ModelTypeInvalidationMap invalidation_map = |
1076 ModelSafeRoutingInfoToInvalidationMap(r, std::string()); | 1074 ModelSafeRoutingInfoToInvalidationMap(r, std::string()); |
1077 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, invalidation_map); | 1075 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, invalidation_map); |
1078 scoped_ptr<SyncSession> s(CreateSyncSession(info)); | 1076 scoped_ptr<SyncSession> s(CreateSyncSession(info)); |
1079 scoped_ptr<SyncSessionJob> job(new SyncSessionJob(SyncSessionJob::POLL, | 1077 scoped_ptr<SyncSessionJob> job(new SyncSessionJob(SyncSessionJob::POLL, |
1080 TimeTicks::Now(), | 1078 TimeTicks::Now(), |
1081 s.Pass(), | 1079 s.Pass(), |
1082 ConfigurationParams(), | 1080 ConfigurationParams())); |
1083 FROM_HERE)); | |
1084 job->set_destruction_observer(weak_ptr_factory_.GetWeakPtr()); | 1081 job->set_destruction_observer(weak_ptr_factory_.GetWeakPtr()); |
1085 ScheduleSyncSessionJob(job.Pass()); | 1082 ScheduleSyncSessionJob(FROM_HERE, job.Pass()); |
1086 } | 1083 } |
1087 | 1084 |
1088 void SyncSchedulerImpl::Unthrottle(scoped_ptr<SyncSessionJob> to_be_canary) { | 1085 void SyncSchedulerImpl::Unthrottle(scoped_ptr<SyncSessionJob> to_be_canary) { |
1089 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1086 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1090 DCHECK_EQ(WaitInterval::THROTTLED, wait_interval_->mode); | 1087 DCHECK_EQ(WaitInterval::THROTTLED, wait_interval_->mode); |
1091 DCHECK(!to_be_canary.get() || pending_nudge_ == to_be_canary.get() || | 1088 DCHECK(!to_be_canary.get() || pending_nudge_ == to_be_canary.get() || |
1092 wait_interval_->pending_configure_job == to_be_canary.get()); | 1089 wait_interval_->pending_configure_job == to_be_canary.get()); |
1093 SDVLOG(2) << "Unthrottled " << (to_be_canary.get() ? "with " : "without ") | 1090 SDVLOG(2) << "Unthrottled " << (to_be_canary.get() ? "with " : "without ") |
1094 << "canary."; | 1091 << "canary."; |
1095 | 1092 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 | 1195 |
1199 #undef SDVLOG_LOC | 1196 #undef SDVLOG_LOC |
1200 | 1197 |
1201 #undef SDVLOG | 1198 #undef SDVLOG |
1202 | 1199 |
1203 #undef SLOG | 1200 #undef SLOG |
1204 | 1201 |
1205 #undef ENUM_CASE | 1202 #undef ENUM_CASE |
1206 | 1203 |
1207 } // namespace syncer | 1204 } // namespace syncer |
OLD | NEW |