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