| Index: components/sync/engine_impl/sync_scheduler_impl.cc
|
| diff --git a/sync/engine/sync_scheduler_impl.cc b/components/sync/engine_impl/sync_scheduler_impl.cc
|
| similarity index 87%
|
| rename from sync/engine/sync_scheduler_impl.cc
|
| rename to components/sync/engine_impl/sync_scheduler_impl.cc
|
| index d0926fddb3c56dc45da0f082165c9c4acc608aa9..46909df77bd8d37859304af46c419c4cc52af831 100644
|
| --- a/sync/engine/sync_scheduler_impl.cc
|
| +++ b/components/sync/engine_impl/sync_scheduler_impl.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "sync/engine/sync_scheduler_impl.h"
|
| +#include "components/sync/engine_impl/sync_scheduler_impl.h"
|
|
|
| #include <algorithm>
|
| #include <cstring>
|
| @@ -16,12 +16,12 @@
|
| #include "base/single_thread_task_runner.h"
|
| #include "base/threading/platform_thread.h"
|
| #include "base/threading/thread_task_runner_handle.h"
|
| -#include "sync/engine/backoff_delay_provider.h"
|
| -#include "sync/engine/syncer.h"
|
| -#include "sync/protocol/proto_enum_conversions.h"
|
| -#include "sync/protocol/sync.pb.h"
|
| -#include "sync/util/data_type_histogram.h"
|
| -#include "sync/util/logging.h"
|
| +#include "components/sync/base/data_type_histogram.h"
|
| +#include "components/sync/base/logging.h"
|
| +#include "components/sync/engine_impl/backoff_delay_provider.h"
|
| +#include "components/sync/engine_impl/syncer.h"
|
| +#include "components/sync/protocol/proto_enum_conversions.h"
|
| +#include "components/sync/protocol/sync.pb.h"
|
|
|
| using base::TimeDelta;
|
| using base::TimeTicks;
|
| @@ -79,8 +79,7 @@ bool ShouldRequestEarlyExit(const SyncProtocolError& error) {
|
| return false;
|
| }
|
|
|
| -bool IsActionableError(
|
| - const SyncProtocolError& error) {
|
| +bool IsActionableError(const SyncProtocolError& error) {
|
| return (error.action != UNKNOWN_ACTION);
|
| }
|
|
|
| @@ -120,15 +119,17 @@ ClearParams::ClearParams(const base::Closure& report_success_task)
|
| ClearParams::ClearParams(const ClearParams& other) = default;
|
| ClearParams::~ClearParams() {}
|
|
|
| -SyncSchedulerImpl::WaitInterval::WaitInterval()
|
| - : mode(UNKNOWN) {}
|
| +SyncSchedulerImpl::WaitInterval::WaitInterval() : mode(UNKNOWN) {}
|
|
|
| SyncSchedulerImpl::WaitInterval::WaitInterval(Mode mode, TimeDelta length)
|
| : mode(mode), length(length) {}
|
|
|
| SyncSchedulerImpl::WaitInterval::~WaitInterval() {}
|
|
|
| -#define ENUM_CASE(x) case x: return #x; break;
|
| +#define ENUM_CASE(x) \
|
| + case x: \
|
| + return #x; \
|
| + break;
|
|
|
| const char* SyncSchedulerImpl::WaitInterval::GetModeString(Mode mode) {
|
| switch (mode) {
|
| @@ -164,7 +165,7 @@ GetUpdatesCallerInfo::GetUpdatesSource GetUpdatesFromNudgeSource(
|
|
|
| #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": "
|
|
|
| -#define SDVLOG_LOC(from_here, verbose_level) \
|
| +#define SDVLOG_LOC(from_here, verbose_level) \
|
| DVLOG_LOC(from_here, verbose_level) << name_ << ": "
|
|
|
| SyncSchedulerImpl::SyncSchedulerImpl(const std::string& name,
|
| @@ -184,8 +185,8 @@ SyncSchedulerImpl::SyncSchedulerImpl(const std::string& name,
|
| next_sync_session_job_priority_(NORMAL_PRIORITY),
|
| weak_ptr_factory_(this),
|
| weak_ptr_factory_for_weak_handle_(this) {
|
| - weak_handle_this_ = MakeWeakHandle(
|
| - weak_ptr_factory_for_weak_handle_.GetWeakPtr());
|
| + weak_handle_this_ =
|
| + MakeWeakHandle(weak_ptr_factory_for_weak_handle_.GetWeakPtr());
|
| }
|
|
|
| SyncSchedulerImpl::~SyncSchedulerImpl() {
|
| @@ -203,7 +204,7 @@ void SyncSchedulerImpl::OnCredentialsUpdated() {
|
| }
|
|
|
| void SyncSchedulerImpl::OnConnectionStatusChange() {
|
| - if (HttpResponse::CONNECTION_UNAVAILABLE ==
|
| + if (HttpResponse::CONNECTION_UNAVAILABLE ==
|
| session_context_->connection_manager()->server_status()) {
|
| // Optimistically assume that the connection is fixed and try
|
| // connecting.
|
| @@ -231,8 +232,8 @@ void SyncSchedulerImpl::Start(Mode mode, base::Time last_poll_time) {
|
| std::string thread_name = base::PlatformThread::GetName();
|
| if (thread_name.empty())
|
| thread_name = "<Main thread>";
|
| - SDVLOG(2) << "Start called from thread "
|
| - << thread_name << " with mode " << GetModeString(mode);
|
| + SDVLOG(2) << "Start called from thread " << thread_name << " with mode "
|
| + << GetModeString(mode);
|
| if (!started_) {
|
| started_ = true;
|
| SendInitialSnapshot();
|
| @@ -285,8 +286,7 @@ void SyncSchedulerImpl::SendInitialSnapshot() {
|
| SyncSession::Build(session_context_, this));
|
| SyncCycleEvent event(SyncCycleEvent::STATUS_CHANGED);
|
| event.snapshot = dummy->TakeSnapshot();
|
| - FOR_EACH_OBSERVER(SyncEngineEventListener,
|
| - *session_context_->listeners(),
|
| + FOR_EACH_OBSERVER(SyncEngineEventListener, *session_context_->listeners(),
|
| OnSyncCycleEvent(event));
|
| }
|
|
|
| @@ -294,10 +294,9 @@ namespace {
|
|
|
| // Helper to extract the routing info corresponding to types in
|
| // |types_to_download| from |current_routes|.
|
| -void BuildModelSafeParams(
|
| - ModelTypeSet types_to_download,
|
| - const ModelSafeRoutingInfo& current_routes,
|
| - ModelSafeRoutingInfo* result_routes) {
|
| +void BuildModelSafeParams(ModelTypeSet types_to_download,
|
| + const ModelSafeRoutingInfo& current_routes,
|
| + ModelSafeRoutingInfo* result_routes) {
|
| for (ModelTypeSet::Iterator iter = types_to_download.First(); iter.Good();
|
| iter.Inc()) {
|
| ModelType type = iter.Get();
|
| @@ -324,8 +323,7 @@ void SyncSchedulerImpl::ScheduleConfiguration(
|
| DCHECK(!pending_configure_params_);
|
|
|
| ModelSafeRoutingInfo restricted_routes;
|
| - BuildModelSafeParams(params.types_to_download,
|
| - params.routing_info,
|
| + BuildModelSafeParams(params.types_to_download, params.routing_info,
|
| &restricted_routes);
|
| session_context_->SetRoutingInfo(restricted_routes);
|
|
|
| @@ -397,9 +395,8 @@ void SyncSchedulerImpl::ScheduleLocalNudge(
|
| DCHECK(CalledOnValidThread());
|
| DCHECK(!types.Empty());
|
|
|
| - SDVLOG_LOC(nudge_location, 2)
|
| - << "Scheduling sync because of local change to "
|
| - << ModelTypeSetToString(types);
|
| + SDVLOG_LOC(nudge_location, 2) << "Scheduling sync because of local change to "
|
| + << ModelTypeSetToString(types);
|
| UpdateNudgeTimeRecords(types);
|
| base::TimeDelta nudge_delay = nudge_tracker_.RecordLocalChange(types);
|
| ScheduleNudgeImpl(nudge_delay, nudge_location);
|
| @@ -455,16 +452,15 @@ void SyncSchedulerImpl::ScheduleNudgeImpl(
|
| return;
|
| }
|
|
|
| - SDVLOG_LOC(nudge_location, 2)
|
| - << "In ScheduleNudgeImpl with delay "
|
| - << delay.InMilliseconds() << " ms";
|
| + SDVLOG_LOC(nudge_location, 2) << "In ScheduleNudgeImpl with delay "
|
| + << delay.InMilliseconds() << " ms";
|
|
|
| if (!CanRunNudgeJobNow(NORMAL_PRIORITY))
|
| return;
|
|
|
| TimeTicks incoming_run_time = TimeTicks::Now() + delay;
|
| if (!scheduled_nudge_time_.is_null() &&
|
| - (scheduled_nudge_time_ < incoming_run_time)) {
|
| + (scheduled_nudge_time_ < incoming_run_time)) {
|
| // Old job arrives sooner than this one. Don't reschedule it.
|
| return;
|
| }
|
| @@ -472,15 +468,12 @@ void SyncSchedulerImpl::ScheduleNudgeImpl(
|
| // Either there is no existing nudge in flight or the incoming nudge should be
|
| // made to arrive first (preempt) the existing nudge. We reschedule in either
|
| // case.
|
| - SDVLOG_LOC(nudge_location, 2)
|
| - << "Scheduling a nudge with "
|
| - << delay.InMilliseconds() << " ms delay";
|
| + SDVLOG_LOC(nudge_location, 2) << "Scheduling a nudge with "
|
| + << delay.InMilliseconds() << " ms delay";
|
| scheduled_nudge_time_ = incoming_run_time;
|
| pending_wakeup_timer_.Start(
|
| - nudge_location,
|
| - delay,
|
| - base::Bind(&SyncSchedulerImpl::PerformDelayedNudge,
|
| - weak_ptr_factory_.GetWeakPtr()));
|
| + nudge_location, delay, base::Bind(&SyncSchedulerImpl::PerformDelayedNudge,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| }
|
|
|
| const char* SyncSchedulerImpl::GetModeString(SyncScheduler::Mode mode) {
|
| @@ -505,8 +498,8 @@ void SyncSchedulerImpl::DoNudgeSyncSessionJob(JobPriority priority) {
|
| << ModelTypeSetToString(session_context_->GetEnabledTypes());
|
| std::unique_ptr<SyncSession> session(
|
| SyncSession::Build(session_context_, this));
|
| - bool success = syncer_->NormalSyncShare(
|
| - GetEnabledAndUnthrottledTypes(), &nudge_tracker_, session.get());
|
| + bool success = syncer_->NormalSyncShare(GetEnabledAndUnthrottledTypes(),
|
| + &nudge_tracker_, session.get());
|
|
|
| if (success) {
|
| // That cycle took care of any outstanding work we had.
|
| @@ -544,8 +537,7 @@ void SyncSchedulerImpl::DoConfigurationSyncSessionJob(JobPriority priority) {
|
| SyncSession::Build(session_context_, this));
|
| bool success = syncer_->ConfigureSyncShare(
|
| pending_configure_params_->types_to_download,
|
| - pending_configure_params_->source,
|
| - session.get());
|
| + pending_configure_params_->source, session.get());
|
|
|
| if (success) {
|
| SDVLOG(2) << "Configure succeeded.";
|
| @@ -602,14 +594,14 @@ void SyncSchedulerImpl::HandleFailure(
|
| wait_interval_.reset(
|
| new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, length));
|
| SDVLOG(2) << "Sync cycle failed. Will back off for "
|
| - << wait_interval_->length.InMilliseconds() << "ms.";
|
| + << wait_interval_->length.InMilliseconds() << "ms.";
|
| } else {
|
| // Increase our backoff interval and schedule another retry.
|
| TimeDelta length = delay_provider_->GetDelay(wait_interval_->length);
|
| wait_interval_.reset(
|
| new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, length));
|
| SDVLOG(2) << "Sync cycle failed. Will back off for "
|
| - << wait_interval_->length.InMilliseconds() << "ms.";
|
| + << wait_interval_->length.InMilliseconds() << "ms.";
|
| }
|
| RestartWaiting();
|
| }
|
| @@ -619,9 +611,8 @@ void SyncSchedulerImpl::DoPollSyncSessionJob() {
|
| << ModelTypeSetToString(GetEnabledAndUnthrottledTypes());
|
| std::unique_ptr<SyncSession> session(
|
| SyncSession::Build(session_context_, this));
|
| - bool success = syncer_->PollSyncShare(
|
| - GetEnabledAndUnthrottledTypes(),
|
| - session.get());
|
| + bool success =
|
| + syncer_->PollSyncShare(GetEnabledAndUnthrottledTypes(), session.get());
|
|
|
| // Only restart the timer if the poll succeeded. Otherwise rely on normal
|
| // failure handling to retry with backoff.
|
| @@ -644,7 +635,7 @@ void SyncSchedulerImpl::UpdateNudgeTimeRecords(ModelTypeSet types) {
|
| continue;
|
|
|
| #define PER_DATA_TYPE_MACRO(type_str) \
|
| - SYNC_FREQ_HISTOGRAM("Sync.Freq" type_str, now - previous);
|
| + SYNC_FREQ_HISTOGRAM("Sync.Freq" type_str, now - previous);
|
| SYNC_DATA_TYPE_HISTOGRAM(iter.Get());
|
| #undef PER_DATA_TYPE_MACRO
|
| }
|
| @@ -652,9 +643,9 @@ void SyncSchedulerImpl::UpdateNudgeTimeRecords(ModelTypeSet types) {
|
|
|
| TimeDelta SyncSchedulerImpl::GetPollInterval() {
|
| return (!session_context_->notifications_enabled() ||
|
| - !session_context_->ShouldFetchUpdatesBeforeCommit()) ?
|
| - syncer_short_poll_interval_seconds_ :
|
| - syncer_long_poll_interval_seconds_;
|
| + !session_context_->ShouldFetchUpdatesBeforeCommit())
|
| + ? syncer_short_poll_interval_seconds_
|
| + : syncer_long_poll_interval_seconds_;
|
| }
|
|
|
| void SyncSchedulerImpl::AdjustPolling(PollAdjustType type) {
|
| @@ -705,17 +696,14 @@ void SyncSchedulerImpl::RestartWaiting() {
|
| DCHECK(wait_interval_->length >= TimeDelta::FromSeconds(0));
|
| NotifyRetryTime(base::Time::Now() + wait_interval_->length);
|
| SDVLOG(2) << "Starting WaitInterval timer of length "
|
| - << wait_interval_->length.InMilliseconds() << "ms.";
|
| + << wait_interval_->length.InMilliseconds() << "ms.";
|
| if (wait_interval_->mode == WaitInterval::THROTTLED) {
|
| - pending_wakeup_timer_.Start(
|
| - FROM_HERE,
|
| - wait_interval_->length,
|
| - base::Bind(&SyncSchedulerImpl::Unthrottle,
|
| - weak_ptr_factory_.GetWeakPtr()));
|
| + pending_wakeup_timer_.Start(FROM_HERE, wait_interval_->length,
|
| + base::Bind(&SyncSchedulerImpl::Unthrottle,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| } else {
|
| pending_wakeup_timer_.Start(
|
| - FROM_HERE,
|
| - wait_interval_->length,
|
| + FROM_HERE, wait_interval_->length,
|
| base::Bind(&SyncSchedulerImpl::ExponentialBackoffRetry,
|
| weak_ptr_factory_.GetWeakPtr()));
|
| }
|
| @@ -793,7 +781,7 @@ void SyncSchedulerImpl::TrySyncSessionJobImpl() {
|
| wait_interval_.reset(
|
| new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, length));
|
| SDVLOG(2) << "Sync cycle failed. Will back off for "
|
| - << wait_interval_->length.InMilliseconds() << "ms.";
|
| + << wait_interval_->length.InMilliseconds() << "ms.";
|
| RestartWaiting();
|
| }
|
| }
|
| @@ -835,12 +823,10 @@ void SyncSchedulerImpl::TypeUnthrottle(base::TimeTicks unthrottle_time) {
|
| const base::TimeTicks now = base::TimeTicks::Now();
|
| base::TimeDelta time_until_next_unthrottle =
|
| nudge_tracker_.GetTimeUntilNextUnthrottle(now);
|
| - type_unthrottle_timer_.Start(
|
| - FROM_HERE,
|
| - time_until_next_unthrottle,
|
| - base::Bind(&SyncSchedulerImpl::TypeUnthrottle,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - now + time_until_next_unthrottle));
|
| + type_unthrottle_timer_.Start(FROM_HERE, time_until_next_unthrottle,
|
| + base::Bind(&SyncSchedulerImpl::TypeUnthrottle,
|
| + weak_ptr_factory_.GetWeakPtr(),
|
| + now + time_until_next_unthrottle));
|
| }
|
|
|
| // Maybe this is a good time to run a nudge job. Let's try it.
|
| @@ -866,27 +852,25 @@ void SyncSchedulerImpl::ExponentialBackoffRetry() {
|
| }
|
|
|
| void SyncSchedulerImpl::NotifyRetryTime(base::Time retry_time) {
|
| - FOR_EACH_OBSERVER(SyncEngineEventListener,
|
| - *session_context_->listeners(),
|
| + FOR_EACH_OBSERVER(SyncEngineEventListener, *session_context_->listeners(),
|
| OnRetryTimeChanged(retry_time));
|
| }
|
|
|
| void SyncSchedulerImpl::NotifyThrottledTypesChanged(ModelTypeSet types) {
|
| - FOR_EACH_OBSERVER(SyncEngineEventListener,
|
| - *session_context_->listeners(),
|
| + FOR_EACH_OBSERVER(SyncEngineEventListener, *session_context_->listeners(),
|
| OnThrottledTypesChanged(types));
|
| }
|
|
|
| bool SyncSchedulerImpl::IsBackingOff() const {
|
| DCHECK(CalledOnValidThread());
|
| - return wait_interval_.get() && wait_interval_->mode ==
|
| - WaitInterval::EXPONENTIAL_BACKOFF;
|
| + return wait_interval_.get() &&
|
| + wait_interval_->mode == WaitInterval::EXPONENTIAL_BACKOFF;
|
| }
|
|
|
| void SyncSchedulerImpl::OnThrottled(const base::TimeDelta& throttle_duration) {
|
| DCHECK(CalledOnValidThread());
|
| - wait_interval_.reset(new WaitInterval(WaitInterval::THROTTLED,
|
| - throttle_duration));
|
| + wait_interval_.reset(
|
| + new WaitInterval(WaitInterval::THROTTLED, throttle_duration));
|
| NotifyRetryTime(base::Time::Now() + wait_interval_->length);
|
| NotifyThrottledTypesChanged(ModelTypeSet::All());
|
| }
|
| @@ -902,19 +886,17 @@ void SyncSchedulerImpl::OnTypesThrottled(
|
| nudge_tracker_.SetTypesThrottledUntil(types, throttle_duration, now);
|
| base::TimeDelta time_until_next_unthrottle =
|
| nudge_tracker_.GetTimeUntilNextUnthrottle(now);
|
| - type_unthrottle_timer_.Start(
|
| - FROM_HERE,
|
| - time_until_next_unthrottle,
|
| - base::Bind(&SyncSchedulerImpl::TypeUnthrottle,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - now + time_until_next_unthrottle));
|
| + type_unthrottle_timer_.Start(FROM_HERE, time_until_next_unthrottle,
|
| + base::Bind(&SyncSchedulerImpl::TypeUnthrottle,
|
| + weak_ptr_factory_.GetWeakPtr(),
|
| + now + time_until_next_unthrottle));
|
| NotifyThrottledTypesChanged(nudge_tracker_.GetThrottledTypes());
|
| }
|
|
|
| bool SyncSchedulerImpl::IsCurrentlyThrottled() {
|
| DCHECK(CalledOnValidThread());
|
| - return wait_interval_.get() && wait_interval_->mode ==
|
| - WaitInterval::THROTTLED;
|
| + return wait_interval_.get() &&
|
| + wait_interval_->mode == WaitInterval::THROTTLED;
|
| }
|
|
|
| void SyncSchedulerImpl::OnReceivedShortPollIntervalUpdate(
|
| @@ -961,8 +943,7 @@ void SyncSchedulerImpl::OnSyncProtocolError(
|
| }
|
| if (IsActionableError(sync_protocol_error)) {
|
| SDVLOG(2) << "OnActionableError";
|
| - FOR_EACH_OBSERVER(SyncEngineEventListener,
|
| - *session_context_->listeners(),
|
| + FOR_EACH_OBSERVER(SyncEngineEventListener, *session_context_->listeners(),
|
| OnActionableError(sync_protocol_error));
|
| }
|
| }
|
| @@ -974,9 +955,8 @@ void SyncSchedulerImpl::OnReceivedGuRetryDelay(const base::TimeDelta& delay) {
|
| }
|
|
|
| void SyncSchedulerImpl::OnReceivedMigrationRequest(ModelTypeSet types) {
|
| - FOR_EACH_OBSERVER(SyncEngineEventListener,
|
| - *session_context_->listeners(),
|
| - OnMigrationRequested(types));
|
| + FOR_EACH_OBSERVER(SyncEngineEventListener, *session_context_->listeners(),
|
| + OnMigrationRequested(types));
|
| }
|
|
|
| void SyncSchedulerImpl::SetNotificationsEnabled(bool notifications_enabled) {
|
|
|