Chromium Code Reviews| 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/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 } | 234 } |
| 235 | 235 |
| 236 void SyncScheduler::StartImpl(Mode mode, ModeChangeCallback* callback) { | 236 void SyncScheduler::StartImpl(Mode mode, ModeChangeCallback* callback) { |
| 237 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 237 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 238 SVLOG(2) << "In StartImpl with mode " << GetModeString(mode); | 238 SVLOG(2) << "In StartImpl with mode " << GetModeString(mode); |
| 239 | 239 |
| 240 scoped_ptr<ModeChangeCallback> scoped_callback(callback); | 240 scoped_ptr<ModeChangeCallback> scoped_callback(callback); |
| 241 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 241 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 242 DCHECK(!session_context_->account_name().empty()); | 242 DCHECK(!session_context_->account_name().empty()); |
| 243 DCHECK(syncer_.get()); | 243 DCHECK(syncer_.get()); |
| 244 Mode old_mode = mode_; | |
| 244 mode_ = mode; | 245 mode_ = mode; |
| 245 AdjustPolling(NULL); // Will kick start poll timer if needed. | 246 AdjustPolling(NULL); // Will kick start poll timer if needed. |
| 246 if (scoped_callback.get()) | 247 if (scoped_callback.get()) |
| 247 scoped_callback->Run(); | 248 scoped_callback->Run(); |
| 248 | 249 |
| 249 // We just changed our mode. See if there are any pending jobs that we could | 250 if (old_mode != mode_) { |
| 250 // execute in the new mode. | 251 // We just changed our mode. See if there are any pending jobs that we could |
| 251 DoPendingJobIfPossible(false); | 252 // execute in the new mode. |
| 253 DoPendingJobIfPossible(false); | |
| 254 } | |
| 252 } | 255 } |
| 253 | 256 |
| 254 SyncScheduler::JobProcessDecision SyncScheduler::DecideWhileInWaitInterval( | 257 SyncScheduler::JobProcessDecision SyncScheduler::DecideWhileInWaitInterval( |
| 255 const SyncSessionJob& job) { | 258 const SyncSessionJob& job) { |
| 256 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 259 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 257 DCHECK(wait_interval_.get()); | 260 DCHECK(wait_interval_.get()); |
| 258 DCHECK_NE(job.purpose, SyncSessionJob::CLEAR_USER_DATA); | 261 DCHECK_NE(job.purpose, SyncSessionJob::CLEAR_USER_DATA); |
| 259 DCHECK_NE(job.purpose, SyncSessionJob::CLEANUP_DISABLED_TYPES); | 262 DCHECK_NE(job.purpose, SyncSessionJob::CLEANUP_DISABLED_TYPES); |
| 260 | 263 |
| 261 SVLOG(2) << "DecideWhileInWaitInterval with WaitInterval mode " | 264 SVLOG(2) << "DecideWhileInWaitInterval with WaitInterval mode " |
| 262 << WaitInterval::GetModeString(wait_interval_->mode) | 265 << WaitInterval::GetModeString(wait_interval_->mode) |
| 263 << (wait_interval_->had_nudge ? " (had nudge)" : "") | 266 << (wait_interval_->had_nudge ? " (had nudge)" : "") |
| 264 << (job.is_canary_job ? " (canary)" : ""); | 267 << (job.is_canary_job ? " (canary)" : ""); |
| 265 | 268 |
| 266 if (job.purpose == SyncSessionJob::POLL) | 269 if (job.purpose == SyncSessionJob::POLL) |
| 267 return DROP; | 270 return DROP; |
| 268 | 271 |
| 269 DCHECK(job.purpose == SyncSessionJob::NUDGE || | 272 DCHECK(job.purpose == SyncSessionJob::NUDGE || |
| 270 job.purpose == SyncSessionJob::CONFIGURATION); | 273 job.purpose == SyncSessionJob::CONFIGURATION); |
| 271 if (wait_interval_->mode == WaitInterval::THROTTLED) | 274 if (wait_interval_->mode == WaitInterval::THROTTLED) |
| 272 return SAVE; | 275 return SAVE; |
| 273 | 276 |
| 274 DCHECK_EQ(wait_interval_->mode, WaitInterval::EXPONENTIAL_BACKOFF); | 277 DCHECK_EQ(wait_interval_->mode, WaitInterval::EXPONENTIAL_BACKOFF); |
| 275 if (job.purpose == SyncSessionJob::NUDGE) { | 278 if (job.purpose == SyncSessionJob::NUDGE) { |
| 276 if (mode_ == CONFIGURATION_MODE) | 279 if (mode_ == CONFIGURATION_MODE) |
| 277 return SAVE; | 280 return SAVE; |
| 278 | 281 |
| 279 // If we already had one nudge then just drop this nudge. We will retry | 282 // If we already had one nudge then just drop this nudge. We will retry |
| 280 // later when the timer runs out. | 283 // later when the timer runs out. |
| 281 return wait_interval_->had_nudge ? DROP : CONTINUE; | 284 if (!job.is_canary_job) |
| 285 return wait_interval_->had_nudge ? DROP : CONTINUE; | |
| 286 else // We are here because timer ran out. So retry. | |
| 287 return CONTINUE; | |
|
tim (not reviewing)
2011/08/04 00:24:40
so we always continue with canary_jobs? don't we
lipalani1
2011/08/04 01:14:33
We call that when network connection changes. We s
| |
| 282 } | 288 } |
| 283 // This is a config job. | |
| 284 return job.is_canary_job ? CONTINUE : SAVE; | 289 return job.is_canary_job ? CONTINUE : SAVE; |
| 285 } | 290 } |
| 286 | 291 |
| 287 SyncScheduler::JobProcessDecision SyncScheduler::DecideOnJob( | 292 SyncScheduler::JobProcessDecision SyncScheduler::DecideOnJob( |
| 288 const SyncSessionJob& job) { | 293 const SyncSessionJob& job) { |
| 289 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 294 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 290 if (job.purpose == SyncSessionJob::CLEAR_USER_DATA || | 295 if (job.purpose == SyncSessionJob::CLEAR_USER_DATA || |
| 291 job.purpose == SyncSessionJob::CLEANUP_DISABLED_TYPES) | 296 job.purpose == SyncSessionJob::CLEANUP_DISABLED_TYPES) |
| 292 return CONTINUE; | 297 return CONTINUE; |
| 293 | 298 |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 // "one-off" job (i.e. purpose == | 803 // "one-off" job (i.e. purpose == |
| 799 // SyncSessionJob::{CLEAR_USER_DATA,CLEANUP_DISABLED_TYPES}), if | 804 // SyncSessionJob::{CLEAR_USER_DATA,CLEANUP_DISABLED_TYPES}), if |
| 800 // there was work_to_do before it ran this wont have changed, as | 805 // there was work_to_do before it ran this wont have changed, as |
| 801 // jobs like this don't run a full sync cycle. So we don't need | 806 // jobs like this don't run a full sync cycle. So we don't need |
| 802 // special code here. | 807 // special code here. |
| 803 wait_interval_.reset(); | 808 wait_interval_.reset(); |
| 804 SVLOG(2) << "Job succeeded so not scheduling more jobs"; | 809 SVLOG(2) << "Job succeeded so not scheduling more jobs"; |
| 805 return; | 810 return; |
| 806 } | 811 } |
| 807 | 812 |
| 808 if (old_job.session->source().updates_source == | 813 if (IsBackingOff() && wait_interval_->timer.IsRunning() && |
|
tim (not reviewing)
2011/08/04 00:24:40
comment
lipalani1
2011/08/04 01:14:33
Done.
| |
| 809 GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION) { | 814 mode_ == NORMAL_MODE) { |
| 810 SVLOG(2) << "Job failed with source continuation"; | |
| 811 // We don't seem to have made forward progress. Start or extend backoff. | |
| 812 HandleConsecutiveContinuationError(old_job); | |
| 813 } else if (IsBackingOff()) { | |
| 814 SVLOG(2) << "A nudge during backoff failed"; | 815 SVLOG(2) << "A nudge during backoff failed"; |
| 815 // We weren't continuing but we're in backoff; must have been a nudge. | 816 // We weren't continuing but we're in backoff; must have been a nudge. |
| 816 DCHECK_EQ(SyncSessionJob::NUDGE, old_job.purpose); | 817 DCHECK_EQ(SyncSessionJob::NUDGE, old_job.purpose); |
| 817 DCHECK(!wait_interval_->had_nudge); | 818 DCHECK(!wait_interval_->had_nudge); |
| 818 wait_interval_->had_nudge = true; | 819 wait_interval_->had_nudge = true; |
| 820 // Old job did not finish. So make it the pending job. | |
| 821 InitOrCoalescePendingJob(old_job); | |
| 819 // Resume waiting. | 822 // Resume waiting. |
| 820 RestartWaiting(); | 823 RestartWaiting(); |
| 824 } else if (old_job.session->source().updates_source == | |
| 825 GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION) { | |
| 826 SVLOG(2) << "Job failed with source continuation"; | |
| 827 // We don't seem to have made forward progress. Start or extend backoff. | |
| 828 HandleConsecutiveContinuationError(old_job); | |
| 821 } else { | 829 } else { |
| 822 SVLOG(2) << "Failed. Schedule a job with continuation as source"; | 830 SVLOG(2) << "Failed. Schedule a job with continuation as source"; |
| 823 // We weren't continuing and we aren't in backoff. Schedule a normal | 831 // We weren't continuing and we aren't in backoff. Schedule a normal |
| 824 // continuation. | 832 // continuation. |
| 825 if (old_job.purpose == SyncSessionJob::CONFIGURATION) { | 833 if (old_job.purpose == SyncSessionJob::CONFIGURATION) { |
| 826 ScheduleConfigImpl(old_job.session->routing_info(), | 834 ScheduleConfigImpl(old_job.session->routing_info(), |
| 827 old_job.session->workers(), | 835 old_job.session->workers(), |
| 828 GetUpdatesFromNudgeSource(NUDGE_SOURCE_CONTINUATION)); | 836 GetUpdatesFromNudgeSource(NUDGE_SOURCE_CONTINUATION)); |
| 829 } else { | 837 } else { |
| 830 // For all other purposes(nudge and poll) we schedule a retry nudge. | 838 // For all other purposes(nudge and poll) we schedule a retry nudge. |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1075 | 1083 |
| 1076 #undef SLOG | 1084 #undef SLOG |
| 1077 | 1085 |
| 1078 #undef VLOG_LOC | 1086 #undef VLOG_LOC |
| 1079 | 1087 |
| 1080 #undef VLOG_LOC_STREAM | 1088 #undef VLOG_LOC_STREAM |
| 1081 | 1089 |
| 1082 #undef ENUM_CASE | 1090 #undef ENUM_CASE |
| 1083 | 1091 |
| 1084 } // browser_sync | 1092 } // browser_sync |
| OLD | NEW |