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

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

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

Powered by Google App Engine
This is Rietveld 408576698