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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // |name| is a display string to identify the syncer thread. Takes | 44 // |name| is a display string to identify the syncer thread. Takes |
45 // |ownership of |syncer| and |delay_provider|. | 45 // |ownership of |syncer| and |delay_provider|. |
46 SyncSchedulerImpl(const std::string& name, | 46 SyncSchedulerImpl(const std::string& name, |
47 BackoffDelayProvider* delay_provider, | 47 BackoffDelayProvider* delay_provider, |
48 sessions::SyncSessionContext* context, | 48 sessions::SyncSessionContext* context, |
49 Syncer* syncer); | 49 Syncer* syncer); |
50 | 50 |
51 // Calls Stop(). | 51 // Calls Stop(). |
52 ~SyncSchedulerImpl() override; | 52 ~SyncSchedulerImpl() override; |
53 | 53 |
54 void Start(Mode mode, base::Time last_poll_time) override; | 54 void Start(Mode mode) override; |
55 void ScheduleConfiguration(const ConfigurationParams& params) override; | 55 void ScheduleConfiguration(const ConfigurationParams& params) override; |
56 void Stop() override; | 56 void Stop() override; |
57 void ScheduleLocalNudge( | 57 void ScheduleLocalNudge( |
58 ModelTypeSet types, | 58 ModelTypeSet types, |
59 const tracked_objects::Location& nudge_location) override; | 59 const tracked_objects::Location& nudge_location) override; |
60 void ScheduleLocalRefreshRequest( | 60 void ScheduleLocalRefreshRequest( |
61 ModelTypeSet types, | 61 ModelTypeSet types, |
62 const tracked_objects::Location& nudge_location) override; | 62 const tracked_objects::Location& nudge_location) override; |
63 void ScheduleInvalidationNudge( | 63 void ScheduleInvalidationNudge( |
64 syncer::ModelType type, | 64 syncer::ModelType type, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 static const char* GetModeString(Mode mode); | 144 static const char* GetModeString(Mode mode); |
145 | 145 |
146 void SetDefaultNudgeDelay(base::TimeDelta delay_ms); | 146 void SetDefaultNudgeDelay(base::TimeDelta delay_ms); |
147 | 147 |
148 // Invoke the syncer to perform a nudge job. | 148 // Invoke the syncer to perform a nudge job. |
149 void DoNudgeSyncSessionJob(JobPriority priority); | 149 void DoNudgeSyncSessionJob(JobPriority priority); |
150 | 150 |
151 // Invoke the syncer to perform a configuration job. | 151 // Invoke the syncer to perform a configuration job. |
152 void DoConfigurationSyncSessionJob(JobPriority priority); | 152 void DoConfigurationSyncSessionJob(JobPriority priority); |
153 | 153 |
154 // Helper function for Do{Nudge,Configuration,Poll}SyncSessionJob. | 154 // Helper function for Do{Nudge,Configuration}SyncSessionJob. |
155 void HandleSuccess(); | |
156 | |
157 // Helper function for Do{Nudge,Configuration,Poll}SyncSessionJob. | |
158 void HandleFailure( | 155 void HandleFailure( |
159 const sessions::ModelNeutralState& model_neutral_state); | 156 const sessions::ModelNeutralState& model_neutral_state); |
160 | 157 |
161 // Invoke the Syncer to perform a poll job. | 158 // Invoke the Syncer to perform a poll job. |
162 void DoPollSyncSessionJob(); | 159 void DoPollSyncSessionJob(); |
163 | 160 |
164 // Helper function to calculate poll interval. | 161 // Helper function to calculate poll interval. |
165 base::TimeDelta GetPollInterval(); | 162 base::TimeDelta GetPollInterval(); |
166 | 163 |
167 // Adjusts the poll timer to account for new poll interval, and possibly | 164 // Adjusts the poll timer to account for new poll interval, and possibly |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 const std::string name_; | 239 const std::string name_; |
243 | 240 |
244 // Set in Start(), unset in Stop(). | 241 // Set in Start(), unset in Stop(). |
245 bool started_; | 242 bool started_; |
246 | 243 |
247 // Modifiable versions of kDefaultLongPollIntervalSeconds which can be | 244 // Modifiable versions of kDefaultLongPollIntervalSeconds which can be |
248 // updated by the server. | 245 // updated by the server. |
249 base::TimeDelta syncer_short_poll_interval_seconds_; | 246 base::TimeDelta syncer_short_poll_interval_seconds_; |
250 base::TimeDelta syncer_long_poll_interval_seconds_; | 247 base::TimeDelta syncer_long_poll_interval_seconds_; |
251 | 248 |
252 // Timer for polling. Restarted on each successful poll, and when entering | 249 // Periodic timer for polling. See AdjustPolling. |
253 // normal sync mode or exiting an error state. Not active in configuration | 250 base::RepeatingTimer<SyncSchedulerImpl> poll_timer_; |
254 // mode. | |
255 base::OneShotTimer<SyncSchedulerImpl> poll_timer_; | |
256 | 251 |
257 // The mode of operation. | 252 // The mode of operation. |
258 Mode mode_; | 253 Mode mode_; |
259 | 254 |
260 // Current wait state. Null if we're not in backoff and not throttled. | 255 // Current wait state. Null if we're not in backoff and not throttled. |
261 scoped_ptr<WaitInterval> wait_interval_; | 256 scoped_ptr<WaitInterval> wait_interval_; |
262 | 257 |
263 scoped_ptr<BackoffDelayProvider> delay_provider_; | 258 scoped_ptr<BackoffDelayProvider> delay_provider_; |
264 | 259 |
265 // The event that will wake us up. | 260 // The event that will wake us up. |
(...skipping 23 matching lines...) Expand all Loading... |
289 typedef std::map<ModelType, base::TimeTicks> ModelTypeTimeMap; | 284 typedef std::map<ModelType, base::TimeTicks> ModelTypeTimeMap; |
290 ModelTypeTimeMap last_local_nudges_by_model_type_; | 285 ModelTypeTimeMap last_local_nudges_by_model_type_; |
291 | 286 |
292 // Used as an "anti-reentrancy defensive assertion". | 287 // Used as an "anti-reentrancy defensive assertion". |
293 // While true, it is illegal for any new scheduling activity to take place. | 288 // While true, it is illegal for any new scheduling activity to take place. |
294 // Ensures that higher layers don't break this law in response to events that | 289 // Ensures that higher layers don't break this law in response to events that |
295 // take place during a sync cycle. We call this out because such violations | 290 // take place during a sync cycle. We call this out because such violations |
296 // could result in tight sync loops hitting sync servers. | 291 // could result in tight sync loops hitting sync servers. |
297 bool no_scheduling_allowed_; | 292 bool no_scheduling_allowed_; |
298 | 293 |
| 294 // crbug/251307. This is a workaround for M29. crbug/259913 tracks proper fix |
| 295 // for M30. |
| 296 // The issue is that poll job runs after few hours of inactivity and therefore |
| 297 // will always fail with auth error because of expired access token. Once |
| 298 // fresh access token is requested poll job is not retried. |
| 299 // The change is to remember that poll timer just fired and retry poll job |
| 300 // after credentials are updated. |
| 301 bool do_poll_after_credentials_updated_; |
| 302 |
299 // TryJob might get called for multiple reasons. It should only call | 303 // TryJob might get called for multiple reasons. It should only call |
300 // DoPollSyncSessionJob after some time since the last attempt. | 304 // DoPollSyncSessionJob after some time since the last attempt. |
301 // last_poll_reset_ keeps track of when was last attempt. | 305 // last_poll_reset_ keeps track of when was last attempt. |
302 base::TimeTicks last_poll_reset_; | 306 base::TimeTicks last_poll_reset_; |
303 | 307 |
304 // next_sync_session_job_priority_ defines which priority will be used next | 308 // next_sync_session_job_priority_ defines which priority will be used next |
305 // time TrySyncSessionJobImpl is called. CANARY_PRIORITY allows syncer to run | 309 // time TrySyncSessionJobImpl is called. CANARY_PRIORITY allows syncer to run |
306 // even if scheduler is in exponential backoff. This is needed for events that | 310 // even if scheduler is in exponential backoff. This is needed for events that |
307 // have chance of resolving previous error (e.g. network connection change | 311 // have chance of resolving previous error (e.g. network connection change |
308 // after NETWORK_UNAVAILABLE error). | 312 // after NETWORK_UNAVAILABLE error). |
309 // It is reset back to NORMAL_PRIORITY on every call to TrySyncSessionJobImpl. | 313 // It is reset back to NORMAL_PRIORITY on every call to TrySyncSessionJobImpl. |
310 JobPriority next_sync_session_job_priority_; | 314 JobPriority next_sync_session_job_priority_; |
311 | 315 |
312 // One-shot timer for scheduling GU retry according to delay set by server. | 316 // One-shot timer for scheduling GU retry according to delay set by server. |
313 base::OneShotTimer<SyncSchedulerImpl> retry_timer_; | 317 base::OneShotTimer<SyncSchedulerImpl> retry_timer_; |
314 | 318 |
315 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_; | 319 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_; |
316 | 320 |
317 // A second factory specially for weak_handle_this_, to allow the handle | 321 // A second factory specially for weak_handle_this_, to allow the handle |
318 // to be const and alleviate threading concerns. | 322 // to be const and alleviate threading concerns. |
319 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_for_weak_handle_; | 323 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_for_weak_handle_; |
320 | 324 |
321 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl); | 325 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl); |
322 }; | 326 }; |
323 | 327 |
324 } // namespace syncer | 328 } // namespace syncer |
325 | 329 |
326 #endif // SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ | 330 #endif // SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ |
OLD | NEW |