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