| 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 |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 Intersection(ProtocolTypes(), enabled_types); | 274 Intersection(ProtocolTypes(), enabled_types); |
| 275 ModelTypeSet throttled_types = nudge_tracker_.GetThrottledTypes(); | 275 ModelTypeSet throttled_types = nudge_tracker_.GetThrottledTypes(); |
| 276 return Difference(enabled_protocol_types, throttled_types); | 276 return Difference(enabled_protocol_types, throttled_types); |
| 277 } | 277 } |
| 278 | 278 |
| 279 void SyncSchedulerImpl::SendInitialSnapshot() { | 279 void SyncSchedulerImpl::SendInitialSnapshot() { |
| 280 DCHECK(CalledOnValidThread()); | 280 DCHECK(CalledOnValidThread()); |
| 281 std::unique_ptr<SyncCycle> dummy(SyncCycle::Build(cycle_context_, this)); | 281 std::unique_ptr<SyncCycle> dummy(SyncCycle::Build(cycle_context_, this)); |
| 282 SyncCycleEvent event(SyncCycleEvent::STATUS_CHANGED); | 282 SyncCycleEvent event(SyncCycleEvent::STATUS_CHANGED); |
| 283 event.snapshot = dummy->TakeSnapshot(); | 283 event.snapshot = dummy->TakeSnapshot(); |
| 284 FOR_EACH_OBSERVER(SyncEngineEventListener, *cycle_context_->listeners(), | 284 for (auto& observer : *cycle_context_->listeners()) |
| 285 OnSyncCycleEvent(event)); | 285 observer.OnSyncCycleEvent(event); |
| 286 } | 286 } |
| 287 | 287 |
| 288 namespace { | 288 namespace { |
| 289 | 289 |
| 290 // Helper to extract the routing info corresponding to types in | 290 // Helper to extract the routing info corresponding to types in |
| 291 // |types_to_download| from |current_routes|. | 291 // |types_to_download| from |current_routes|. |
| 292 void BuildModelSafeParams(ModelTypeSet types_to_download, | 292 void BuildModelSafeParams(ModelTypeSet types_to_download, |
| 293 const ModelSafeRoutingInfo& current_routes, | 293 const ModelSafeRoutingInfo& current_routes, |
| 294 ModelSafeRoutingInfo* result_routes) { | 294 ModelSafeRoutingInfo* result_routes) { |
| 295 for (ModelTypeSet::Iterator iter = types_to_download.First(); iter.Good(); | 295 for (ModelTypeSet::Iterator iter = types_to_download.First(); iter.Good(); |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 // throttling, type throttling, network errors, transient errors) will also | 836 // throttling, type throttling, network errors, transient errors) will also |
| 837 // setup the appropriate retry logic (eg. retry after timeout, exponential | 837 // setup the appropriate retry logic (eg. retry after timeout, exponential |
| 838 // backoff, retry when the network changes). | 838 // backoff, retry when the network changes). |
| 839 } | 839 } |
| 840 | 840 |
| 841 void SyncSchedulerImpl::ExponentialBackoffRetry() { | 841 void SyncSchedulerImpl::ExponentialBackoffRetry() { |
| 842 TryCanaryJob(); | 842 TryCanaryJob(); |
| 843 } | 843 } |
| 844 | 844 |
| 845 void SyncSchedulerImpl::NotifyRetryTime(base::Time retry_time) { | 845 void SyncSchedulerImpl::NotifyRetryTime(base::Time retry_time) { |
| 846 FOR_EACH_OBSERVER(SyncEngineEventListener, *cycle_context_->listeners(), | 846 for (auto& observer : *cycle_context_->listeners()) |
| 847 OnRetryTimeChanged(retry_time)); | 847 observer.OnRetryTimeChanged(retry_time); |
| 848 } | 848 } |
| 849 | 849 |
| 850 void SyncSchedulerImpl::NotifyThrottledTypesChanged(ModelTypeSet types) { | 850 void SyncSchedulerImpl::NotifyThrottledTypesChanged(ModelTypeSet types) { |
| 851 FOR_EACH_OBSERVER(SyncEngineEventListener, *cycle_context_->listeners(), | 851 for (auto& observer : *cycle_context_->listeners()) |
| 852 OnThrottledTypesChanged(types)); | 852 observer.OnThrottledTypesChanged(types); |
| 853 } | 853 } |
| 854 | 854 |
| 855 bool SyncSchedulerImpl::IsBackingOff() const { | 855 bool SyncSchedulerImpl::IsBackingOff() const { |
| 856 DCHECK(CalledOnValidThread()); | 856 DCHECK(CalledOnValidThread()); |
| 857 return wait_interval_.get() && | 857 return wait_interval_.get() && |
| 858 wait_interval_->mode == WaitInterval::EXPONENTIAL_BACKOFF; | 858 wait_interval_->mode == WaitInterval::EXPONENTIAL_BACKOFF; |
| 859 } | 859 } |
| 860 | 860 |
| 861 void SyncSchedulerImpl::OnThrottled(const base::TimeDelta& throttle_duration) { | 861 void SyncSchedulerImpl::OnThrottled(const base::TimeDelta& throttle_duration) { |
| 862 DCHECK(CalledOnValidThread()); | 862 DCHECK(CalledOnValidThread()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 | 927 |
| 928 void SyncSchedulerImpl::OnSyncProtocolError( | 928 void SyncSchedulerImpl::OnSyncProtocolError( |
| 929 const SyncProtocolError& sync_protocol_error) { | 929 const SyncProtocolError& sync_protocol_error) { |
| 930 DCHECK(CalledOnValidThread()); | 930 DCHECK(CalledOnValidThread()); |
| 931 if (ShouldRequestEarlyExit(sync_protocol_error)) { | 931 if (ShouldRequestEarlyExit(sync_protocol_error)) { |
| 932 SDVLOG(2) << "Sync Scheduler requesting early exit."; | 932 SDVLOG(2) << "Sync Scheduler requesting early exit."; |
| 933 Stop(); | 933 Stop(); |
| 934 } | 934 } |
| 935 if (IsActionableError(sync_protocol_error)) { | 935 if (IsActionableError(sync_protocol_error)) { |
| 936 SDVLOG(2) << "OnActionableError"; | 936 SDVLOG(2) << "OnActionableError"; |
| 937 FOR_EACH_OBSERVER(SyncEngineEventListener, *cycle_context_->listeners(), | 937 for (auto& observer : *cycle_context_->listeners()) |
| 938 OnActionableError(sync_protocol_error)); | 938 observer.OnActionableError(sync_protocol_error); |
| 939 } | 939 } |
| 940 } | 940 } |
| 941 | 941 |
| 942 void SyncSchedulerImpl::OnReceivedGuRetryDelay(const base::TimeDelta& delay) { | 942 void SyncSchedulerImpl::OnReceivedGuRetryDelay(const base::TimeDelta& delay) { |
| 943 nudge_tracker_.SetNextRetryTime(TimeTicks::Now() + delay); | 943 nudge_tracker_.SetNextRetryTime(TimeTicks::Now() + delay); |
| 944 retry_timer_.Start(FROM_HERE, delay, this, | 944 retry_timer_.Start(FROM_HERE, delay, this, |
| 945 &SyncSchedulerImpl::RetryTimerCallback); | 945 &SyncSchedulerImpl::RetryTimerCallback); |
| 946 } | 946 } |
| 947 | 947 |
| 948 void SyncSchedulerImpl::OnReceivedMigrationRequest(ModelTypeSet types) { | 948 void SyncSchedulerImpl::OnReceivedMigrationRequest(ModelTypeSet types) { |
| 949 FOR_EACH_OBSERVER(SyncEngineEventListener, *cycle_context_->listeners(), | 949 for (auto& observer : *cycle_context_->listeners()) |
| 950 OnMigrationRequested(types)); | 950 observer.OnMigrationRequested(types); |
| 951 } | 951 } |
| 952 | 952 |
| 953 void SyncSchedulerImpl::SetNotificationsEnabled(bool notifications_enabled) { | 953 void SyncSchedulerImpl::SetNotificationsEnabled(bool notifications_enabled) { |
| 954 DCHECK(CalledOnValidThread()); | 954 DCHECK(CalledOnValidThread()); |
| 955 cycle_context_->set_notifications_enabled(notifications_enabled); | 955 cycle_context_->set_notifications_enabled(notifications_enabled); |
| 956 if (notifications_enabled) | 956 if (notifications_enabled) |
| 957 nudge_tracker_.OnInvalidationsEnabled(); | 957 nudge_tracker_.OnInvalidationsEnabled(); |
| 958 else | 958 else |
| 959 nudge_tracker_.OnInvalidationsDisabled(); | 959 nudge_tracker_.OnInvalidationsDisabled(); |
| 960 } | 960 } |
| 961 | 961 |
| 962 #undef SDVLOG_LOC | 962 #undef SDVLOG_LOC |
| 963 | 963 |
| 964 #undef SDVLOG | 964 #undef SDVLOG |
| 965 | 965 |
| 966 #undef SLOG | 966 #undef SLOG |
| 967 | 967 |
| 968 #undef ENUM_CASE | 968 #undef ENUM_CASE |
| 969 | 969 |
| 970 } // namespace syncer | 970 } // namespace syncer |
| OLD | NEW |