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

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

Issue 10483015: [Sync] Refactor sync configuration logic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 // A class to schedule syncer tasks intelligently. 5 // A class to schedule syncer tasks intelligently.
6 #ifndef SYNC_ENGINE_SYNC_SCHEDULER_H_ 6 #ifndef SYNC_ENGINE_SYNC_SCHEDULER_H_
7 #define SYNC_ENGINE_SYNC_SCHEDULER_H_ 7 #define SYNC_ENGINE_SYNC_SCHEDULER_H_
8 #pragma once 8 #pragma once
9 9
10 #include <string> 10 #include <string>
(...skipping 19 matching lines...) Expand all
30 class MessageLoop; 30 class MessageLoop;
31 31
32 namespace tracked_objects { 32 namespace tracked_objects {
33 class Location; 33 class Location;
34 } // namespace tracked_objects 34 } // namespace tracked_objects
35 35
36 namespace browser_sync { 36 namespace browser_sync {
37 37
38 struct ServerConnectionEvent; 38 struct ServerConnectionEvent;
39 39
40 struct ConfigureParams {
41 ConfigureParams();
42 ConfigureParams(
43 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& source,
44 const syncable::ModelTypeSet& types_to_config,
45 const browser_sync::ModelSafeRoutingInfo& routing_info,
46 bool need_encryption_key,
47 const base::Closure& ready_task);
48 ~ConfigureParams();
49
50 // Source for the configuration.
51 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source;
52 // The types that should be downloaded.
53 syncable::ModelTypeSet types_to_config;
54 // The new routing info (superset of types to be downloaded).
55 ModelSafeRoutingInfo routing_info;
56 // Whether we need to perform a GetKey command.
57 bool need_encryption_key;
58 // Callback to invoke on configuration completion.
59 base::Closure ready_task;
60 };
61
40 class SyncScheduler : public sessions::SyncSession::Delegate { 62 class SyncScheduler : public sessions::SyncSession::Delegate {
41 public: 63 public:
42 enum Mode { 64 enum Mode {
43 // In this mode, the thread only performs configuration tasks. This is 65 // In this mode, the thread only performs configuration tasks. This is
44 // designed to make the case where we want to download updates for a 66 // designed to make the case where we want to download updates for a
45 // specific type only, and not continue syncing until we are moved into 67 // specific type only, and not continue syncing until we are moved into
46 // normal mode. 68 // normal mode.
47 CONFIGURATION_MODE, 69 CONFIGURATION_MODE,
48 // Resumes polling and allows nudges, drops configuration tasks. Runs 70 // Resumes polling and allows nudges, drops configuration tasks. Runs
49 // through entire sync cycle. 71 // through entire sync cycle.
50 NORMAL_MODE, 72 NORMAL_MODE,
51 }; 73 };
52 74
53 // All methods of SyncScheduler must be called on the same thread 75 // All methods of SyncScheduler must be called on the same thread
54 // (except for RequestEarlyExit()). 76 // (except for RequestEarlyExit()).
55 77
56 // |name| is a display string to identify the syncer thread. Takes 78 // |name| is a display string to identify the syncer thread. Takes
57 // |ownership of |syncer|. 79 // |ownership of |syncer|.
58 SyncScheduler(const std::string& name, 80 SyncScheduler(const std::string& name,
59 sessions::SyncSessionContext* context, Syncer* syncer); 81 sessions::SyncSessionContext* context, Syncer* syncer);
60 82
61 // Calls Stop(). 83 // Calls Stop().
62 virtual ~SyncScheduler(); 84 virtual ~SyncScheduler();
63 85
64 // Start the scheduler with the given mode. If the scheduler is 86 // Start the scheduler with the given mode. If the scheduler is
65 // already started, switch to the given mode, although some 87 // already started, switch to the given mode, although some
66 // scheduled tasks from the old mode may still run. If non-NULL, 88 // scheduled tasks from the old mode may still run.
67 // |callback| will be invoked when the mode has been changed to 89 void Start(Mode mode);
68 // |mode|. Takes ownership of |callback|. 90
69 void Start(Mode mode, const base::Closure& callback); 91 // Performs the configuration tasks specified by |params|. Returns true if
92 // the configuration task completes, false if a retry had to be scheduled
93 // for later completion. |params.ready_task| is invoked whenever the
94 // configuration task completes.
95 // Note: must already be in CONFIGURATION mode.
96 bool Configure(const ConfigureParams& params);
70 97
71 // Request that any running syncer task stop as soon as possible and 98 // Request that any running syncer task stop as soon as possible and
72 // cancel all scheduled tasks. This function can be called from any thread, 99 // cancel all scheduled tasks. This function can be called from any thread,
73 // and should in fact be called from a thread that isn't the sync loop to 100 // and should in fact be called from a thread that isn't the sync loop to
74 // allow preempting ongoing sync cycles. 101 // allow preempting ongoing sync cycles.
75 // Invokes |callback| from the sync loop once syncer is idle and all tasks 102 // Invokes |callback| from the sync loop once syncer is idle and all tasks
76 // are cancelled. 103 // are cancelled.
77 void RequestStop(const base::Closure& callback); 104 void RequestStop(const base::Closure& callback);
78 105
79 // The meat and potatoes. 106 // The meat and potatoes.
80 void ScheduleNudge(const base::TimeDelta& delay, NudgeSource source, 107 void ScheduleNudge(const base::TimeDelta& delay, NudgeSource source,
81 syncable::ModelTypeSet types, 108 syncable::ModelTypeSet types,
82 const tracked_objects::Location& nudge_location); 109 const tracked_objects::Location& nudge_location);
83 void ScheduleNudgeWithPayloads( 110 void ScheduleNudgeWithPayloads(
84 const base::TimeDelta& delay, NudgeSource source, 111 const base::TimeDelta& delay, NudgeSource source,
85 const syncable::ModelTypePayloadMap& types_with_payloads, 112 const syncable::ModelTypePayloadMap& types_with_payloads,
86 const tracked_objects::Location& nudge_location); 113 const tracked_objects::Location& nudge_location);
87 114
88 // Note: The source argument of this function must come from the subset of
89 // GetUpdatesCallerInfo values related to configurations.
90 void Configure(
91 syncable::ModelTypeSet types,
92 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source);
93
94 void ClearUserData(); 115 void ClearUserData();
95 116
96 void CleanupDisabledTypes(); 117 void CleanupDisabledTypes();
97 118
98 // Change status of notifications in the SyncSessionContext. 119 // Change status of notifications in the SyncSessionContext.
99 void set_notifications_enabled(bool notifications_enabled); 120 void set_notifications_enabled(bool notifications_enabled);
100 121
101 base::TimeDelta sessions_commit_delay() const; 122 base::TimeDelta sessions_commit_delay() const;
102 123
103 // DDOS avoidance function. Calculates how long we should wait before trying 124 // DDOS avoidance function. Calculates how long we should wait before trying
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // during initial sync or reconfiguration. We don't run all steps of 174 // during initial sync or reconfiguration. We don't run all steps of
154 // the sync cycle for these (e.g. CleanupDisabledTypes is skipped). 175 // the sync cycle for these (e.g. CleanupDisabledTypes is skipped).
155 CONFIGURATION, 176 CONFIGURATION,
156 // The user disabled some types and we have to clean up the data 177 // The user disabled some types and we have to clean up the data
157 // for those. 178 // for those.
158 CLEANUP_DISABLED_TYPES, 179 CLEANUP_DISABLED_TYPES,
159 }; 180 };
160 SyncSessionJob(); 181 SyncSessionJob();
161 SyncSessionJob(SyncSessionJobPurpose purpose, base::TimeTicks start, 182 SyncSessionJob(SyncSessionJobPurpose purpose, base::TimeTicks start,
162 linked_ptr<sessions::SyncSession> session, bool is_canary_job, 183 linked_ptr<sessions::SyncSession> session, bool is_canary_job,
184 ConfigureParams config_params,
163 const tracked_objects::Location& nudge_location); 185 const tracked_objects::Location& nudge_location);
164 ~SyncSessionJob(); 186 ~SyncSessionJob();
165 static const char* GetPurposeString(SyncSessionJobPurpose purpose); 187 static const char* GetPurposeString(SyncSessionJobPurpose purpose);
166 188
167 SyncSessionJobPurpose purpose; 189 SyncSessionJobPurpose purpose;
168 base::TimeTicks scheduled_start; 190 base::TimeTicks scheduled_start;
169 linked_ptr<sessions::SyncSession> session; 191 linked_ptr<sessions::SyncSession> session;
170 bool is_canary_job; 192 bool is_canary_job;
193 ConfigureParams config_params;
171 194
172 // This is the location the job came from. Used for debugging. 195 // This is the location the job came from. Used for debugging.
173 // In case of multiple nudges getting coalesced this stores the 196 // In case of multiple nudges getting coalesced this stores the
174 // first location that came in. 197 // first location that came in.
175 tracked_objects::Location from_here; 198 tracked_objects::Location from_here;
176 }; 199 };
177 friend class SyncSchedulerTest; 200 friend class SyncSchedulerTest;
178 friend class SyncSchedulerWhiteboxTest; 201 friend class SyncSchedulerWhiteboxTest;
179 friend class SyncerTest; 202 friend class SyncerTest;
180 203
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 scoped_ptr<Syncer> syncer_; 425 scoped_ptr<Syncer> syncer_;
403 426
404 sessions::SyncSessionContext *session_context_; 427 sessions::SyncSessionContext *session_context_;
405 428
406 DISALLOW_COPY_AND_ASSIGN(SyncScheduler); 429 DISALLOW_COPY_AND_ASSIGN(SyncScheduler);
407 }; 430 };
408 431
409 } // namespace browser_sync 432 } // namespace browser_sync
410 433
411 #endif // SYNC_ENGINE_SYNC_SCHEDULER_H_ 434 #endif // SYNC_ENGINE_SYNC_SCHEDULER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698