| Index: chrome/browser/sync/engine/sync_scheduler.cc
|
| diff --git a/chrome/browser/sync/engine/sync_scheduler.cc b/chrome/browser/sync/engine/sync_scheduler.cc
|
| index 993b72755abcd019a89a4ff8380c7a91d5c9dbac..ea3a8474320c618c808efe663f6bb5f8f5e7ad6a 100644
|
| --- a/chrome/browser/sync/engine/sync_scheduler.cc
|
| +++ b/chrome/browser/sync/engine/sync_scheduler.cc
|
| @@ -58,14 +58,18 @@ SyncScheduler::SyncSessionJob::SyncSessionJob()
|
|
|
| SyncScheduler::SyncSessionJob::~SyncSessionJob() {}
|
|
|
| -SyncScheduler::SyncSessionJob::SyncSessionJob(SyncSessionJobPurpose purpose,
|
| +SyncScheduler::SyncSessionJob::SyncSessionJob(
|
| + SyncSessionJobPurpose purpose,
|
| base::TimeTicks start,
|
| linked_ptr<sessions::SyncSession> session, bool is_canary_job,
|
| - const tracked_objects::Location& from_here) : purpose(purpose),
|
| - scheduled_start(start),
|
| - session(session),
|
| - is_canary_job(is_canary_job),
|
| - from_here(from_here) {
|
| + const base::Closure& on_success,
|
| + const tracked_objects::Location& from_here)
|
| + : purpose(purpose),
|
| + scheduled_start(start),
|
| + session(session),
|
| + is_canary_job(is_canary_job),
|
| + on_success(on_success),
|
| + from_here(from_here) {
|
| }
|
|
|
| const char* SyncScheduler::SyncSessionJob::GetPurposeString(
|
| @@ -199,7 +203,7 @@ void SyncScheduler::CheckServerConnectionManagerStatus(
|
| }
|
| }
|
|
|
| -void SyncScheduler::Start(Mode mode, ModeChangeCallback* callback) {
|
| +void SyncScheduler::Start(Mode mode, const base::Closure& callback) {
|
| DCHECK_EQ(MessageLoop::current(), sync_loop_);
|
| std::string thread_name = MessageLoop::current()->thread_name();
|
| if (thread_name.empty())
|
| @@ -213,8 +217,6 @@ void SyncScheduler::Start(Mode mode, ModeChangeCallback* callback) {
|
| &SyncScheduler::SendInitialSnapshot));
|
| }
|
| started_ = true;
|
| - // TODO(sync): This will leak if StartImpl is never run. Fix this.
|
| - // Might be easiest to just use base::Callback.
|
| PostTask(FROM_HERE, "StartImpl",
|
| method_factory_.NewRunnableMethod(
|
| &SyncScheduler::StartImpl, mode, callback));
|
| @@ -241,19 +243,18 @@ void SyncScheduler::WatchConnectionManager() {
|
| scm->AddListener(this);
|
| }
|
|
|
| -void SyncScheduler::StartImpl(Mode mode, ModeChangeCallback* callback) {
|
| +void SyncScheduler::StartImpl(Mode mode, const base::Closure& callback) {
|
| DCHECK_EQ(MessageLoop::current(), sync_loop_);
|
| SVLOG(2) << "In StartImpl with mode " << GetModeString(mode);
|
|
|
| - scoped_ptr<ModeChangeCallback> scoped_callback(callback);
|
| DCHECK_EQ(MessageLoop::current(), sync_loop_);
|
| DCHECK(!session_context_->account_name().empty());
|
| DCHECK(syncer_.get());
|
| Mode old_mode = mode_;
|
| mode_ = mode;
|
| AdjustPolling(NULL); // Will kick start poll timer if needed.
|
| - if (scoped_callback.get())
|
| - scoped_callback->Run();
|
| + if (!callback.is_null())
|
| + callback.Run();
|
|
|
| if (old_mode != mode_) {
|
| // We just changed our mode. See if there are any pending jobs that we could
|
| @@ -343,7 +344,8 @@ void SyncScheduler::InitOrCoalescePendingJob(const SyncSessionJob& job) {
|
| s->delegate(), s->source(), s->routing_info(), s->workers()));
|
|
|
| SyncSessionJob new_job(SyncSessionJob::NUDGE, job.scheduled_start,
|
| - make_linked_ptr(session.release()), false, job.from_here);
|
| + make_linked_ptr(session.release()),
|
| + false, base::Closure(), job.from_here);
|
| pending_nudge_.reset(new SyncSessionJob(new_job));
|
|
|
| return;
|
| @@ -391,7 +393,8 @@ void SyncScheduler::SaveJob(const SyncSessionJob& job) {
|
| SyncSession* s(new SyncSession(session_context_.get(), this,
|
| old->source(), old->routing_info(), old->workers()));
|
| SyncSessionJob new_job(job.purpose, TimeTicks::Now(),
|
| - make_linked_ptr(s), false, job.from_here);
|
| + make_linked_ptr(s), false, base::Closure(),
|
| + job.from_here);
|
| wait_interval_->pending_configure_job.reset(new SyncSessionJob(new_job));
|
| } // drop the rest.
|
| // TODO(sync): Is it okay to drop the rest? It's weird that
|
| @@ -415,11 +418,12 @@ void SyncScheduler::ScheduleClearUserData() {
|
| &SyncScheduler::ScheduleClearUserDataImpl));
|
| }
|
|
|
| -void SyncScheduler::ScheduleCleanupDisabledTypes() {
|
| +void SyncScheduler::ScheduleCleanupDisabledTypes(
|
| + const base::Closure& callback) {
|
| DCHECK_EQ(MessageLoop::current(), sync_loop_);
|
| PostTask(FROM_HERE, "ScheduleCleanupDisabledTypes",
|
| method_factory_.NewRunnableMethod(
|
| - &SyncScheduler::ScheduleCleanupDisabledTypesImpl));
|
| + &SyncScheduler::ScheduleCleanupDisabledTypesImpl, callback));
|
| }
|
|
|
| void SyncScheduler::ScheduleNudge(
|
| @@ -463,14 +467,15 @@ void SyncScheduler::ScheduleClearUserDataImpl() {
|
| DCHECK_EQ(MessageLoop::current(), sync_loop_);
|
| ScheduleSyncSessionJob(
|
| TimeDelta::FromSeconds(0), SyncSessionJob::CLEAR_USER_DATA,
|
| - CreateSyncSession(SyncSourceInfo()), FROM_HERE);
|
| + CreateSyncSession(SyncSourceInfo()), base::Closure(), FROM_HERE);
|
| }
|
|
|
| -void SyncScheduler::ScheduleCleanupDisabledTypesImpl() {
|
| +void SyncScheduler::ScheduleCleanupDisabledTypesImpl(
|
| + const base::Closure& callback) {
|
| DCHECK_EQ(MessageLoop::current(), sync_loop_);
|
| ScheduleSyncSessionJob(
|
| TimeDelta::FromSeconds(0), SyncSessionJob::CLEANUP_DISABLED_TYPES,
|
| - CreateSyncSession(SyncSourceInfo()), FROM_HERE);
|
| + CreateSyncSession(SyncSourceInfo()), callback, FROM_HERE);
|
| }
|
|
|
| void SyncScheduler::ScheduleNudgeImpl(
|
| @@ -493,7 +498,7 @@ void SyncScheduler::ScheduleNudgeImpl(
|
| SyncSession* session(CreateSyncSession(info));
|
| SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now() + delay,
|
| make_linked_ptr(session), is_canary_job,
|
| - nudge_location);
|
| + base::Closure(), nudge_location);
|
|
|
| session = NULL;
|
| if (!ShouldRunJob(job))
|
| @@ -523,7 +528,7 @@ void SyncScheduler::ScheduleNudgeImpl(
|
|
|
| // TODO(lipalani) - pass the job itself to ScheduleSyncSessionJob.
|
| ScheduleSyncSessionJob(delay, SyncSessionJob::NUDGE, job.session.release(),
|
| - nudge_location);
|
| + base::Closure(), nudge_location);
|
| }
|
|
|
| // Helper to extract the routing info and workers corresponding to types in
|
| @@ -600,7 +605,8 @@ void SyncScheduler::ScheduleConfigImpl(
|
| routing_info, std::string())),
|
| routing_info, workers);
|
| ScheduleSyncSessionJob(TimeDelta::FromSeconds(0),
|
| - SyncSessionJob::CONFIGURATION, session, FROM_HERE);
|
| + SyncSessionJob::CONFIGURATION,
|
| + session, base::Closure(), FROM_HERE);
|
| }
|
|
|
| const char* SyncScheduler::GetModeString(SyncScheduler::Mode mode) {
|
| @@ -640,6 +646,7 @@ void SyncScheduler::ScheduleSyncSessionJob(
|
| const base::TimeDelta& delay,
|
| SyncSessionJob::SyncSessionJobPurpose purpose,
|
| sessions::SyncSession* session,
|
| + const base::Closure& on_success,
|
| const tracked_objects::Location& from_here) {
|
| DCHECK_EQ(MessageLoop::current(), sync_loop_);
|
| SVLOG_LOC(from_here, 2)
|
| @@ -648,7 +655,7 @@ void SyncScheduler::ScheduleSyncSessionJob(
|
| << " job and " << delay.InMilliseconds() << " ms delay";
|
|
|
| SyncSessionJob job(purpose, TimeTicks::Now() + delay,
|
| - make_linked_ptr(session), false, from_here);
|
| + make_linked_ptr(session), false, on_success, from_here);
|
| if (purpose == SyncSessionJob::NUDGE) {
|
| SVLOG_LOC(from_here, 2) << "Resetting pending_nudge";
|
| DCHECK(!pending_nudge_.get() || pending_nudge_->session.get() == session);
|
| @@ -782,6 +789,8 @@ void SyncScheduler::FinishSyncSessionJob(const SyncSessionJob& job) {
|
|
|
| SVLOG(2) << "Updating the next polling time after SyncMain";
|
| ScheduleNextSync(job);
|
| + if (!job.on_success.is_null())
|
| + job.on_success.Run();
|
| }
|
|
|
| void SyncScheduler::ScheduleNextSync(const SyncSessionJob& old_job) {
|
| @@ -910,7 +919,8 @@ void SyncScheduler::HandleConsecutiveContinuationError(
|
| SyncSession* s(new SyncSession(session_context_.get(), this,
|
| old->source(), old->routing_info(), old->workers()));
|
| SyncSessionJob job(old_job.purpose, TimeTicks::Now() + length,
|
| - make_linked_ptr(s), false, FROM_HERE);
|
| + make_linked_ptr(s), false, base::Closure(),
|
| + FROM_HERE);
|
| wait_interval_->pending_configure_job.reset(new SyncSessionJob(job));
|
| } else {
|
| // We are not in configuration mode. So wait_interval's pending job
|
| @@ -1006,6 +1016,8 @@ SyncSession* SyncScheduler::CreateSyncSession(const SyncSourceInfo& source) {
|
| ModelSafeRoutingInfo routes;
|
| std::vector<ModelSafeWorker*> workers;
|
| session_context_->registrar()->GetModelSafeRoutingInfo(&routes);
|
| + VLOG(2) << "Creating sync session with routes "
|
| + << ModelSafeRoutingInfoToString(routes);
|
| session_context_->registrar()->GetWorkers(&workers);
|
| SyncSourceInfo info(source);
|
|
|
| @@ -1023,7 +1035,7 @@ void SyncScheduler::PollTimerCallback() {
|
| SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, types_with_payloads);
|
| SyncSession* s = CreateSyncSession(info);
|
| ScheduleSyncSessionJob(TimeDelta::FromSeconds(0), SyncSessionJob::POLL, s,
|
| - FROM_HERE);
|
| + base::Closure(), FROM_HERE);
|
| }
|
|
|
| void SyncScheduler::Unthrottle() {
|
|
|