Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #ifndef SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ | 5 #ifndef SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ |
| 6 #define SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ | 6 #define SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 ServerConnectionChangeDuringBackoff); | 124 ServerConnectionChangeDuringBackoff); |
| 125 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, | 125 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, |
| 126 ConnectionChangeCanaryPreemptedByNudge); | 126 ConnectionChangeCanaryPreemptedByNudge); |
| 127 | 127 |
| 128 struct SYNC_EXPORT_PRIVATE WaitInterval { | 128 struct SYNC_EXPORT_PRIVATE WaitInterval { |
| 129 enum Mode { | 129 enum Mode { |
| 130 // Uninitialized state, should not be set in practice. | 130 // Uninitialized state, should not be set in practice. |
| 131 UNKNOWN = -1, | 131 UNKNOWN = -1, |
| 132 // A wait interval whose duration has been affected by exponential | 132 // A wait interval whose duration has been affected by exponential |
| 133 // backoff. | 133 // backoff. |
| 134 // EXPONENTIAL_BACKOFF intervals are nudge-rate limited to 1 per interval. | 134 // EXPONENTIAL_BACKOFF intervals are nudge-rate limited to 1 per interval. |
|
tim (not reviewing)
2013/04/05 16:56:44
Amend comment.
rlarocque
2013/04/05 19:13:29
Done.
| |
| 135 EXPONENTIAL_BACKOFF, | 135 EXPONENTIAL_BACKOFF, |
| 136 // A server-initiated throttled interval. We do not allow any syncing | 136 // A server-initiated throttled interval. We do not allow any syncing |
| 137 // during such an interval. | 137 // during such an interval. |
| 138 THROTTLED, | 138 THROTTLED, |
| 139 }; | 139 }; |
| 140 WaitInterval(); | 140 WaitInterval(); |
| 141 ~WaitInterval(); | 141 ~WaitInterval(); |
| 142 WaitInterval(Mode mode, base::TimeDelta length); | 142 WaitInterval(Mode mode, base::TimeDelta length); |
| 143 | 143 |
| 144 static const char* GetModeString(Mode mode); | 144 static const char* GetModeString(Mode mode); |
| 145 | 145 |
| 146 Mode mode; | 146 Mode mode; |
| 147 | 147 |
| 148 // This bool is set to true if we have observed a nudge during this | 148 // This bool is set to true if we have observed a nudge during this |
|
tim (not reviewing)
2013/04/05 16:56:44
Remove comment.
rlarocque
2013/04/05 19:13:29
Done.
| |
| 149 // interval and mode == EXPONENTIAL_BACKOFF. | 149 // interval and mode == EXPONENTIAL_BACKOFF. |
| 150 bool had_nudge; | |
| 151 base::TimeDelta length; | 150 base::TimeDelta length; |
| 152 base::OneShotTimer<SyncSchedulerImpl> timer; | |
| 153 }; | 151 }; |
| 154 | 152 |
| 155 static const char* GetModeString(Mode mode); | 153 static const char* GetModeString(Mode mode); |
| 156 | 154 |
| 157 static const char* GetDecisionString(JobProcessDecision decision); | 155 static const char* GetDecisionString(JobProcessDecision decision); |
| 158 | 156 |
| 159 // Helper to cancel any existing delayed task and replace it with a new one. | |
| 160 // It will not post any tasks if the scheduler is in a "stopped" state. | |
| 161 void PostDelayedTask(const tracked_objects::Location& from_here, | |
| 162 const char* name, | |
| 163 const base::Closure& task, | |
| 164 base::TimeDelta delay); | |
| 165 | |
| 166 // Invoke the syncer to perform a non-POLL job. | 157 // Invoke the syncer to perform a non-POLL job. |
| 167 bool DoSyncSessionJobImpl(scoped_ptr<SyncSessionJob> job, | 158 bool DoSyncSessionJobImpl(scoped_ptr<SyncSessionJob> job, |
| 168 JobPriority priority); | 159 JobPriority priority); |
| 169 | 160 |
| 170 // Invoke the syncer to perform a nudge job. | 161 // Invoke the syncer to perform a nudge job. |
| 171 bool DoNudgeSyncSessionJob(JobPriority priority); | 162 void DoNudgeSyncSessionJob(JobPriority priority); |
| 172 | 163 |
| 173 // Invoke the syncer to perform a configuration job. | 164 // Invoke the syncer to perform a configuration job. |
| 174 bool DoConfigurationSyncSessionJob(JobPriority priority); | 165 bool DoConfigurationSyncSessionJob(JobPriority priority); |
| 175 | 166 |
| 176 // Returns whether or not it's safe to run a poll job at this time. | 167 // Returns whether or not it's safe to run a poll job at this time. |
| 177 bool ShouldPoll(); | 168 bool ShouldPoll(); |
| 178 | 169 |
| 179 // Invoke the Syncer to perform a poll job. | 170 // Invoke the Syncer to perform a poll job. |
| 180 void DoPollSyncSessionJob(); | 171 void DoPollSyncSessionJob(); |
| 181 | 172 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 base::RepeatingTimer<SyncSchedulerImpl> poll_timer_; | 286 base::RepeatingTimer<SyncSchedulerImpl> poll_timer_; |
| 296 | 287 |
| 297 // The mode of operation. | 288 // The mode of operation. |
| 298 Mode mode_; | 289 Mode mode_; |
| 299 | 290 |
| 300 // Current wait state. Null if we're not in backoff and not throttled. | 291 // Current wait state. Null if we're not in backoff and not throttled. |
| 301 scoped_ptr<WaitInterval> wait_interval_; | 292 scoped_ptr<WaitInterval> wait_interval_; |
| 302 | 293 |
| 303 scoped_ptr<BackoffDelayProvider> delay_provider_; | 294 scoped_ptr<BackoffDelayProvider> delay_provider_; |
| 304 | 295 |
| 305 // We allow at most one PostedTask to be pending at one time. This is it. | 296 // The event that will wake us up. |
| 306 // We will cancel this task before starting a new one. | 297 base::OneShotTimer<SyncSchedulerImpl> pending_wakeup_timer_; |
| 307 base::CancelableClosure pending_wakeup_event_; | |
| 308 | 298 |
| 309 // Pending configure job storage. Note that | 299 // Pending configure job storage. Note that |
| 310 // (mode_ != CONFIGURATION_MODE) \implies !pending_configure_job_. | 300 // (mode_ != CONFIGURATION_MODE) \implies !pending_configure_job_. |
| 311 scoped_ptr<SyncSessionJob> pending_configure_job_; | 301 scoped_ptr<SyncSessionJob> pending_configure_job_; |
| 312 | 302 |
| 313 // Pending nudge job storage. These jobs can exist in CONFIGURATION_MODE, but | 303 // Pending nudge job storage. These jobs can exist in CONFIGURATION_MODE, but |
| 314 // they will be run only in NORMAL_MODE. | 304 // they will be run only in NORMAL_MODE. |
| 315 scoped_ptr<SyncSessionJob> pending_nudge_job_; | 305 scoped_ptr<SyncSessionJob> pending_nudge_job_; |
| 316 | 306 |
| 317 // Invoked to run through the sync cycle. | 307 // Invoked to run through the sync cycle. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 331 // take place during a sync cycle. We call this out because such violations | 321 // take place during a sync cycle. We call this out because such violations |
| 332 // could result in tight sync loops hitting sync servers. | 322 // could result in tight sync loops hitting sync servers. |
| 333 bool no_scheduling_allowed_; | 323 bool no_scheduling_allowed_; |
| 334 | 324 |
| 335 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl); | 325 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl); |
| 336 }; | 326 }; |
| 337 | 327 |
| 338 } // namespace syncer | 328 } // namespace syncer |
| 339 | 329 |
| 340 #endif // SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ | 330 #endif // SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ |
| OLD | NEW |