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

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

Issue 488843002: [Sync] Add support for server controlled nudge delays (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 6 years, 4 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
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 14 matching lines...) Expand all
25 using base::TimeTicks; 25 using base::TimeTicks;
26 26
27 namespace syncer { 27 namespace syncer {
28 28
29 using sessions::SyncSession; 29 using sessions::SyncSession;
30 using sessions::SyncSessionSnapshot; 30 using sessions::SyncSessionSnapshot;
31 using sync_pb::GetUpdatesCallerInfo; 31 using sync_pb::GetUpdatesCallerInfo;
32 32
33 namespace { 33 namespace {
34 34
35 bool IsConfigRelatedUpdateSourceValue(
36 GetUpdatesCallerInfo::GetUpdatesSource source) {
37 switch (source) {
38 case GetUpdatesCallerInfo::RECONFIGURATION:
39 case GetUpdatesCallerInfo::MIGRATION:
40 case GetUpdatesCallerInfo::NEW_CLIENT:
41 case GetUpdatesCallerInfo::NEWLY_SUPPORTED_DATATYPE:
42 return true;
43 default:
44 return false;
45 }
46 }
47
35 bool ShouldRequestEarlyExit(const SyncProtocolError& error) { 48 bool ShouldRequestEarlyExit(const SyncProtocolError& error) {
36 switch (error.error_type) { 49 switch (error.error_type) {
37 case SYNC_SUCCESS: 50 case SYNC_SUCCESS:
38 case MIGRATION_DONE: 51 case MIGRATION_DONE:
39 case THROTTLED: 52 case THROTTLED:
40 case TRANSIENT_ERROR: 53 case TRANSIENT_ERROR:
41 return false; 54 return false;
42 case NOT_MY_BIRTHDAY: 55 case NOT_MY_BIRTHDAY:
43 case CLEAR_PENDING: 56 case CLEAR_PENDING:
44 case DISABLED_BY_ADMIN: 57 case DISABLED_BY_ADMIN:
(...skipping 13 matching lines...) Expand all
58 default: 71 default:
59 NOTREACHED(); 72 NOTREACHED();
60 return false; 73 return false;
61 } 74 }
62 } 75 }
63 76
64 bool IsActionableError( 77 bool IsActionableError(
65 const SyncProtocolError& error) { 78 const SyncProtocolError& error) {
66 return (error.action != UNKNOWN_ACTION); 79 return (error.action != UNKNOWN_ACTION);
67 } 80 }
81
68 } // namespace 82 } // namespace
69 83
70 ConfigurationParams::ConfigurationParams() 84 ConfigurationParams::ConfigurationParams()
71 : source(GetUpdatesCallerInfo::UNKNOWN) {} 85 : source(GetUpdatesCallerInfo::UNKNOWN) {}
72 ConfigurationParams::ConfigurationParams( 86 ConfigurationParams::ConfigurationParams(
73 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& source, 87 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& source,
74 ModelTypeSet types_to_download, 88 ModelTypeSet types_to_download,
75 const ModelSafeRoutingInfo& routing_info, 89 const ModelSafeRoutingInfo& routing_info,
76 const base::Closure& ready_task, 90 const base::Closure& ready_task,
77 const base::Closure& retry_task) 91 const base::Closure& retry_task)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 // Helper macros to log with the syncer thread name; useful when there 139 // Helper macros to log with the syncer thread name; useful when there
126 // are multiple syncer threads involved. 140 // are multiple syncer threads involved.
127 141
128 #define SLOG(severity) LOG(severity) << name_ << ": " 142 #define SLOG(severity) LOG(severity) << name_ << ": "
129 143
130 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " 144 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": "
131 145
132 #define SDVLOG_LOC(from_here, verbose_level) \ 146 #define SDVLOG_LOC(from_here, verbose_level) \
133 DVLOG_LOC(from_here, verbose_level) << name_ << ": " 147 DVLOG_LOC(from_here, verbose_level) << name_ << ": "
134 148
135 namespace {
136
137 const int kDefaultSessionsCommitDelaySeconds = 10;
138
139 bool IsConfigRelatedUpdateSourceValue(
140 GetUpdatesCallerInfo::GetUpdatesSource source) {
141 switch (source) {
142 case GetUpdatesCallerInfo::RECONFIGURATION:
143 case GetUpdatesCallerInfo::MIGRATION:
144 case GetUpdatesCallerInfo::NEW_CLIENT:
145 case GetUpdatesCallerInfo::NEWLY_SUPPORTED_DATATYPE:
146 return true;
147 default:
148 return false;
149 }
150 }
151
152 } // namespace
153
154 SyncSchedulerImpl::SyncSchedulerImpl(const std::string& name, 149 SyncSchedulerImpl::SyncSchedulerImpl(const std::string& name,
155 BackoffDelayProvider* delay_provider, 150 BackoffDelayProvider* delay_provider,
156 sessions::SyncSessionContext* context, 151 sessions::SyncSessionContext* context,
157 Syncer* syncer) 152 Syncer* syncer)
158 : name_(name), 153 : name_(name),
159 started_(false), 154 started_(false),
160 syncer_short_poll_interval_seconds_( 155 syncer_short_poll_interval_seconds_(
161 TimeDelta::FromSeconds(kDefaultShortPollIntervalSeconds)), 156 TimeDelta::FromSeconds(kDefaultShortPollIntervalSeconds)),
162 syncer_long_poll_interval_seconds_( 157 syncer_long_poll_interval_seconds_(
163 TimeDelta::FromSeconds(kDefaultLongPollIntervalSeconds)), 158 TimeDelta::FromSeconds(kDefaultLongPollIntervalSeconds)),
164 sessions_commit_delay_(
165 TimeDelta::FromSeconds(kDefaultSessionsCommitDelaySeconds)),
166 mode_(NORMAL_MODE), 159 mode_(NORMAL_MODE),
167 delay_provider_(delay_provider), 160 delay_provider_(delay_provider),
168 syncer_(syncer), 161 syncer_(syncer),
169 session_context_(context), 162 session_context_(context),
170 no_scheduling_allowed_(false), 163 no_scheduling_allowed_(false),
171 do_poll_after_credentials_updated_(false), 164 do_poll_after_credentials_updated_(false),
172 next_sync_session_job_priority_(NORMAL_PRIORITY), 165 next_sync_session_job_priority_(NORMAL_PRIORITY),
173 weak_ptr_factory_(this), 166 weak_ptr_factory_(this),
174 weak_ptr_factory_for_weak_handle_(this) { 167 weak_ptr_factory_for_weak_handle_(this) {
175 weak_handle_this_ = MakeWeakHandle( 168 weak_handle_this_ = MakeWeakHandle(
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 342
350 if (mode_ == CONFIGURATION_MODE) { 343 if (mode_ == CONFIGURATION_MODE) {
351 SDVLOG(1) << "Not running nudge because we're in configuration mode."; 344 SDVLOG(1) << "Not running nudge because we're in configuration mode.";
352 return false; 345 return false;
353 } 346 }
354 347
355 return true; 348 return true;
356 } 349 }
357 350
358 void SyncSchedulerImpl::ScheduleLocalNudge( 351 void SyncSchedulerImpl::ScheduleLocalNudge(
359 const TimeDelta& desired_delay,
360 ModelTypeSet types, 352 ModelTypeSet types,
361 const tracked_objects::Location& nudge_location) { 353 const tracked_objects::Location& nudge_location) {
362 DCHECK(CalledOnValidThread()); 354 DCHECK(CalledOnValidThread());
363 DCHECK(!types.Empty()); 355 DCHECK(!types.Empty());
364 356
365 SDVLOG_LOC(nudge_location, 2) 357 SDVLOG_LOC(nudge_location, 2)
366 << "Scheduling sync because of local change to " 358 << "Scheduling sync because of local change to "
367 << ModelTypeSetToString(types); 359 << ModelTypeSetToString(types);
368 UpdateNudgeTimeRecords(types); 360 UpdateNudgeTimeRecords(types);
369 nudge_tracker_.RecordLocalChange(types); 361 base::TimeDelta nudge_delay = nudge_tracker_.RecordLocalChange(types);
370 ScheduleNudgeImpl(desired_delay, nudge_location); 362 ScheduleNudgeImpl(nudge_delay, nudge_location);
371 } 363 }
372 364
373 void SyncSchedulerImpl::ScheduleLocalRefreshRequest( 365 void SyncSchedulerImpl::ScheduleLocalRefreshRequest(
374 const TimeDelta& desired_delay,
375 ModelTypeSet types, 366 ModelTypeSet types,
376 const tracked_objects::Location& nudge_location) { 367 const tracked_objects::Location& nudge_location) {
377 DCHECK(CalledOnValidThread()); 368 DCHECK(CalledOnValidThread());
378 DCHECK(!types.Empty()); 369 DCHECK(!types.Empty());
379 370
380 SDVLOG_LOC(nudge_location, 2) 371 SDVLOG_LOC(nudge_location, 2)
381 << "Scheduling sync because of local refresh request for " 372 << "Scheduling sync because of local refresh request for "
382 << ModelTypeSetToString(types); 373 << ModelTypeSetToString(types);
383 nudge_tracker_.RecordLocalRefreshRequest(types); 374 base::TimeDelta nudge_delay = nudge_tracker_.RecordLocalRefreshRequest(types);
384 ScheduleNudgeImpl(desired_delay, nudge_location); 375 ScheduleNudgeImpl(nudge_delay, nudge_location);
385 } 376 }
386 377
387 void SyncSchedulerImpl::ScheduleInvalidationNudge( 378 void SyncSchedulerImpl::ScheduleInvalidationNudge(
388 const TimeDelta& desired_delay,
389 syncer::ModelType model_type, 379 syncer::ModelType model_type,
390 scoped_ptr<InvalidationInterface> invalidation, 380 scoped_ptr<InvalidationInterface> invalidation,
391 const tracked_objects::Location& nudge_location) { 381 const tracked_objects::Location& nudge_location) {
392 DCHECK(CalledOnValidThread()); 382 DCHECK(CalledOnValidThread());
393 383
394 SDVLOG_LOC(nudge_location, 2) 384 SDVLOG_LOC(nudge_location, 2)
395 << "Scheduling sync because we received invalidation for " 385 << "Scheduling sync because we received invalidation for "
396 << ModelTypeToString(model_type); 386 << ModelTypeToString(model_type);
397 nudge_tracker_.RecordRemoteInvalidation(model_type, invalidation.Pass()); 387 base::TimeDelta nudge_delay =
398 ScheduleNudgeImpl(desired_delay, nudge_location); 388 nudge_tracker_.RecordRemoteInvalidation(model_type, invalidation.Pass());
389 ScheduleNudgeImpl(nudge_delay, nudge_location);
399 } 390 }
400 391
401 void SyncSchedulerImpl::ScheduleInitialSyncNudge(syncer::ModelType model_type) { 392 void SyncSchedulerImpl::ScheduleInitialSyncNudge(syncer::ModelType model_type) {
402 DCHECK(CalledOnValidThread()); 393 DCHECK(CalledOnValidThread());
403 394
404 SDVLOG(2) << "Scheduling non-blocking initial sync for " 395 SDVLOG(2) << "Scheduling non-blocking initial sync for "
405 << ModelTypeToString(model_type); 396 << ModelTypeToString(model_type);
406 nudge_tracker_.RecordInitialSyncRequired(model_type); 397 nudge_tracker_.RecordInitialSyncRequired(model_type);
407 ScheduleNudgeImpl(TimeDelta::FromSeconds(0), FROM_HERE); 398 ScheduleNudgeImpl(TimeDelta::FromSeconds(0), FROM_HERE);
408 } 399 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 } 445 }
455 446
456 const char* SyncSchedulerImpl::GetModeString(SyncScheduler::Mode mode) { 447 const char* SyncSchedulerImpl::GetModeString(SyncScheduler::Mode mode) {
457 switch (mode) { 448 switch (mode) {
458 ENUM_CASE(CONFIGURATION_MODE); 449 ENUM_CASE(CONFIGURATION_MODE);
459 ENUM_CASE(NORMAL_MODE); 450 ENUM_CASE(NORMAL_MODE);
460 } 451 }
461 return ""; 452 return "";
462 } 453 }
463 454
455 void SyncSchedulerImpl::SetDefaultNudgeDelay(base::TimeDelta delay_ms) {
456 DCHECK(CalledOnValidThread());
457 nudge_tracker_.SetDefaultNudgeDelay(delay_ms);
458 }
459
464 void SyncSchedulerImpl::DoNudgeSyncSessionJob(JobPriority priority) { 460 void SyncSchedulerImpl::DoNudgeSyncSessionJob(JobPriority priority) {
465 DCHECK(CalledOnValidThread()); 461 DCHECK(CalledOnValidThread());
466 DCHECK(CanRunNudgeJobNow(priority)); 462 DCHECK(CanRunNudgeJobNow(priority));
467 463
468 DVLOG(2) << "Will run normal mode sync cycle with types " 464 DVLOG(2) << "Will run normal mode sync cycle with types "
469 << ModelTypeSetToString(session_context_->GetEnabledTypes()); 465 << ModelTypeSetToString(session_context_->GetEnabledTypes());
470 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); 466 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this));
471 bool premature_exit = !syncer_->NormalSyncShare( 467 bool premature_exit = !syncer_->NormalSyncShare(
472 GetEnabledAndUnthrottledTypes(), 468 GetEnabledAndUnthrottledTypes(),
473 nudge_tracker_, 469 nudge_tracker_,
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 DCHECK(CalledOnValidThread()); 851 DCHECK(CalledOnValidThread());
856 syncer_short_poll_interval_seconds_ = new_interval; 852 syncer_short_poll_interval_seconds_ = new_interval;
857 } 853 }
858 854
859 void SyncSchedulerImpl::OnReceivedLongPollIntervalUpdate( 855 void SyncSchedulerImpl::OnReceivedLongPollIntervalUpdate(
860 const base::TimeDelta& new_interval) { 856 const base::TimeDelta& new_interval) {
861 DCHECK(CalledOnValidThread()); 857 DCHECK(CalledOnValidThread());
862 syncer_long_poll_interval_seconds_ = new_interval; 858 syncer_long_poll_interval_seconds_ = new_interval;
863 } 859 }
864 860
865 void SyncSchedulerImpl::OnReceivedSessionsCommitDelay( 861 void SyncSchedulerImpl::OnReceivedCustomNudgeDelays(
866 const base::TimeDelta& new_delay) { 862 const std::map<ModelType, base::TimeDelta>& nudge_delays) {
867 DCHECK(CalledOnValidThread()); 863 DCHECK(CalledOnValidThread());
868 sessions_commit_delay_ = new_delay; 864 nudge_tracker_.OnReceivedCustomNudgeDelays(nudge_delays);
869 } 865 }
870 866
871 void SyncSchedulerImpl::OnReceivedClientInvalidationHintBufferSize(int size) { 867 void SyncSchedulerImpl::OnReceivedClientInvalidationHintBufferSize(int size) {
872 if (size > 0) 868 if (size > 0)
873 nudge_tracker_.SetHintBufferSize(size); 869 nudge_tracker_.SetHintBufferSize(size);
874 else 870 else
875 NOTREACHED() << "Hint buffer size should be > 0."; 871 NOTREACHED() << "Hint buffer size should be > 0.";
876 } 872 }
877 873
878 void SyncSchedulerImpl::OnSyncProtocolError( 874 void SyncSchedulerImpl::OnSyncProtocolError(
(...skipping 25 matching lines...) Expand all
904 900
905 void SyncSchedulerImpl::SetNotificationsEnabled(bool notifications_enabled) { 901 void SyncSchedulerImpl::SetNotificationsEnabled(bool notifications_enabled) {
906 DCHECK(CalledOnValidThread()); 902 DCHECK(CalledOnValidThread());
907 session_context_->set_notifications_enabled(notifications_enabled); 903 session_context_->set_notifications_enabled(notifications_enabled);
908 if (notifications_enabled) 904 if (notifications_enabled)
909 nudge_tracker_.OnInvalidationsEnabled(); 905 nudge_tracker_.OnInvalidationsEnabled();
910 else 906 else
911 nudge_tracker_.OnInvalidationsDisabled(); 907 nudge_tracker_.OnInvalidationsDisabled();
912 } 908 }
913 909
914 base::TimeDelta SyncSchedulerImpl::GetSessionsCommitDelay() const {
915 DCHECK(CalledOnValidThread());
916 return sessions_commit_delay_;
917 }
918
919 #undef SDVLOG_LOC 910 #undef SDVLOG_LOC
920 911
921 #undef SDVLOG 912 #undef SDVLOG
922 913
923 #undef SLOG 914 #undef SLOG
924 915
925 #undef ENUM_CASE 916 #undef ENUM_CASE
926 917
927 } // namespace syncer 918 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698