Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: sync/engine/sync_scheduler_impl.h

Issue 1132013004: [Sync] Refactoring polling to be reliable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Full patch Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sync/engine/sync_scheduler.h ('k') | sync/engine/sync_scheduler_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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) override; 54 void Start(Mode mode, base::Time last_poll_time) 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
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}SyncSessionJob. 154 // Helper function for Do{Nudge,Configuration,Poll}SyncSessionJob.
155 void HandleSuccess();
156
157 // Helper function for Do{Nudge,Configuration,Poll}SyncSessionJob.
155 void HandleFailure( 158 void HandleFailure(
156 const sessions::ModelNeutralState& model_neutral_state); 159 const sessions::ModelNeutralState& model_neutral_state);
157 160
158 // Invoke the Syncer to perform a poll job. 161 // Invoke the Syncer to perform a poll job.
159 void DoPollSyncSessionJob(); 162 void DoPollSyncSessionJob();
160 163
161 // Helper function to calculate poll interval. 164 // Helper function to calculate poll interval.
162 base::TimeDelta GetPollInterval(); 165 base::TimeDelta GetPollInterval();
163 166
164 // Adjusts the poll timer to account for new poll interval, and possibly 167 // Adjusts the poll timer to account for new poll interval, and possibly
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 const std::string name_; 242 const std::string name_;
240 243
241 // Set in Start(), unset in Stop(). 244 // Set in Start(), unset in Stop().
242 bool started_; 245 bool started_;
243 246
244 // Modifiable versions of kDefaultLongPollIntervalSeconds which can be 247 // Modifiable versions of kDefaultLongPollIntervalSeconds which can be
245 // updated by the server. 248 // updated by the server.
246 base::TimeDelta syncer_short_poll_interval_seconds_; 249 base::TimeDelta syncer_short_poll_interval_seconds_;
247 base::TimeDelta syncer_long_poll_interval_seconds_; 250 base::TimeDelta syncer_long_poll_interval_seconds_;
248 251
249 // Periodic timer for polling. See AdjustPolling. 252 // Timer for polling. Restarted on each successful poll, and when entering
250 base::RepeatingTimer<SyncSchedulerImpl> poll_timer_; 253 // normal sync mode or exiting an error state. Not active in configuration
254 // mode.
255 base::OneShotTimer<SyncSchedulerImpl> poll_timer_;
251 256
252 // The mode of operation. 257 // The mode of operation.
253 Mode mode_; 258 Mode mode_;
254 259
255 // Current wait state. Null if we're not in backoff and not throttled. 260 // Current wait state. Null if we're not in backoff and not throttled.
256 scoped_ptr<WaitInterval> wait_interval_; 261 scoped_ptr<WaitInterval> wait_interval_;
257 262
258 scoped_ptr<BackoffDelayProvider> delay_provider_; 263 scoped_ptr<BackoffDelayProvider> delay_provider_;
259 264
260 // The event that will wake us up. 265 // The event that will wake us up.
(...skipping 23 matching lines...) Expand all
284 typedef std::map<ModelType, base::TimeTicks> ModelTypeTimeMap; 289 typedef std::map<ModelType, base::TimeTicks> ModelTypeTimeMap;
285 ModelTypeTimeMap last_local_nudges_by_model_type_; 290 ModelTypeTimeMap last_local_nudges_by_model_type_;
286 291
287 // Used as an "anti-reentrancy defensive assertion". 292 // Used as an "anti-reentrancy defensive assertion".
288 // While true, it is illegal for any new scheduling activity to take place. 293 // While true, it is illegal for any new scheduling activity to take place.
289 // Ensures that higher layers don't break this law in response to events that 294 // Ensures that higher layers don't break this law in response to events that
290 // take place during a sync cycle. We call this out because such violations 295 // take place during a sync cycle. We call this out because such violations
291 // could result in tight sync loops hitting sync servers. 296 // could result in tight sync loops hitting sync servers.
292 bool no_scheduling_allowed_; 297 bool no_scheduling_allowed_;
293 298
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
303 // TryJob might get called for multiple reasons. It should only call 299 // TryJob might get called for multiple reasons. It should only call
304 // DoPollSyncSessionJob after some time since the last attempt. 300 // DoPollSyncSessionJob after some time since the last attempt.
305 // last_poll_reset_ keeps track of when was last attempt. 301 // last_poll_reset_ keeps track of when was last attempt.
306 base::TimeTicks last_poll_reset_; 302 base::TimeTicks last_poll_reset_;
307 303
308 // next_sync_session_job_priority_ defines which priority will be used next 304 // next_sync_session_job_priority_ defines which priority will be used next
309 // time TrySyncSessionJobImpl is called. CANARY_PRIORITY allows syncer to run 305 // time TrySyncSessionJobImpl is called. CANARY_PRIORITY allows syncer to run
310 // even if scheduler is in exponential backoff. This is needed for events that 306 // even if scheduler is in exponential backoff. This is needed for events that
311 // have chance of resolving previous error (e.g. network connection change 307 // have chance of resolving previous error (e.g. network connection change
312 // after NETWORK_UNAVAILABLE error). 308 // after NETWORK_UNAVAILABLE error).
313 // It is reset back to NORMAL_PRIORITY on every call to TrySyncSessionJobImpl. 309 // It is reset back to NORMAL_PRIORITY on every call to TrySyncSessionJobImpl.
314 JobPriority next_sync_session_job_priority_; 310 JobPriority next_sync_session_job_priority_;
315 311
316 // One-shot timer for scheduling GU retry according to delay set by server. 312 // One-shot timer for scheduling GU retry according to delay set by server.
317 base::OneShotTimer<SyncSchedulerImpl> retry_timer_; 313 base::OneShotTimer<SyncSchedulerImpl> retry_timer_;
318 314
319 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_; 315 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_;
320 316
321 // A second factory specially for weak_handle_this_, to allow the handle 317 // A second factory specially for weak_handle_this_, to allow the handle
322 // to be const and alleviate threading concerns. 318 // to be const and alleviate threading concerns.
323 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_for_weak_handle_; 319 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_for_weak_handle_;
324 320
325 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl); 321 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl);
326 }; 322 };
327 323
328 } // namespace syncer 324 } // namespace syncer
329 325
330 #endif // SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ 326 #endif // SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_
OLDNEW
« no previous file with comments | « sync/engine/sync_scheduler.h ('k') | sync/engine/sync_scheduler_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698