| 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 // execute in the new mode. | 252 // execute in the new mode. |
| 253 if (mode_ == NORMAL_MODE) { | 253 if (mode_ == NORMAL_MODE) { |
| 254 // It is illegal to switch to NORMAL_MODE if a previous CONFIGURATION job | 254 // It is illegal to switch to NORMAL_MODE if a previous CONFIGURATION job |
| 255 // has not yet completed. | 255 // has not yet completed. |
| 256 DCHECK(!wait_interval_.get() || !wait_interval_->pending_configure_job); | 256 DCHECK(!wait_interval_.get() || !wait_interval_->pending_configure_job); |
| 257 } | 257 } |
| 258 | 258 |
| 259 scoped_ptr<SyncSessionJob> pending(TakePendingJobForCurrentMode()); | 259 scoped_ptr<SyncSessionJob> pending(TakePendingJobForCurrentMode()); |
| 260 if (pending.get()) { | 260 if (pending.get()) { |
| 261 SDVLOG(2) << "Executing pending job. Good luck!"; | 261 SDVLOG(2) << "Executing pending job. Good luck!"; |
| 262 DoSyncSessionJob(pending.Pass()); | 262 DoSyncSessionJob(pending.Pass(), NORMAL_PRIORITY); |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 | 266 |
| 267 void SyncSchedulerImpl::SendInitialSnapshot() { | 267 void SyncSchedulerImpl::SendInitialSnapshot() { |
| 268 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 268 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 269 scoped_ptr<SyncSession> dummy(new SyncSession( | 269 scoped_ptr<SyncSession> dummy(new SyncSession( |
| 270 session_context_, this, SyncSourceInfo())); | 270 session_context_, this, SyncSourceInfo())); |
| 271 SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED); | 271 SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED); |
| 272 event.snapshot = dummy->TakeSnapshot(); | 272 event.snapshot = dummy->TakeSnapshot(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 SyncSourceInfo(params.source, | 321 SyncSourceInfo(params.source, |
| 322 ModelSafeRoutingInfoToInvalidationMap( | 322 ModelSafeRoutingInfoToInvalidationMap( |
| 323 restricted_routes, | 323 restricted_routes, |
| 324 std::string())))); | 324 std::string())))); |
| 325 scoped_ptr<SyncSessionJob> job(new SyncSessionJob( | 325 scoped_ptr<SyncSessionJob> job(new SyncSessionJob( |
| 326 SyncSessionJob::CONFIGURATION, | 326 SyncSessionJob::CONFIGURATION, |
| 327 TimeTicks::Now(), | 327 TimeTicks::Now(), |
| 328 session.Pass(), | 328 session.Pass(), |
| 329 params)); | 329 params)); |
| 330 job->set_destruction_observer(weak_ptr_factory_.GetWeakPtr()); | 330 job->set_destruction_observer(weak_ptr_factory_.GetWeakPtr()); |
| 331 bool succeeded = DoSyncSessionJob(job.Pass()); | 331 bool succeeded = DoSyncSessionJob(job.Pass(), NORMAL_PRIORITY); |
| 332 | 332 |
| 333 // If we failed, the job would have been saved as the pending configure | 333 // If we failed, the job would have been saved as the pending configure |
| 334 // job and a wait interval would have been set. | 334 // job and a wait interval would have been set. |
| 335 if (!succeeded) { | 335 if (!succeeded) { |
| 336 DCHECK(wait_interval_.get() && wait_interval_->pending_configure_job); | 336 DCHECK(wait_interval_.get() && wait_interval_->pending_configure_job); |
| 337 return false; | 337 return false; |
| 338 } | 338 } |
| 339 } else { | 339 } else { |
| 340 SDVLOG(2) << "No change in routing info, calling ready task directly."; | 340 SDVLOG(2) << "No change in routing info, calling ready task directly."; |
| 341 params.ready_task.Run(); | 341 params.ready_task.Run(); |
| 342 } | 342 } |
| 343 | 343 |
| 344 return true; | 344 return true; |
| 345 } | 345 } |
| 346 | 346 |
| 347 SyncSchedulerImpl::JobProcessDecision | 347 SyncSchedulerImpl::JobProcessDecision |
| 348 SyncSchedulerImpl::DecideWhileInWaitInterval(const SyncSessionJob& job) { | 348 SyncSchedulerImpl::DecideWhileInWaitInterval(const SyncSessionJob& job, |
| 349 JobPriority priority) { |
| 349 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 350 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 350 DCHECK(wait_interval_.get()); | 351 DCHECK(wait_interval_.get()); |
| 351 | 352 |
| 352 SDVLOG(2) << "DecideWhileInWaitInterval with WaitInterval mode " | 353 SDVLOG(2) << "DecideWhileInWaitInterval with WaitInterval mode " |
| 353 << WaitInterval::GetModeString(wait_interval_->mode) | 354 << WaitInterval::GetModeString(wait_interval_->mode) |
| 354 << (wait_interval_->had_nudge ? " (had nudge)" : "") | 355 << (wait_interval_->had_nudge ? " (had nudge)" : "") |
| 355 << (job.is_canary() ? " (canary)" : ""); | 356 << ((priority == CANARY_PRIORITY) ? " (canary)" : ""); |
| 356 | 357 |
| 357 if (job.purpose() == SyncSessionJob::POLL) | 358 if (job.purpose() == SyncSessionJob::POLL) |
| 358 return DROP; | 359 return DROP; |
| 359 | 360 |
| 360 // If we save a job while in a WaitInterval, there is a well-defined moment | 361 // If we save a job while in a WaitInterval, there is a well-defined moment |
| 361 // in time in the future when it makes sense for that SAVE-worthy job to try | 362 // in time in the future when it makes sense for that SAVE-worthy job to try |
| 362 // running again -- the end of the WaitInterval. | 363 // running again -- the end of the WaitInterval. |
| 363 DCHECK(job.purpose() == SyncSessionJob::NUDGE || | 364 DCHECK(job.purpose() == SyncSessionJob::NUDGE || |
| 364 job.purpose() == SyncSessionJob::CONFIGURATION); | 365 job.purpose() == SyncSessionJob::CONFIGURATION); |
| 365 | 366 |
| 366 // If throttled, there's a clock ticking to unthrottle. We want to get | 367 // If throttled, there's a clock ticking to unthrottle. We want to get |
| 367 // on the same train. | 368 // on the same train. |
| 368 if (wait_interval_->mode == WaitInterval::THROTTLED) | 369 if (wait_interval_->mode == WaitInterval::THROTTLED) |
| 369 return SAVE; | 370 return SAVE; |
| 370 | 371 |
| 371 DCHECK_EQ(wait_interval_->mode, WaitInterval::EXPONENTIAL_BACKOFF); | 372 DCHECK_EQ(wait_interval_->mode, WaitInterval::EXPONENTIAL_BACKOFF); |
| 372 if (job.purpose() == SyncSessionJob::NUDGE) { | 373 if (job.purpose() == SyncSessionJob::NUDGE) { |
| 373 if (mode_ == CONFIGURATION_MODE) | 374 if (mode_ == CONFIGURATION_MODE) |
| 374 return SAVE; | 375 return SAVE; |
| 375 | 376 |
| 376 // If we already had one nudge then just drop this nudge. We will retry | 377 // If we already had one nudge then just drop this nudge. We will retry |
| 377 // later when the timer runs out. | 378 // later when the timer runs out. |
| 378 if (!job.is_canary()) | 379 if (priority == NORMAL_PRIORITY) |
| 379 return wait_interval_->had_nudge ? DROP : CONTINUE; | 380 return wait_interval_->had_nudge ? DROP : CONTINUE; |
| 380 else // We are here because timer ran out. So retry. | 381 else // We are here because timer ran out. So retry. |
| 381 return CONTINUE; | 382 return CONTINUE; |
| 382 } | 383 } |
| 383 return job.is_canary() ? CONTINUE : SAVE; | 384 return (priority == CANARY_PRIORITY) ? CONTINUE : SAVE; |
| 384 } | 385 } |
| 385 | 386 |
| 386 SyncSchedulerImpl::JobProcessDecision SyncSchedulerImpl::DecideOnJob( | 387 SyncSchedulerImpl::JobProcessDecision SyncSchedulerImpl::DecideOnJob( |
| 387 const SyncSessionJob& job) { | 388 const SyncSessionJob& job, |
| 389 JobPriority priority) { |
| 388 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 390 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 389 | 391 |
| 390 // See if our type is throttled. | 392 // See if our type is throttled. |
| 391 ModelTypeSet throttled_types = | 393 ModelTypeSet throttled_types = |
| 392 session_context_->throttled_data_type_tracker()->GetThrottledTypes(); | 394 session_context_->throttled_data_type_tracker()->GetThrottledTypes(); |
| 393 if (job.purpose() == SyncSessionJob::NUDGE && | 395 if (job.purpose() == SyncSessionJob::NUDGE && |
| 394 job.session()->source().updates_source == GetUpdatesCallerInfo::LOCAL) { | 396 job.session()->source().updates_source == GetUpdatesCallerInfo::LOCAL) { |
| 395 ModelTypeSet requested_types; | 397 ModelTypeSet requested_types; |
| 396 for (ModelTypeInvalidationMap::const_iterator i = | 398 for (ModelTypeInvalidationMap::const_iterator i = |
| 397 job.session()->source().types.begin(); | 399 job.session()->source().types.begin(); |
| 398 i != job.session()->source().types.end(); | 400 i != job.session()->source().types.end(); |
| 399 ++i) { | 401 ++i) { |
| 400 requested_types.Put(i->first); | 402 requested_types.Put(i->first); |
| 401 } | 403 } |
| 402 | 404 |
| 403 // If all types are throttled, do not CONTINUE. Today, we don't treat | 405 // If all types are throttled, do not CONTINUE. Today, we don't treat |
| 404 // a per-datatype "unthrottle" event as something that should force a | 406 // a per-datatype "unthrottle" event as something that should force a |
| 405 // canary job. For this reason, there's no good time to reschedule this job | 407 // canary job. For this reason, there's no good time to reschedule this job |
| 406 // to run -- we'll lazily wait for an independent event to trigger a sync. | 408 // to run -- we'll lazily wait for an independent event to trigger a sync. |
| 407 // Note that there may already be such an event if we're in a WaitInterval, | 409 // Note that there may already be such an event if we're in a WaitInterval, |
| 408 // so we can retry it then. | 410 // so we can retry it then. |
| 409 if (!requested_types.Empty() && throttled_types.HasAll(requested_types)) | 411 if (!requested_types.Empty() && throttled_types.HasAll(requested_types)) |
| 410 return DROP; // TODO(tim): Don't drop. http://crbug.com/177659 | 412 return DROP; // TODO(tim): Don't drop. http://crbug.com/177659 |
| 411 } | 413 } |
| 412 | 414 |
| 413 if (wait_interval_.get()) | 415 if (wait_interval_.get()) |
| 414 return DecideWhileInWaitInterval(job); | 416 return DecideWhileInWaitInterval(job, priority); |
| 415 | 417 |
| 416 if (mode_ == CONFIGURATION_MODE) { | 418 if (mode_ == CONFIGURATION_MODE) { |
| 417 if (job.purpose() == SyncSessionJob::NUDGE) | 419 if (job.purpose() == SyncSessionJob::NUDGE) |
| 418 return SAVE; // Running requires a mode switch. | 420 return SAVE; // Running requires a mode switch. |
| 419 else if (job.purpose() == SyncSessionJob::CONFIGURATION) | 421 else if (job.purpose() == SyncSessionJob::CONFIGURATION) |
| 420 return CONTINUE; | 422 return CONTINUE; |
| 421 else | 423 else |
| 422 return DROP; | 424 return DROP; |
| 423 } | 425 } |
| 424 | 426 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 if (!session_context_->connection_manager()->HasInvalidAuthToken()) | 468 if (!session_context_->connection_manager()->HasInvalidAuthToken()) |
| 467 return CONTINUE; | 469 return CONTINUE; |
| 468 | 470 |
| 469 SDVLOG(2) << "No valid auth token. Using that to decide on job."; | 471 SDVLOG(2) << "No valid auth token. Using that to decide on job."; |
| 470 // Running the job would require updated auth, so we can't honour | 472 // Running the job would require updated auth, so we can't honour |
| 471 // job.scheduled_start(). | 473 // job.scheduled_start(). |
| 472 return job.purpose() == SyncSessionJob::NUDGE ? SAVE : DROP; | 474 return job.purpose() == SyncSessionJob::NUDGE ? SAVE : DROP; |
| 473 } | 475 } |
| 474 | 476 |
| 475 void SyncSchedulerImpl::HandleSaveJobDecision(scoped_ptr<SyncSessionJob> job) { | 477 void SyncSchedulerImpl::HandleSaveJobDecision(scoped_ptr<SyncSessionJob> job) { |
| 476 DCHECK_EQ(DecideOnJob(*job), SAVE); | |
| 477 const bool is_nudge = job->purpose() == SyncSessionJob::NUDGE; | 478 const bool is_nudge = job->purpose() == SyncSessionJob::NUDGE; |
| 478 if (is_nudge && pending_nudge_) { | 479 if (is_nudge && pending_nudge_) { |
| 479 SDVLOG(2) << "Coalescing a pending nudge"; | 480 SDVLOG(2) << "Coalescing a pending nudge"; |
| 480 // TODO(tim): This basically means we never use the more-careful coalescing | 481 // TODO(tim): This basically means we never use the more-careful coalescing |
| 481 // logic in ScheduleNudgeImpl that takes the min of the two nudge start | 482 // logic in ScheduleNudgeImpl that takes the min of the two nudge start |
| 482 // times, because we're calling this function first. Pull this out | 483 // times, because we're calling this function first. Pull this out |
| 483 // into a function to coalesce + set start times and reuse. | 484 // into a function to coalesce + set start times and reuse. |
| 484 pending_nudge_->mutable_session()->CoalesceSources( | 485 pending_nudge_->mutable_session()->CoalesceSources( |
| 485 job->session()->source()); | 486 job->session()->source()); |
| 486 return; | 487 return; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 | 593 |
| 593 SyncSourceInfo info(source, invalidation_map); | 594 SyncSourceInfo info(source, invalidation_map); |
| 594 UpdateNudgeTimeRecords(info); | 595 UpdateNudgeTimeRecords(info); |
| 595 | 596 |
| 596 scoped_ptr<SyncSessionJob> job(new SyncSessionJob( | 597 scoped_ptr<SyncSessionJob> job(new SyncSessionJob( |
| 597 SyncSessionJob::NUDGE, | 598 SyncSessionJob::NUDGE, |
| 598 TimeTicks::Now() + delay, | 599 TimeTicks::Now() + delay, |
| 599 CreateSyncSession(info).Pass(), | 600 CreateSyncSession(info).Pass(), |
| 600 ConfigurationParams())); | 601 ConfigurationParams())); |
| 601 job->set_destruction_observer(weak_ptr_factory_.GetWeakPtr()); | 602 job->set_destruction_observer(weak_ptr_factory_.GetWeakPtr()); |
| 602 JobProcessDecision decision = DecideOnJob(*job); | 603 JobProcessDecision decision = DecideOnJob(*job, NORMAL_PRIORITY); |
| 603 SDVLOG(2) << "Should run " | 604 SDVLOG(2) << "Should run " |
| 604 << SyncSessionJob::GetPurposeString(job->purpose()) | 605 << SyncSessionJob::GetPurposeString(job->purpose()) |
| 605 << " job " << job->session() | 606 << " job " << job->session() |
| 606 << " in mode " << GetModeString(mode_) | 607 << " in mode " << GetModeString(mode_) |
| 607 << ": " << GetDecisionString(decision); | 608 << ": " << GetDecisionString(decision); |
| 608 if (decision != CONTINUE) { | 609 if (decision != CONTINUE) { |
| 609 // End of the line, though we may save the job for later. | 610 // End of the line, though we may save the job for later. |
| 610 if (decision == SAVE) { | 611 if (decision == SAVE) { |
| 611 HandleSaveJobDecision(job.Pass()); | 612 HandleSaveJobDecision(job.Pass()); |
| 612 } else { | 613 } else { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 if (job->purpose() == SyncSessionJob::NUDGE) { | 708 if (job->purpose() == SyncSessionJob::NUDGE) { |
| 708 SDVLOG_LOC(loc, 2) << "Resetting pending_nudge to "; | 709 SDVLOG_LOC(loc, 2) << "Resetting pending_nudge to "; |
| 709 DCHECK(!pending_nudge_ || pending_nudge_->session() == | 710 DCHECK(!pending_nudge_ || pending_nudge_->session() == |
| 710 job->session()); | 711 job->session()); |
| 711 set_pending_nudge(job.get()); | 712 set_pending_nudge(job.get()); |
| 712 } | 713 } |
| 713 | 714 |
| 714 PostDelayedTask(loc, "DoSyncSessionJob", | 715 PostDelayedTask(loc, "DoSyncSessionJob", |
| 715 base::Bind(base::IgnoreResult(&SyncSchedulerImpl::DoSyncSessionJob), | 716 base::Bind(base::IgnoreResult(&SyncSchedulerImpl::DoSyncSessionJob), |
| 716 weak_ptr_factory_.GetWeakPtr(), | 717 weak_ptr_factory_.GetWeakPtr(), |
| 717 base::Passed(&job)), | 718 base::Passed(&job), |
| 719 NORMAL_PRIORITY), |
| 718 delay); | 720 delay); |
| 719 } | 721 } |
| 720 | 722 |
| 721 bool SyncSchedulerImpl::DoSyncSessionJob(scoped_ptr<SyncSessionJob> job) { | 723 bool SyncSchedulerImpl::DoSyncSessionJob(scoped_ptr<SyncSessionJob> job, |
| 724 JobPriority priority) { |
| 722 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 725 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 723 if (job->purpose() == SyncSessionJob::NUDGE) { | 726 if (job->purpose() == SyncSessionJob::NUDGE) { |
| 724 if (pending_nudge_ == NULL || | 727 if (pending_nudge_ == NULL || |
| 725 pending_nudge_->session() != job->session()) { | 728 pending_nudge_->session() != job->session()) { |
| 726 // |job| is abandoned. | 729 // |job| is abandoned. |
| 727 SDVLOG(2) << "Dropping a nudge in " | 730 SDVLOG(2) << "Dropping a nudge in " |
| 728 << "DoSyncSessionJob because another nudge was scheduled"; | 731 << "DoSyncSessionJob because another nudge was scheduled"; |
| 729 return false; | 732 return false; |
| 730 } | 733 } |
| 731 pending_nudge_ = NULL; | 734 pending_nudge_ = NULL; |
| 732 } | 735 } |
| 733 | 736 |
| 734 base::AutoReset<bool> protector(&no_scheduling_allowed_, true); | 737 base::AutoReset<bool> protector(&no_scheduling_allowed_, true); |
| 735 JobProcessDecision decision = DecideOnJob(*job); | 738 JobProcessDecision decision = DecideOnJob(*job, priority); |
| 736 SDVLOG(2) << "Should run " | 739 SDVLOG(2) << "Should run " |
| 737 << SyncSessionJob::GetPurposeString(job->purpose()) | 740 << SyncSessionJob::GetPurposeString(job->purpose()) |
| 738 << " job " << job->session() | 741 << " job " << job->session() |
| 739 << " in mode " << GetModeString(mode_) | 742 << " in mode " << GetModeString(mode_) |
| 740 << " with source " << job->session()->source().updates_source | 743 << " with source " << job->session()->source().updates_source |
| 741 << ": " << GetDecisionString(decision); | 744 << ": " << GetDecisionString(decision); |
| 742 if (decision != CONTINUE) { | 745 if (decision != CONTINUE) { |
| 743 if (decision == SAVE) { | 746 if (decision == SAVE) { |
| 744 HandleSaveJobDecision(job.Pass()); | 747 HandleSaveJobDecision(job.Pass()); |
| 745 } else { | 748 } else { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 wait_interval_->timer.Start(FROM_HERE, wait_interval_->length, | 910 wait_interval_->timer.Start(FROM_HERE, wait_interval_->length, |
| 908 base::Bind(&SyncSchedulerImpl::DoCanaryJob, | 911 base::Bind(&SyncSchedulerImpl::DoCanaryJob, |
| 909 weak_ptr_factory_.GetWeakPtr(), | 912 weak_ptr_factory_.GetWeakPtr(), |
| 910 base::Passed(&job))); | 913 base::Passed(&job))); |
| 911 } | 914 } |
| 912 } | 915 } |
| 913 | 916 |
| 914 void SyncSchedulerImpl::HandleContinuationError( | 917 void SyncSchedulerImpl::HandleContinuationError( |
| 915 scoped_ptr<SyncSessionJob> old_job) { | 918 scoped_ptr<SyncSessionJob> old_job) { |
| 916 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 919 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 917 if (DCHECK_IS_ON()) { | |
| 918 if (IsBackingOff()) { | |
| 919 DCHECK(wait_interval_->timer.IsRunning() || old_job->is_canary()); | |
| 920 } | |
| 921 } | |
| 922 | 920 |
| 923 TimeDelta length = delay_provider_->GetDelay( | 921 TimeDelta length = delay_provider_->GetDelay( |
| 924 IsBackingOff() ? wait_interval_->length : | 922 IsBackingOff() ? wait_interval_->length : |
| 925 delay_provider_->GetInitialDelay( | 923 delay_provider_->GetInitialDelay( |
| 926 old_job->session()->status_controller().model_neutral_state())); | 924 old_job->session()->status_controller().model_neutral_state())); |
| 927 | 925 |
| 928 SDVLOG(2) << "In handle continuation error with " | 926 SDVLOG(2) << "In handle continuation error with " |
| 929 << SyncSessionJob::GetPurposeString(old_job->purpose()) | 927 << SyncSessionJob::GetPurposeString(old_job->purpose()) |
| 930 << " job. The time delta(ms) is " | 928 << " job. The time delta(ms) is " |
| 931 << length.InMilliseconds(); | 929 << length.InMilliseconds(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 started_ = false; | 974 started_ = false; |
| 977 } | 975 } |
| 978 if (!callback.is_null()) | 976 if (!callback.is_null()) |
| 979 callback.Run(); | 977 callback.Run(); |
| 980 } | 978 } |
| 981 | 979 |
| 982 void SyncSchedulerImpl::DoCanaryJob(scoped_ptr<SyncSessionJob> to_be_canary) { | 980 void SyncSchedulerImpl::DoCanaryJob(scoped_ptr<SyncSessionJob> to_be_canary) { |
| 983 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 981 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 984 SDVLOG(2) << "Do canary job"; | 982 SDVLOG(2) << "Do canary job"; |
| 985 | 983 |
| 986 // Only set canary privileges here, when we are about to run the job. This | |
| 987 // avoids confusion in managing canary bits during scheduling, when you | |
| 988 // consider that mode switches (e.g., to config) can "pre-empt" a NUDGE that | |
| 989 // was scheduled as canary, and send it to an "unscheduled" state. | |
| 990 to_be_canary->GrantCanaryPrivilege(); | |
| 991 | |
| 992 if (to_be_canary->purpose() == SyncSessionJob::NUDGE) { | 984 if (to_be_canary->purpose() == SyncSessionJob::NUDGE) { |
| 993 // TODO(tim): Bug 158313. Remove this check. | 985 // TODO(tim): Bug 158313. Remove this check. |
| 994 if (pending_nudge_ == NULL || | 986 if (pending_nudge_ == NULL || |
| 995 pending_nudge_->session() != to_be_canary->session()) { | 987 pending_nudge_->session() != to_be_canary->session()) { |
| 996 // |job| is abandoned. | 988 // |job| is abandoned. |
| 997 SDVLOG(2) << "Dropping a nudge in " | 989 SDVLOG(2) << "Dropping a nudge in " |
| 998 << "DoSyncSessionJob because another nudge was scheduled"; | 990 << "DoSyncSessionJob because another nudge was scheduled"; |
| 999 return; | 991 return; |
| 1000 } | 992 } |
| 1001 DCHECK_EQ(pending_nudge_->session(), to_be_canary->session()); | 993 DCHECK_EQ(pending_nudge_->session(), to_be_canary->session()); |
| 1002 } | 994 } |
| 1003 DoSyncSessionJob(to_be_canary.Pass()); | 995 |
| 996 // This is the only place where we invoke DoSyncSessionJob with canary |
| 997 // privileges. Everyone else should use NORMAL_PRIORITY. |
| 998 DoSyncSessionJob(to_be_canary.Pass(), CANARY_PRIORITY); |
| 1004 } | 999 } |
| 1005 | 1000 |
| 1006 scoped_ptr<SyncSessionJob> SyncSchedulerImpl::TakePendingJobForCurrentMode() { | 1001 scoped_ptr<SyncSessionJob> SyncSchedulerImpl::TakePendingJobForCurrentMode() { |
| 1007 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1002 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1008 // If we find a scheduled pending_ job, abandon the old one and return a | 1003 // If we find a scheduled pending_ job, abandon the old one and return a |
| 1009 // a clone. If unscheduled, just hand over ownership. | 1004 // a clone. If unscheduled, just hand over ownership. |
| 1010 scoped_ptr<SyncSessionJob> candidate; | 1005 scoped_ptr<SyncSessionJob> candidate; |
| 1011 if (mode_ == CONFIGURATION_MODE && wait_interval_.get() | 1006 if (mode_ == CONFIGURATION_MODE && wait_interval_.get() |
| 1012 && wait_interval_->pending_configure_job) { | 1007 && wait_interval_->pending_configure_job) { |
| 1013 SDVLOG(2) << "Found pending configure job"; | 1008 SDVLOG(2) << "Found pending configure job"; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1164 | 1159 |
| 1165 #undef SDVLOG_LOC | 1160 #undef SDVLOG_LOC |
| 1166 | 1161 |
| 1167 #undef SDVLOG | 1162 #undef SDVLOG |
| 1168 | 1163 |
| 1169 #undef SLOG | 1164 #undef SLOG |
| 1170 | 1165 |
| 1171 #undef ENUM_CASE | 1166 #undef ENUM_CASE |
| 1172 | 1167 |
| 1173 } // namespace syncer | 1168 } // namespace syncer |
| OLD | NEW |