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

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

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

Powered by Google App Engine
This is Rietveld 408576698