Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(568)

Side by Side Diff: sync/engine/sync_scheduler_impl.cc

Issue 152013003: Split up SyncEngineEventListener callbacks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: One more forward declaration Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/engine/sync_scheduler_impl.h ('k') | sync/engine/syncer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 247
248 ModelTypeSet SyncSchedulerImpl::GetEnabledAndUnthrottledTypes() { 248 ModelTypeSet SyncSchedulerImpl::GetEnabledAndUnthrottledTypes() {
249 ModelTypeSet enabled_types = session_context_->enabled_types(); 249 ModelTypeSet enabled_types = session_context_->enabled_types();
250 ModelTypeSet throttled_types = nudge_tracker_.GetThrottledTypes(); 250 ModelTypeSet throttled_types = nudge_tracker_.GetThrottledTypes();
251 return Difference(enabled_types, throttled_types); 251 return Difference(enabled_types, throttled_types);
252 } 252 }
253 253
254 void SyncSchedulerImpl::SendInitialSnapshot() { 254 void SyncSchedulerImpl::SendInitialSnapshot() {
255 DCHECK(CalledOnValidThread()); 255 DCHECK(CalledOnValidThread());
256 scoped_ptr<SyncSession> dummy(SyncSession::Build(session_context_, this)); 256 scoped_ptr<SyncSession> dummy(SyncSession::Build(session_context_, this));
257 SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED); 257 SyncCycleEvent event(SyncCycleEvent::STATUS_CHANGED);
258 event.snapshot = dummy->TakeSnapshot(); 258 event.snapshot = dummy->TakeSnapshot();
259 session_context_->NotifyListeners(event); 259 FOR_EACH_OBSERVER(SyncEngineEventListener,
260 *session_context_->listeners(),
261 OnSyncCycleEvent(event));
260 } 262 }
261 263
262 namespace { 264 namespace {
263 265
264 // Helper to extract the routing info corresponding to types in 266 // Helper to extract the routing info corresponding to types in
265 // |types_to_download| from |current_routes|. 267 // |types_to_download| from |current_routes|.
266 void BuildModelSafeParams( 268 void BuildModelSafeParams(
267 ModelTypeSet types_to_download, 269 ModelTypeSet types_to_download,
268 const ModelSafeRoutingInfo& current_routes, 270 const ModelSafeRoutingInfo& current_routes,
269 ModelSafeRoutingInfo* result_routes) { 271 ModelSafeRoutingInfo* result_routes) {
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 // first put us into a state that prevents successful sync cycles (eg. global 805 // first put us into a state that prevents successful sync cycles (eg. global
804 // throttling, type throttling, network errors, transient errors) will also 806 // throttling, type throttling, network errors, transient errors) will also
805 // setup the appropriate retry logic (eg. retry after timeout, exponential 807 // setup the appropriate retry logic (eg. retry after timeout, exponential
806 // backoff, retry when the network changes). 808 // backoff, retry when the network changes).
807 } 809 }
808 810
809 void SyncSchedulerImpl::ExponentialBackoffRetry() { 811 void SyncSchedulerImpl::ExponentialBackoffRetry() {
810 TryCanaryJob(); 812 TryCanaryJob();
811 } 813 }
812 814
813 void SyncSchedulerImpl::Notify(SyncEngineEvent::EventCause cause) {
814 DCHECK(CalledOnValidThread());
815 session_context_->NotifyListeners(SyncEngineEvent(cause));
816 }
817
818 void SyncSchedulerImpl::NotifyRetryTime(base::Time retry_time) { 815 void SyncSchedulerImpl::NotifyRetryTime(base::Time retry_time) {
819 SyncEngineEvent event(SyncEngineEvent::RETRY_TIME_CHANGED); 816 FOR_EACH_OBSERVER(SyncEngineEventListener,
820 event.retry_time = retry_time; 817 *session_context_->listeners(),
821 session_context_->NotifyListeners(event); 818 OnRetryTimeChanged(retry_time));
822 } 819 }
823 820
824 void SyncSchedulerImpl::NotifyThrottledTypesChanged(ModelTypeSet types) { 821 void SyncSchedulerImpl::NotifyThrottledTypesChanged(ModelTypeSet types) {
825 SyncEngineEvent event(SyncEngineEvent::THROTTLED_TYPES_CHANGED); 822 FOR_EACH_OBSERVER(SyncEngineEventListener,
826 event.throttled_types = types; 823 *session_context_->listeners(),
827 session_context_->NotifyListeners(event); 824 OnThrottledTypesChanged(types));
828 } 825 }
829 826
830 bool SyncSchedulerImpl::IsBackingOff() const { 827 bool SyncSchedulerImpl::IsBackingOff() const {
831 DCHECK(CalledOnValidThread()); 828 DCHECK(CalledOnValidThread());
832 return wait_interval_.get() && wait_interval_->mode == 829 return wait_interval_.get() && wait_interval_->mode ==
833 WaitInterval::EXPONENTIAL_BACKOFF; 830 WaitInterval::EXPONENTIAL_BACKOFF;
834 } 831 }
835 832
836 void SyncSchedulerImpl::OnThrottled(const base::TimeDelta& throttle_duration) { 833 void SyncSchedulerImpl::OnThrottled(const base::TimeDelta& throttle_duration) {
837 DCHECK(CalledOnValidThread()); 834 DCHECK(CalledOnValidThread());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 sessions_commit_delay_ = new_delay; 878 sessions_commit_delay_ = new_delay;
882 } 879 }
883 880
884 void SyncSchedulerImpl::OnReceivedClientInvalidationHintBufferSize(int size) { 881 void SyncSchedulerImpl::OnReceivedClientInvalidationHintBufferSize(int size) {
885 if (size > 0) 882 if (size > 0)
886 nudge_tracker_.SetHintBufferSize(size); 883 nudge_tracker_.SetHintBufferSize(size);
887 else 884 else
888 NOTREACHED() << "Hint buffer size should be > 0."; 885 NOTREACHED() << "Hint buffer size should be > 0.";
889 } 886 }
890 887
891 void SyncSchedulerImpl::OnActionableError( 888 void SyncSchedulerImpl::OnSyncProtocolError(
892 const sessions::SyncSessionSnapshot& snap) { 889 const SyncProtocolError& sync_protocol_error) {
893 DCHECK(CalledOnValidThread()); 890 DCHECK(CalledOnValidThread());
894 SDVLOG(2) << "OnActionableError"; 891 if (ShouldRequestEarlyExit(sync_protocol_error)) {
895 SyncEngineEvent event(SyncEngineEvent::ACTIONABLE_ERROR);
896 event.snapshot = snap;
897 session_context_->NotifyListeners(event);
898 }
899
900 void SyncSchedulerImpl::OnSyncProtocolError(
901 const sessions::SyncSessionSnapshot& snapshot) {
902 DCHECK(CalledOnValidThread());
903 if (ShouldRequestEarlyExit(
904 snapshot.model_neutral_state().sync_protocol_error)) {
905 SDVLOG(2) << "Sync Scheduler requesting early exit."; 892 SDVLOG(2) << "Sync Scheduler requesting early exit.";
906 Stop(); 893 Stop();
907 } 894 }
908 if (IsActionableError(snapshot.model_neutral_state().sync_protocol_error)) 895 if (IsActionableError(sync_protocol_error)) {
909 OnActionableError(snapshot); 896 SDVLOG(2) << "OnActionableError";
897 FOR_EACH_OBSERVER(SyncEngineEventListener,
898 *session_context_->listeners(),
899 OnActionableError(sync_protocol_error));
900 }
910 } 901 }
911 902
912 void SyncSchedulerImpl::OnReceivedGuRetryDelay(const base::TimeDelta& delay) { 903 void SyncSchedulerImpl::OnReceivedGuRetryDelay(const base::TimeDelta& delay) {
913 nudge_tracker_.SetNextRetryTime(TimeTicks::Now() + delay); 904 nudge_tracker_.SetNextRetryTime(TimeTicks::Now() + delay);
914 retry_timer_.Start(FROM_HERE, delay, this, 905 retry_timer_.Start(FROM_HERE, delay, this,
915 &SyncSchedulerImpl::RetryTimerCallback); 906 &SyncSchedulerImpl::RetryTimerCallback);
916 } 907 }
917 908
918 void SyncSchedulerImpl::SetNotificationsEnabled(bool notifications_enabled) { 909 void SyncSchedulerImpl::SetNotificationsEnabled(bool notifications_enabled) {
919 DCHECK(CalledOnValidThread()); 910 DCHECK(CalledOnValidThread());
(...skipping 11 matching lines...) Expand all
931 922
932 #undef SDVLOG_LOC 923 #undef SDVLOG_LOC
933 924
934 #undef SDVLOG 925 #undef SDVLOG
935 926
936 #undef SLOG 927 #undef SLOG
937 928
938 #undef ENUM_CASE 929 #undef ENUM_CASE
939 930
940 } // namespace syncer 931 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/sync_scheduler_impl.h ('k') | sync/engine/syncer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698