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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 virtual bool IsCurrentlyThrottled() OVERRIDE; | 82 virtual bool IsCurrentlyThrottled() OVERRIDE; |
83 virtual void OnReceivedShortPollIntervalUpdate( | 83 virtual void OnReceivedShortPollIntervalUpdate( |
84 const base::TimeDelta& new_interval) OVERRIDE; | 84 const base::TimeDelta& new_interval) OVERRIDE; |
85 virtual void OnReceivedLongPollIntervalUpdate( | 85 virtual void OnReceivedLongPollIntervalUpdate( |
86 const base::TimeDelta& new_interval) OVERRIDE; | 86 const base::TimeDelta& new_interval) OVERRIDE; |
87 virtual void OnReceivedSessionsCommitDelay( | 87 virtual void OnReceivedSessionsCommitDelay( |
88 const base::TimeDelta& new_delay) OVERRIDE; | 88 const base::TimeDelta& new_delay) OVERRIDE; |
89 virtual void OnReceivedClientInvalidationHintBufferSize(int size) OVERRIDE; | 89 virtual void OnReceivedClientInvalidationHintBufferSize(int size) OVERRIDE; |
90 virtual void OnSyncProtocolError( | 90 virtual void OnSyncProtocolError( |
91 const sessions::SyncSessionSnapshot& snapshot) OVERRIDE; | 91 const sessions::SyncSessionSnapshot& snapshot) OVERRIDE; |
| 92 virtual void OnReceivedGuRetryDelaySeconds(int delay_seconds) OVERRIDE; |
92 | 93 |
93 private: | 94 private: |
94 enum JobPriority { | 95 enum JobPriority { |
95 // Non-canary jobs respect exponential backoff. | 96 // Non-canary jobs respect exponential backoff. |
96 NORMAL_PRIORITY, | 97 NORMAL_PRIORITY, |
97 // Canary jobs bypass exponential backoff, so use with extreme caution. | 98 // Canary jobs bypass exponential backoff, so use with extreme caution. |
98 CANARY_PRIORITY | 99 CANARY_PRIORITY |
99 }; | 100 }; |
100 | 101 |
101 enum PollAdjustType { | 102 enum PollAdjustType { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 WaitInterval(Mode mode, base::TimeDelta length); | 148 WaitInterval(Mode mode, base::TimeDelta length); |
148 | 149 |
149 static const char* GetModeString(Mode mode); | 150 static const char* GetModeString(Mode mode); |
150 | 151 |
151 Mode mode; | 152 Mode mode; |
152 base::TimeDelta length; | 153 base::TimeDelta length; |
153 }; | 154 }; |
154 | 155 |
155 static const char* GetModeString(Mode mode); | 156 static const char* GetModeString(Mode mode); |
156 | 157 |
157 // Invoke the syncer to perform a nudge job. | |
158 void DoNudgeSyncSessionJob(JobPriority priority); | |
159 | |
160 // Invoke the syncer to perform a configuration job. | 158 // Invoke the syncer to perform a configuration job. |
161 void DoConfigurationSyncSessionJob(JobPriority priority); | 159 void DoConfigurationSyncSessionJob(JobPriority priority); |
162 | 160 |
163 // Helper function for Do{Nudge,Configuration}SyncSessionJob. | 161 // Helper function for Do{Nudge,Configuration}SyncSessionJob. |
164 void HandleFailure( | 162 void HandleFailure( |
165 const sessions::ModelNeutralState& model_neutral_state); | 163 const sessions::ModelNeutralState& model_neutral_state); |
166 | 164 |
167 // Invoke the Syncer to perform a poll job. | 165 // Invoke the syncer to perform a nudge job. Return true if session didn't |
168 void DoPollSyncSessionJob(); | 166 // abort pre-maturely. |
| 167 bool DoNudgeSyncSessionJob(sessions::SyncSession* session); |
| 168 |
| 169 // Invoke the Syncer to perform a poll job. Return true if session didn't |
| 170 // abort pre-maturely. |
| 171 bool DoPollSyncSessionJob(sessions::SyncSession* session); |
| 172 |
| 173 // Invoke the Syncer to perform a retry job. Return true if session didn't |
| 174 // abort pre-maturely. |
| 175 bool DoRetrySyncSessionJob(sessions::SyncSession* session); |
169 | 176 |
170 // Helper function to calculate poll interval. | 177 // Helper function to calculate poll interval. |
171 base::TimeDelta GetPollInterval(); | 178 base::TimeDelta GetPollInterval(); |
172 | 179 |
173 // Adjusts the poll timer to account for new poll interval, and possibly | 180 // Adjusts the poll timer to account for new poll interval, and possibly |
174 // resets the poll interval, depedning on the flag's value. | 181 // resets the poll interval, depedning on the flag's value. |
175 void AdjustPolling(PollAdjustType type); | 182 void AdjustPolling(PollAdjustType type); |
176 | 183 |
177 // Helper to restart waiting with |wait_interval_|'s timer. | 184 // Helper to restart waiting with |wait_interval_|'s timer. |
178 void RestartWaiting(); | 185 void RestartWaiting(); |
(...skipping 26 matching lines...) Expand all Loading... |
205 | 212 |
206 // Looks for pending work and, if it finds any, run this work at "canary" | 213 // Looks for pending work and, if it finds any, run this work at "canary" |
207 // priority. | 214 // priority. |
208 void TryCanaryJob(); | 215 void TryCanaryJob(); |
209 | 216 |
210 // At the moment TrySyncSessionJob just posts call to TrySyncSessionJobImpl on | 217 // At the moment TrySyncSessionJob just posts call to TrySyncSessionJobImpl on |
211 // current thread. In the future it will request access token here. | 218 // current thread. In the future it will request access token here. |
212 void TrySyncSessionJob(); | 219 void TrySyncSessionJob(); |
213 void TrySyncSessionJobImpl(); | 220 void TrySyncSessionJobImpl(); |
214 | 221 |
| 222 // Post-processing according to session result. |
| 223 void SyncSessionPostProcessing(sessions::SyncSession* session); |
| 224 |
215 // Transitions out of the THROTTLED WaitInterval then calls TryCanaryJob(). | 225 // Transitions out of the THROTTLED WaitInterval then calls TryCanaryJob(). |
216 void Unthrottle(); | 226 void Unthrottle(); |
217 | 227 |
218 // Called when a per-type throttling interval expires. | 228 // Called when a per-type throttling interval expires. |
219 void TypeUnthrottle(base::TimeTicks unthrottle_time); | 229 void TypeUnthrottle(base::TimeTicks unthrottle_time); |
220 | 230 |
221 // Runs a normal nudge job when the scheduled timer expires. | 231 // Runs a normal nudge job when the scheduled timer expires. |
222 void PerformDelayedNudge(); | 232 void PerformDelayedNudge(); |
223 | 233 |
224 // Attempts to exit EXPONENTIAL_BACKOFF by calling TryCanaryJob(). | 234 // Attempts to exit EXPONENTIAL_BACKOFF by calling TryCanaryJob(). |
225 void ExponentialBackoffRetry(); | 235 void ExponentialBackoffRetry(); |
226 | 236 |
227 // Called when the root cause of the current connection error is fixed. | 237 // Called when the root cause of the current connection error is fixed. |
228 void OnServerConnectionErrorFixed(); | 238 void OnServerConnectionErrorFixed(); |
229 | 239 |
230 // Creates a session for a poll and performs the sync. | 240 // Creates a session for a poll and performs the sync. |
231 void PollTimerCallback(); | 241 void PollTimerCallback(); |
232 | 242 |
| 243 // Creates a session for a retry and performs the sync. |
| 244 void RetryTimerCallback(); |
| 245 |
233 // Returns the set of types that are enabled and not currently throttled. | 246 // Returns the set of types that are enabled and not currently throttled. |
234 ModelTypeSet GetEnabledAndUnthrottledTypes(); | 247 ModelTypeSet GetEnabledAndUnthrottledTypes(); |
235 | 248 |
236 // Called as we are started to broadcast an initial session snapshot | 249 // Called as we are started to broadcast an initial session snapshot |
237 // containing data like initial_sync_ended. Important when the client starts | 250 // containing data like initial_sync_ended. Important when the client starts |
238 // up and does not need to perform an initial sync. | 251 // up and does not need to perform an initial sync. |
239 void SendInitialSnapshot(); | 252 void SendInitialSnapshot(); |
240 | 253 |
241 // This is used for histogramming and analysis of ScheduleNudge* APIs. | 254 // This is used for histogramming and analysis of ScheduleNudge* APIs. |
242 // SyncScheduler is the ultimate choke-point for all such invocations (with | 255 // SyncScheduler is the ultimate choke-point for all such invocations (with |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 // after NETWORK_UNAVAILABLE error). | 342 // after NETWORK_UNAVAILABLE error). |
330 // It is reset back to NORMAL_PRIORITY on every call to TrySyncSessionJobImpl. | 343 // It is reset back to NORMAL_PRIORITY on every call to TrySyncSessionJobImpl. |
331 JobPriority next_sync_session_job_priority_; | 344 JobPriority next_sync_session_job_priority_; |
332 | 345 |
333 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_; | 346 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_; |
334 | 347 |
335 // A second factory specially for weak_handle_this_, to allow the handle | 348 // A second factory specially for weak_handle_this_, to allow the handle |
336 // to be const and alleviate threading concerns. | 349 // to be const and alleviate threading concerns. |
337 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_for_weak_handle_; | 350 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_for_weak_handle_; |
338 | 351 |
| 352 // One-shot timer for scheduling GU retry according to delay set by server. |
| 353 base::OneShotTimer<SyncSchedulerImpl> retry_timer_; |
| 354 |
339 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl); | 355 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl); |
340 }; | 356 }; |
341 | 357 |
342 } // namespace syncer | 358 } // namespace syncer |
343 | 359 |
344 #endif // SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ | 360 #endif // SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ |
OLD | NEW |