| 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; |
| 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 // We are in backoff mode and our time did not run out. That means we had |
| 809 GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION) { | 814 // a local change, notification from server or a network connection change |
| 810 SVLOG(2) << "Job failed with source continuation"; | 815 // notification. In any case set had_nudge = true so we dont retry next |
| 811 // We don't seem to have made forward progress. Start or extend backoff. | 816 // nudge. Note: we will keep retrying network connection changes though as |
| 812 HandleConsecutiveContinuationError(old_job); | 817 // they are treated as canary jobs. Also we check the mode here because |
| 813 } else if (IsBackingOff()) { | 818 // we want to do this only in normal mode. For config mode jobs we dont |
| 819 // have anything similar to had_nudge. |
| 820 if (IsBackingOff() && wait_interval_->timer.IsRunning() && |
| 821 mode_ == NORMAL_MODE) { |
| 814 SVLOG(2) << "A nudge during backoff failed"; | 822 SVLOG(2) << "A nudge during backoff failed"; |
| 815 // We weren't continuing but we're in backoff; must have been a nudge. | 823 // We weren't continuing but we're in backoff; must have been a nudge. |
| 816 DCHECK_EQ(SyncSessionJob::NUDGE, old_job.purpose); | 824 DCHECK_EQ(SyncSessionJob::NUDGE, old_job.purpose); |
| 817 DCHECK(!wait_interval_->had_nudge); | 825 DCHECK(!wait_interval_->had_nudge); |
| 818 wait_interval_->had_nudge = true; | 826 wait_interval_->had_nudge = true; |
| 827 // Old job did not finish. So make it the pending job. |
| 828 InitOrCoalescePendingJob(old_job); |
| 819 // Resume waiting. | 829 // Resume waiting. |
| 820 RestartWaiting(); | 830 RestartWaiting(); |
| 831 } else if (old_job.session->source().updates_source == |
| 832 GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION) { |
| 833 SVLOG(2) << "Job failed with source continuation"; |
| 834 // We don't seem to have made forward progress. Start or extend backoff. |
| 835 HandleConsecutiveContinuationError(old_job); |
| 821 } else { | 836 } else { |
| 822 SVLOG(2) << "Failed. Schedule a job with continuation as source"; | 837 SVLOG(2) << "Failed. Schedule a job with continuation as source"; |
| 823 // We weren't continuing and we aren't in backoff. Schedule a normal | 838 // We weren't continuing and we aren't in backoff. Schedule a normal |
| 824 // continuation. | 839 // continuation. |
| 825 if (old_job.purpose == SyncSessionJob::CONFIGURATION) { | 840 if (old_job.purpose == SyncSessionJob::CONFIGURATION) { |
| 826 ScheduleConfigImpl(old_job.session->routing_info(), | 841 ScheduleConfigImpl(old_job.session->routing_info(), |
| 827 old_job.session->workers(), | 842 old_job.session->workers(), |
| 828 GetUpdatesFromNudgeSource(NUDGE_SOURCE_CONTINUATION)); | 843 GetUpdatesFromNudgeSource(NUDGE_SOURCE_CONTINUATION)); |
| 829 } else { | 844 } else { |
| 830 // For all other purposes(nudge and poll) we schedule a retry nudge. | 845 // 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 | 1090 |
| 1076 #undef SLOG | 1091 #undef SLOG |
| 1077 | 1092 |
| 1078 #undef VLOG_LOC | 1093 #undef VLOG_LOC |
| 1079 | 1094 |
| 1080 #undef VLOG_LOC_STREAM | 1095 #undef VLOG_LOC_STREAM |
| 1081 | 1096 |
| 1082 #undef ENUM_CASE | 1097 #undef ENUM_CASE |
| 1083 | 1098 |
| 1084 } // browser_sync | 1099 } // browser_sync |
| OLD | NEW |