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 "components/sync/engine_impl/sync_scheduler_impl.h" | 5 #include "components/sync/engine_impl/sync_scheduler_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/ptr_util.h" |
15 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
16 #include "base/threading/platform_thread.h" | 17 #include "base/threading/platform_thread.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
18 #include "components/sync/base/data_type_histogram.h" | 19 #include "components/sync/base/data_type_histogram.h" |
19 #include "components/sync/base/logging.h" | 20 #include "components/sync/base/logging.h" |
20 #include "components/sync/engine_impl/backoff_delay_provider.h" | 21 #include "components/sync/engine_impl/backoff_delay_provider.h" |
21 #include "components/sync/protocol/proto_enum_conversions.h" | 22 #include "components/sync/protocol/proto_enum_conversions.h" |
22 #include "components/sync/protocol/sync.pb.h" | 23 #include "components/sync/protocol/sync.pb.h" |
23 | 24 |
24 using base::TimeDelta; | 25 using base::TimeDelta; |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 // for a pending configure job. | 318 // for a pending configure job. |
318 DCHECK(!pending_configure_params_); | 319 DCHECK(!pending_configure_params_); |
319 | 320 |
320 ModelSafeRoutingInfo restricted_routes; | 321 ModelSafeRoutingInfo restricted_routes; |
321 BuildModelSafeParams(params.types_to_download, params.routing_info, | 322 BuildModelSafeParams(params.types_to_download, params.routing_info, |
322 &restricted_routes); | 323 &restricted_routes); |
323 cycle_context_->SetRoutingInfo(restricted_routes); | 324 cycle_context_->SetRoutingInfo(restricted_routes); |
324 | 325 |
325 // Only reconfigure if we have types to download. | 326 // Only reconfigure if we have types to download. |
326 if (!params.types_to_download.Empty()) { | 327 if (!params.types_to_download.Empty()) { |
327 pending_configure_params_.reset(new ConfigurationParams(params)); | 328 pending_configure_params_ = base::MakeUnique<ConfigurationParams>(params); |
328 TrySyncCycleJob(); | 329 TrySyncCycleJob(); |
329 } else { | 330 } else { |
330 SDVLOG(2) << "No change in routing info, calling ready task directly."; | 331 SDVLOG(2) << "No change in routing info, calling ready task directly."; |
331 params.ready_task.Run(); | 332 params.ready_task.Run(); |
332 } | 333 } |
333 } | 334 } |
334 | 335 |
335 void SyncSchedulerImpl::ScheduleClearServerData(const ClearParams& params) { | 336 void SyncSchedulerImpl::ScheduleClearServerData(const ClearParams& params) { |
336 DCHECK(CalledOnValidThread()); | 337 DCHECK(CalledOnValidThread()); |
337 DCHECK_EQ(CLEAR_SERVER_DATA_MODE, mode_); | 338 DCHECK_EQ(CLEAR_SERVER_DATA_MODE, mode_); |
338 DCHECK(!pending_configure_params_); | 339 DCHECK(!pending_configure_params_); |
339 DCHECK(!params.report_success_task.is_null()); | 340 DCHECK(!params.report_success_task.is_null()); |
340 CHECK(started_) << "Scheduler must be running to clear."; | 341 CHECK(started_) << "Scheduler must be running to clear."; |
341 pending_clear_params_.reset(new ClearParams(params)); | 342 pending_clear_params_ = base::MakeUnique<ClearParams>(params); |
342 TrySyncCycleJob(); | 343 TrySyncCycleJob(); |
343 } | 344 } |
344 | 345 |
345 bool SyncSchedulerImpl::CanRunJobNow(JobPriority priority) { | 346 bool SyncSchedulerImpl::CanRunJobNow(JobPriority priority) { |
346 DCHECK(CalledOnValidThread()); | 347 DCHECK(CalledOnValidThread()); |
347 if (IsCurrentlyThrottled()) { | 348 if (IsCurrentlyThrottled()) { |
348 SDVLOG(1) << "Unable to run a job because we're throttled."; | 349 SDVLOG(1) << "Unable to run a job because we're throttled."; |
349 return false; | 350 return false; |
350 } | 351 } |
351 | 352 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 } | 577 } |
577 | 578 |
578 void SyncSchedulerImpl::HandleFailure( | 579 void SyncSchedulerImpl::HandleFailure( |
579 const ModelNeutralState& model_neutral_state) { | 580 const ModelNeutralState& model_neutral_state) { |
580 if (IsCurrentlyThrottled()) { | 581 if (IsCurrentlyThrottled()) { |
581 SDVLOG(2) << "Was throttled during previous sync cycle."; | 582 SDVLOG(2) << "Was throttled during previous sync cycle."; |
582 } else if (!IsBackingOff()) { | 583 } else if (!IsBackingOff()) { |
583 // Setup our backoff if this is our first such failure. | 584 // Setup our backoff if this is our first such failure. |
584 TimeDelta length = delay_provider_->GetDelay( | 585 TimeDelta length = delay_provider_->GetDelay( |
585 delay_provider_->GetInitialDelay(model_neutral_state)); | 586 delay_provider_->GetInitialDelay(model_neutral_state)); |
586 wait_interval_.reset( | 587 wait_interval_ = base::MakeUnique<WaitInterval>( |
587 new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, length)); | 588 WaitInterval::EXPONENTIAL_BACKOFF, length); |
588 SDVLOG(2) << "Sync cycle failed. Will back off for " | 589 SDVLOG(2) << "Sync cycle failed. Will back off for " |
589 << wait_interval_->length.InMilliseconds() << "ms."; | 590 << wait_interval_->length.InMilliseconds() << "ms."; |
590 } else { | 591 } else { |
591 // Increase our backoff interval and schedule another retry. | 592 // Increase our backoff interval and schedule another retry. |
592 TimeDelta length = delay_provider_->GetDelay(wait_interval_->length); | 593 TimeDelta length = delay_provider_->GetDelay(wait_interval_->length); |
593 wait_interval_.reset( | 594 wait_interval_ = base::MakeUnique<WaitInterval>( |
594 new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, length)); | 595 WaitInterval::EXPONENTIAL_BACKOFF, length); |
595 SDVLOG(2) << "Sync cycle failed. Will back off for " | 596 SDVLOG(2) << "Sync cycle failed. Will back off for " |
596 << wait_interval_->length.InMilliseconds() << "ms."; | 597 << wait_interval_->length.InMilliseconds() << "ms."; |
597 } | 598 } |
598 RestartWaiting(); | 599 RestartWaiting(); |
599 } | 600 } |
600 | 601 |
601 void SyncSchedulerImpl::DoPollSyncCycleJob() { | 602 void SyncSchedulerImpl::DoPollSyncCycleJob() { |
602 SDVLOG(2) << "Polling with types " | 603 SDVLOG(2) << "Polling with types " |
603 << ModelTypeSetToString(GetEnabledAndUnthrottledTypes()); | 604 << ModelTypeSetToString(GetEnabledAndUnthrottledTypes()); |
604 std::unique_ptr<SyncCycle> cycle(SyncCycle::Build(cycle_context_, this)); | 605 std::unique_ptr<SyncCycle> cycle(SyncCycle::Build(cycle_context_, this)); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 // error states should trigger a canary job. | 763 // error states should trigger a canary job. |
763 DCHECK(IsCurrentlyThrottled() || IsBackingOff() || | 764 DCHECK(IsCurrentlyThrottled() || IsBackingOff() || |
764 cycle_context_->connection_manager()->HasInvalidAuthToken()); | 765 cycle_context_->connection_manager()->HasInvalidAuthToken()); |
765 } | 766 } |
766 | 767 |
767 if (IsBackingOff() && !pending_wakeup_timer_.IsRunning()) { | 768 if (IsBackingOff() && !pending_wakeup_timer_.IsRunning()) { |
768 // If we succeeded, our wait interval would have been cleared. If it hasn't | 769 // If we succeeded, our wait interval would have been cleared. If it hasn't |
769 // been cleared, then we should increase our backoff interval and schedule | 770 // been cleared, then we should increase our backoff interval and schedule |
770 // another retry. | 771 // another retry. |
771 TimeDelta length = delay_provider_->GetDelay(wait_interval_->length); | 772 TimeDelta length = delay_provider_->GetDelay(wait_interval_->length); |
772 wait_interval_.reset( | 773 wait_interval_ = base::MakeUnique<WaitInterval>( |
773 new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, length)); | 774 WaitInterval::EXPONENTIAL_BACKOFF, length); |
774 SDVLOG(2) << "Sync cycle failed. Will back off for " | 775 SDVLOG(2) << "Sync cycle failed. Will back off for " |
775 << wait_interval_->length.InMilliseconds() << "ms."; | 776 << wait_interval_->length.InMilliseconds() << "ms."; |
776 RestartWaiting(); | 777 RestartWaiting(); |
777 } | 778 } |
778 } | 779 } |
779 | 780 |
780 void SyncSchedulerImpl::PollTimerCallback() { | 781 void SyncSchedulerImpl::PollTimerCallback() { |
781 DCHECK(CalledOnValidThread()); | 782 DCHECK(CalledOnValidThread()); |
782 CHECK(!syncer_->IsSyncing()); | 783 CHECK(!syncer_->IsSyncing()); |
783 | 784 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 } | 854 } |
854 | 855 |
855 bool SyncSchedulerImpl::IsBackingOff() const { | 856 bool SyncSchedulerImpl::IsBackingOff() const { |
856 DCHECK(CalledOnValidThread()); | 857 DCHECK(CalledOnValidThread()); |
857 return wait_interval_.get() && | 858 return wait_interval_.get() && |
858 wait_interval_->mode == WaitInterval::EXPONENTIAL_BACKOFF; | 859 wait_interval_->mode == WaitInterval::EXPONENTIAL_BACKOFF; |
859 } | 860 } |
860 | 861 |
861 void SyncSchedulerImpl::OnThrottled(const base::TimeDelta& throttle_duration) { | 862 void SyncSchedulerImpl::OnThrottled(const base::TimeDelta& throttle_duration) { |
862 DCHECK(CalledOnValidThread()); | 863 DCHECK(CalledOnValidThread()); |
863 wait_interval_.reset( | 864 wait_interval_ = base::MakeUnique<WaitInterval>(WaitInterval::THROTTLED, |
864 new WaitInterval(WaitInterval::THROTTLED, throttle_duration)); | 865 throttle_duration); |
865 NotifyRetryTime(base::Time::Now() + wait_interval_->length); | 866 NotifyRetryTime(base::Time::Now() + wait_interval_->length); |
866 NotifyThrottledTypesChanged(ModelTypeSet::All()); | 867 NotifyThrottledTypesChanged(ModelTypeSet::All()); |
867 } | 868 } |
868 | 869 |
869 void SyncSchedulerImpl::OnTypesThrottled( | 870 void SyncSchedulerImpl::OnTypesThrottled( |
870 ModelTypeSet types, | 871 ModelTypeSet types, |
871 const base::TimeDelta& throttle_duration) { | 872 const base::TimeDelta& throttle_duration) { |
872 base::TimeTicks now = base::TimeTicks::Now(); | 873 base::TimeTicks now = base::TimeTicks::Now(); |
873 | 874 |
874 SDVLOG(1) << "Throttling " << ModelTypeSetToString(types) << " for " | 875 SDVLOG(1) << "Throttling " << ModelTypeSetToString(types) << " for " |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 | 962 |
962 #undef SDVLOG_LOC | 963 #undef SDVLOG_LOC |
963 | 964 |
964 #undef SDVLOG | 965 #undef SDVLOG |
965 | 966 |
966 #undef SLOG | 967 #undef SLOG |
967 | 968 |
968 #undef ENUM_CASE | 969 #undef ENUM_CASE |
969 | 970 |
970 } // namespace syncer | 971 } // namespace syncer |
OLD | NEW |