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

Side by Side Diff: chrome/browser/sync/engine/sync_scheduler.h

Issue 7655055: [Sync] Make BackendMigrator not wait for full sync cycles (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix race condition Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // A class to schedule syncer tasks intelligently. 5 // A class to schedule syncer tasks intelligently.
6 #ifndef CHROME_BROWSER_SYNC_ENGINE_SYNC_SCHEDULER_H_ 6 #ifndef CHROME_BROWSER_SYNC_ENGINE_SYNC_SCHEDULER_H_
7 #define CHROME_BROWSER_SYNC_ENGINE_SYNC_SCHEDULER_H_ 7 #define CHROME_BROWSER_SYNC_ENGINE_SYNC_SCHEDULER_H_
8 #pragma once 8 #pragma once
9 9
10 #include <string> 10 #include <string>
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // (except for RequestEarlyExit()). 55 // (except for RequestEarlyExit()).
56 56
57 // |name| is a display string to identify the syncer thread. Takes 57 // |name| is a display string to identify the syncer thread. Takes
58 // |ownership of both |context| and |syncer|. 58 // |ownership of both |context| and |syncer|.
59 SyncScheduler(const std::string& name, 59 SyncScheduler(const std::string& name,
60 sessions::SyncSessionContext* context, Syncer* syncer); 60 sessions::SyncSessionContext* context, Syncer* syncer);
61 61
62 // Calls Stop(). 62 // Calls Stop().
63 virtual ~SyncScheduler(); 63 virtual ~SyncScheduler();
64 64
65 typedef Callback0::Type ModeChangeCallback;
66
67 // Start the scheduler with the given mode. If the scheduler is 65 // Start the scheduler with the given mode. If the scheduler is
68 // already started, switch to the given mode, although some 66 // already started, switch to the given mode, although some
69 // scheduled tasks from the old mode may still run. If non-NULL, 67 // scheduled tasks from the old mode may still run. If non-NULL,
70 // |callback| will be invoked when the mode has been changed to 68 // |callback| will be invoked when the mode has been changed to
71 // |mode|. Takes ownership of |callback|. 69 // |mode|. Takes ownership of |callback|.
72 void Start(Mode mode, ModeChangeCallback* callback); 70 void Start(Mode mode, const base::Closure& callback);
73 71
74 // Request that any running syncer task stop as soon as possible. 72 // Request that any running syncer task stop as soon as possible.
75 // This function can be called from any thread. Stop must still be 73 // This function can be called from any thread. Stop must still be
76 // called to stop future schedule tasks. 74 // called to stop future schedule tasks.
77 // 75 //
78 // TODO(akalin): This function is awkward. Find a better way to let 76 // TODO(akalin): This function is awkward. Find a better way to let
79 // the UI thread stop the syncer thread. 77 // the UI thread stop the syncer thread.
80 void RequestEarlyExit(); 78 void RequestEarlyExit();
81 79
82 // Cancel all scheduled tasks. Can be called even if already stopped. 80 // Cancel all scheduled tasks. Can be called even if already stopped.
83 void Stop(); 81 void Stop();
84 82
83 // TODO(akalin): Add callback parameters to Schedule* functions as
84 // needed. In particular, we'd like to know when a nudge completes
85 // (or fails) so that we can acknowledge any invalidations that
86 // triggered the nudge.
tim (not reviewing) 2011/08/26 12:41:40 So, one of the "future todos / open questions" in
87
85 // The meat and potatoes. 88 // The meat and potatoes.
86 void ScheduleNudge(const base::TimeDelta& delay, NudgeSource source, 89 void ScheduleNudge(const base::TimeDelta& delay, NudgeSource source,
87 const syncable::ModelTypeBitSet& types, 90 const syncable::ModelTypeBitSet& types,
88 const tracked_objects::Location& nudge_location); 91 const tracked_objects::Location& nudge_location);
89 void ScheduleNudgeWithPayloads( 92 void ScheduleNudgeWithPayloads(
90 const base::TimeDelta& delay, NudgeSource source, 93 const base::TimeDelta& delay, NudgeSource source,
91 const syncable::ModelTypePayloadMap& types_with_payloads, 94 const syncable::ModelTypePayloadMap& types_with_payloads,
92 const tracked_objects::Location& nudge_location); 95 const tracked_objects::Location& nudge_location);
93 void ScheduleConfig(const syncable::ModelTypeBitSet& types, 96 void ScheduleConfig(const syncable::ModelTypeBitSet& types,
94 sync_api::ConfigureReason reason); 97 sync_api::ConfigureReason reason);
95 void ScheduleClearUserData(); 98 void ScheduleClearUserData();
96 void ScheduleCleanupDisabledTypes(); 99 void ScheduleCleanupDisabledTypes(const base::Closure& callback);
tim (not reviewing) 2011/08/26 12:41:40 Please comment the new parameter.
97 100
98 // Change status of notifications in the SyncSessionContext. 101 // Change status of notifications in the SyncSessionContext.
99 void set_notifications_enabled(bool notifications_enabled); 102 void set_notifications_enabled(bool notifications_enabled);
100 103
101 base::TimeDelta sessions_commit_delay() const; 104 base::TimeDelta sessions_commit_delay() const;
102 105
103 // DDOS avoidance function. Calculates how long we should wait before trying 106 // DDOS avoidance function. Calculates how long we should wait before trying
104 // again after a failed sync attempt, where the last delay was |base_delay|. 107 // again after a failed sync attempt, where the last delay was |base_delay|.
105 // TODO(tim): Look at URLRequestThrottlerEntryInterface. 108 // TODO(tim): Look at URLRequestThrottlerEntryInterface.
106 static base::TimeDelta GetRecommendedDelay(const base::TimeDelta& base_delay); 109 static base::TimeDelta GetRecommendedDelay(const base::TimeDelta& base_delay);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // Typically used for fetching updates for a subset of the enabled types 152 // Typically used for fetching updates for a subset of the enabled types
150 // during initial sync or reconfiguration. We don't run all steps of 153 // during initial sync or reconfiguration. We don't run all steps of
151 // the sync cycle for these (e.g. CleanupDisabledTypes is skipped). 154 // the sync cycle for these (e.g. CleanupDisabledTypes is skipped).
152 CONFIGURATION, 155 CONFIGURATION,
153 // The user disabled some types and we have to clean up the data 156 // The user disabled some types and we have to clean up the data
154 // for those. 157 // for those.
155 CLEANUP_DISABLED_TYPES, 158 CLEANUP_DISABLED_TYPES,
156 }; 159 };
157 SyncSessionJob(); 160 SyncSessionJob();
158 SyncSessionJob(SyncSessionJobPurpose purpose, base::TimeTicks start, 161 SyncSessionJob(SyncSessionJobPurpose purpose, base::TimeTicks start,
159 linked_ptr<sessions::SyncSession> session, bool is_canary_job, 162 linked_ptr<sessions::SyncSession> session,
160 const tracked_objects::Location& nudge_location); 163 bool is_canary_job, const base::Closure& on_success,
164 const tracked_objects::Location& nudge_location);
161 ~SyncSessionJob(); 165 ~SyncSessionJob();
162 static const char* GetPurposeString(SyncSessionJobPurpose purpose); 166 static const char* GetPurposeString(SyncSessionJobPurpose purpose);
163 167
164 SyncSessionJobPurpose purpose; 168 SyncSessionJobPurpose purpose;
165 base::TimeTicks scheduled_start; 169 base::TimeTicks scheduled_start;
166 linked_ptr<sessions::SyncSession> session; 170 linked_ptr<sessions::SyncSession> session;
167 bool is_canary_job; 171 bool is_canary_job;
172 base::Closure on_success;
tim (not reviewing) 2011/08/26 12:41:40 I like this. I'm still wrapping my head around wh
168 173
169 // This is the location the job came from. Used for debugging. 174 // This is the location the job came from. Used for debugging.
170 // In case of multiple nudges getting coalesced this stores the 175 // In case of multiple nudges getting coalesced this stores the
171 // first location that came in. 176 // first location that came in.
172 tracked_objects::Location from_here; 177 tracked_objects::Location from_here;
173 }; 178 };
174 friend class SyncSchedulerTest; 179 friend class SyncSchedulerTest;
175 friend class SyncSchedulerWhiteboxTest; 180 friend class SyncSchedulerWhiteboxTest;
176 181
177 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, 182 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 void PostTask(const tracked_objects::Location& from_here, 249 void PostTask(const tracked_objects::Location& from_here,
245 const char* name, Task* task); 250 const char* name, Task* task);
246 void PostDelayedTask(const tracked_objects::Location& from_here, 251 void PostDelayedTask(const tracked_objects::Location& from_here,
247 const char* name, Task* task, int64 delay_ms); 252 const char* name, Task* task, int64 delay_ms);
248 253
249 // Helper to assemble a job and post a delayed task to sync. 254 // Helper to assemble a job and post a delayed task to sync.
250 void ScheduleSyncSessionJob( 255 void ScheduleSyncSessionJob(
251 const base::TimeDelta& delay, 256 const base::TimeDelta& delay,
252 SyncSessionJob::SyncSessionJobPurpose purpose, 257 SyncSessionJob::SyncSessionJobPurpose purpose,
253 sessions::SyncSession* session, 258 sessions::SyncSession* session,
259 const base::Closure& on_success,
254 const tracked_objects::Location& from_here); 260 const tracked_objects::Location& from_here);
255 261
256 // Invoke the Syncer to perform a sync. 262 // Invoke the Syncer to perform a sync.
257 void DoSyncSessionJob(const SyncSessionJob& job); 263 void DoSyncSessionJob(const SyncSessionJob& job);
258 264
259 // Called after the Syncer has performed the sync represented by |job|, to 265 // Called after the Syncer has performed the sync represented by |job|, to
260 // reset our state. 266 // reset our state.
261 void FinishSyncSessionJob(const SyncSessionJob& job); 267 void FinishSyncSessionJob(const SyncSessionJob& job);
262 268
263 // Record important state that might be needed in future syncs, such as which 269 // Record important state that might be needed in future syncs, such as which
(...skipping 25 matching lines...) Expand all
289 JobProcessDecision DecideWhileInWaitInterval(const SyncSessionJob& job); 295 JobProcessDecision DecideWhileInWaitInterval(const SyncSessionJob& job);
290 296
291 // Saves the job for future execution. Note: It drops all the poll jobs. 297 // Saves the job for future execution. Note: It drops all the poll jobs.
292 void SaveJob(const SyncSessionJob& job); 298 void SaveJob(const SyncSessionJob& job);
293 299
294 // Coalesces the current job with the pending nudge. 300 // Coalesces the current job with the pending nudge.
295 void InitOrCoalescePendingJob(const SyncSessionJob& job); 301 void InitOrCoalescePendingJob(const SyncSessionJob& job);
296 302
297 // 'Impl' here refers to real implementation of public functions, running on 303 // 'Impl' here refers to real implementation of public functions, running on
298 // |thread_|. 304 // |thread_|.
299 void StartImpl(Mode mode, ModeChangeCallback* callback); 305 void StartImpl(Mode mode, const base::Closure& callback);
300 void ScheduleNudgeImpl( 306 void ScheduleNudgeImpl(
301 const base::TimeDelta& delay, 307 const base::TimeDelta& delay,
302 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, 308 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source,
303 const syncable::ModelTypePayloadMap& types_with_payloads, 309 const syncable::ModelTypePayloadMap& types_with_payloads,
304 bool is_canary_job, const tracked_objects::Location& nudge_location); 310 bool is_canary_job, const tracked_objects::Location& nudge_location);
305 void ScheduleConfigImpl(const ModelSafeRoutingInfo& routing_info, 311 void ScheduleConfigImpl(const ModelSafeRoutingInfo& routing_info,
306 const std::vector<ModelSafeWorker*>& workers, 312 const std::vector<ModelSafeWorker*>& workers,
307 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source); 313 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source);
308 void ScheduleClearUserDataImpl(); 314 void ScheduleClearUserDataImpl();
309 void ScheduleCleanupDisabledTypesImpl(); 315 void ScheduleCleanupDisabledTypesImpl(const base::Closure& callback);
310 316
311 // Returns true if the client is currently in exponential backoff. 317 // Returns true if the client is currently in exponential backoff.
312 bool IsBackingOff() const; 318 bool IsBackingOff() const;
313 319
314 // Helper to signal all listeners registered with |session_context_|. 320 // Helper to signal all listeners registered with |session_context_|.
315 void Notify(SyncEngineEvent::EventCause cause); 321 void Notify(SyncEngineEvent::EventCause cause);
316 322
317 // Callback to change backoff state. 323 // Callback to change backoff state.
318 void DoCanaryJob(); 324 void DoCanaryJob();
319 void Unthrottle(); 325 void Unthrottle();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 scoped_ptr<Syncer> syncer_; 399 scoped_ptr<Syncer> syncer_;
394 400
395 scoped_ptr<sessions::SyncSessionContext> session_context_; 401 scoped_ptr<sessions::SyncSessionContext> session_context_;
396 402
397 DISALLOW_COPY_AND_ASSIGN(SyncScheduler); 403 DISALLOW_COPY_AND_ASSIGN(SyncScheduler);
398 }; 404 };
399 405
400 } // namespace browser_sync 406 } // namespace browser_sync
401 407
402 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNC_SCHEDULER_H_ 408 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNC_SCHEDULER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698