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; |
| 93 |
| 94 // Returns true if the client is currently in exponential backoff. |
| 95 bool IsBackingOff() const; |
92 | 96 |
93 private: | 97 private: |
94 enum JobPriority { | 98 enum JobPriority { |
95 // Non-canary jobs respect exponential backoff. | 99 // Non-canary jobs respect exponential backoff. |
96 NORMAL_PRIORITY, | 100 NORMAL_PRIORITY, |
97 // Canary jobs bypass exponential backoff, so use with extreme caution. | 101 // Canary jobs bypass exponential backoff, so use with extreme caution. |
98 CANARY_PRIORITY | 102 CANARY_PRIORITY |
99 }; | 103 }; |
100 | 104 |
101 enum PollAdjustType { | 105 enum PollAdjustType { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // Invoke the syncer to perform a configuration job. | 164 // Invoke the syncer to perform a configuration job. |
161 void DoConfigurationSyncSessionJob(JobPriority priority); | 165 void DoConfigurationSyncSessionJob(JobPriority priority); |
162 | 166 |
163 // Helper function for Do{Nudge,Configuration}SyncSessionJob. | 167 // Helper function for Do{Nudge,Configuration}SyncSessionJob. |
164 void HandleFailure( | 168 void HandleFailure( |
165 const sessions::ModelNeutralState& model_neutral_state); | 169 const sessions::ModelNeutralState& model_neutral_state); |
166 | 170 |
167 // Invoke the Syncer to perform a poll job. | 171 // Invoke the Syncer to perform a poll job. |
168 void DoPollSyncSessionJob(); | 172 void DoPollSyncSessionJob(); |
169 | 173 |
| 174 // Invoke the Syncer to perform a retry job. |
| 175 void DoRetrySyncSessionJob(); |
| 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(); |
179 | 186 |
180 // Determines if we're allowed to contact the server right now. | 187 // Determines if we're allowed to contact the server right now. |
181 bool CanRunJobNow(JobPriority priority); | 188 bool CanRunJobNow(JobPriority priority); |
182 | 189 |
183 // Determines if we're allowed to contact the server right now. | 190 // Determines if we're allowed to contact the server right now. |
184 bool CanRunNudgeJobNow(JobPriority priority); | 191 bool CanRunNudgeJobNow(JobPriority priority); |
185 | 192 |
186 // If the scheduler's current state supports it, this will create a job based | 193 // If the scheduler's current state supports it, this will create a job based |
187 // on the passed in parameters and coalesce it with any other pending jobs, | 194 // on the passed in parameters and coalesce it with any other pending jobs, |
188 // then post a delayed task to run it. It may also choose to drop the job or | 195 // then post a delayed task to run it. It may also choose to drop the job or |
189 // save it for later, depending on the scheduler's current state. | 196 // save it for later, depending on the scheduler's current state. |
190 void ScheduleNudgeImpl( | 197 void ScheduleNudgeImpl( |
191 const base::TimeDelta& delay, | 198 const base::TimeDelta& delay, |
192 const tracked_objects::Location& nudge_location); | 199 const tracked_objects::Location& nudge_location); |
193 | 200 |
194 // Returns true if the client is currently in exponential backoff. | |
195 bool IsBackingOff() const; | |
196 | |
197 // Helper to signal all listeners registered with |session_context_|. | 201 // Helper to signal all listeners registered with |session_context_|. |
198 void Notify(SyncEngineEvent::EventCause cause); | 202 void Notify(SyncEngineEvent::EventCause cause); |
199 | 203 |
200 // Helper to signal listeners about changed retry time. | 204 // Helper to signal listeners about changed retry time. |
201 void NotifyRetryTime(base::Time retry_time); | 205 void NotifyRetryTime(base::Time retry_time); |
202 | 206 |
203 // Helper to signal listeners about changed throttled types. | 207 // Helper to signal listeners about changed throttled types. |
204 void NotifyThrottledTypesChanged(ModelTypeSet types); | 208 void NotifyThrottledTypesChanged(ModelTypeSet types); |
205 | 209 |
206 // Looks for pending work and, if it finds any, run this work at "canary" | 210 // Looks for pending work and, if it finds any, run this work at "canary" |
(...skipping 16 matching lines...) Expand all Loading... |
223 | 227 |
224 // Attempts to exit EXPONENTIAL_BACKOFF by calling TryCanaryJob(). | 228 // Attempts to exit EXPONENTIAL_BACKOFF by calling TryCanaryJob(). |
225 void ExponentialBackoffRetry(); | 229 void ExponentialBackoffRetry(); |
226 | 230 |
227 // Called when the root cause of the current connection error is fixed. | 231 // Called when the root cause of the current connection error is fixed. |
228 void OnServerConnectionErrorFixed(); | 232 void OnServerConnectionErrorFixed(); |
229 | 233 |
230 // Creates a session for a poll and performs the sync. | 234 // Creates a session for a poll and performs the sync. |
231 void PollTimerCallback(); | 235 void PollTimerCallback(); |
232 | 236 |
| 237 // Creates a session for a retry and performs the sync. |
| 238 void RetryTimerCallback(); |
| 239 |
233 // Returns the set of types that are enabled and not currently throttled. | 240 // Returns the set of types that are enabled and not currently throttled. |
234 ModelTypeSet GetEnabledAndUnthrottledTypes(); | 241 ModelTypeSet GetEnabledAndUnthrottledTypes(); |
235 | 242 |
236 // Called as we are started to broadcast an initial session snapshot | 243 // Called as we are started to broadcast an initial session snapshot |
237 // containing data like initial_sync_ended. Important when the client starts | 244 // containing data like initial_sync_ended. Important when the client starts |
238 // up and does not need to perform an initial sync. | 245 // up and does not need to perform an initial sync. |
239 void SendInitialSnapshot(); | 246 void SendInitialSnapshot(); |
240 | 247 |
241 // This is used for histogramming and analysis of ScheduleNudge* APIs. | 248 // This is used for histogramming and analysis of ScheduleNudge* APIs. |
242 // SyncScheduler is the ultimate choke-point for all such invocations (with | 249 // 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). | 336 // after NETWORK_UNAVAILABLE error). |
330 // It is reset back to NORMAL_PRIORITY on every call to TrySyncSessionJobImpl. | 337 // It is reset back to NORMAL_PRIORITY on every call to TrySyncSessionJobImpl. |
331 JobPriority next_sync_session_job_priority_; | 338 JobPriority next_sync_session_job_priority_; |
332 | 339 |
333 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_; | 340 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_; |
334 | 341 |
335 // A second factory specially for weak_handle_this_, to allow the handle | 342 // A second factory specially for weak_handle_this_, to allow the handle |
336 // to be const and alleviate threading concerns. | 343 // to be const and alleviate threading concerns. |
337 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_for_weak_handle_; | 344 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_for_weak_handle_; |
338 | 345 |
| 346 // One-shot timer for scheduling GU retry according to delay set by server. |
| 347 base::OneShotTimer<SyncSchedulerImpl> retry_timer_; |
| 348 |
339 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl); | 349 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl); |
340 }; | 350 }; |
341 | 351 |
342 } // namespace syncer | 352 } // namespace syncer |
343 | 353 |
344 #endif // SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ | 354 #endif // SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ |
OLD | NEW |