OLD | NEW |
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 Loading... |
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 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 syncable::ModelTypeSet& types_to_download, |
| 49 const browser_sync::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 syncable::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 syncable::ModelTypeSet types, | 113 syncable::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 syncable::ModelTypePayloadMap& types_with_payloads, | 117 const syncable::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 syncable::ModelTypeSet types, | |
95 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source); | |
96 | |
97 // TODO(tim): remove this. crbug.com/131336 | 120 // TODO(tim): remove this. crbug.com/131336 |
98 void ClearUserData(); | 121 void ClearUserData(); |
99 | 122 |
100 void CleanupDisabledTypes(); | 123 void CleanupDisabledTypes(); |
101 | 124 |
102 // Change status of notifications in the SyncSessionContext. | 125 // Change status of notifications in the SyncSessionContext. |
103 void set_notifications_enabled(bool notifications_enabled); | 126 void set_notifications_enabled(bool notifications_enabled); |
104 | 127 |
105 base::TimeDelta sessions_commit_delay() const; | 128 base::TimeDelta sessions_commit_delay() const; |
106 | 129 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // during initial sync or reconfiguration. We don't run all steps of | 180 // during initial sync or reconfiguration. We don't run all steps of |
158 // the sync cycle for these (e.g. CleanupDisabledTypes is skipped). | 181 // the sync cycle for these (e.g. CleanupDisabledTypes is skipped). |
159 CONFIGURATION, | 182 CONFIGURATION, |
160 // The user disabled some types and we have to clean up the data | 183 // The user disabled some types and we have to clean up the data |
161 // for those. | 184 // for those. |
162 CLEANUP_DISABLED_TYPES, | 185 CLEANUP_DISABLED_TYPES, |
163 }; | 186 }; |
164 SyncSessionJob(); | 187 SyncSessionJob(); |
165 SyncSessionJob(SyncSessionJobPurpose purpose, base::TimeTicks start, | 188 SyncSessionJob(SyncSessionJobPurpose purpose, base::TimeTicks start, |
166 linked_ptr<sessions::SyncSession> session, bool is_canary_job, | 189 linked_ptr<sessions::SyncSession> session, bool is_canary_job, |
| 190 ConfigurationParams config_params, |
167 const tracked_objects::Location& nudge_location); | 191 const tracked_objects::Location& nudge_location); |
168 ~SyncSessionJob(); | 192 ~SyncSessionJob(); |
169 static const char* GetPurposeString(SyncSessionJobPurpose purpose); | 193 static const char* GetPurposeString(SyncSessionJobPurpose purpose); |
170 | 194 |
171 SyncSessionJobPurpose purpose; | 195 SyncSessionJobPurpose purpose; |
172 base::TimeTicks scheduled_start; | 196 base::TimeTicks scheduled_start; |
173 linked_ptr<sessions::SyncSession> session; | 197 linked_ptr<sessions::SyncSession> session; |
174 bool is_canary_job; | 198 bool is_canary_job; |
| 199 ConfigurationParams config_params; |
175 | 200 |
176 // This is the location the job came from. Used for debugging. | 201 // This is the location the job came from. Used for debugging. |
177 // In case of multiple nudges getting coalesced this stores the | 202 // In case of multiple nudges getting coalesced this stores the |
178 // first location that came in. | 203 // first location that came in. |
179 tracked_objects::Location from_here; | 204 tracked_objects::Location from_here; |
180 }; | 205 }; |
181 friend class SyncSchedulerTest; | 206 friend class SyncSchedulerTest; |
182 friend class SyncSchedulerWhiteboxTest; | 207 friend class SyncSchedulerWhiteboxTest; |
183 friend class SyncerTest; | 208 friend class SyncerTest; |
184 | 209 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 scoped_ptr<Syncer> syncer_; | 431 scoped_ptr<Syncer> syncer_; |
407 | 432 |
408 sessions::SyncSessionContext *session_context_; | 433 sessions::SyncSessionContext *session_context_; |
409 | 434 |
410 DISALLOW_COPY_AND_ASSIGN(SyncScheduler); | 435 DISALLOW_COPY_AND_ASSIGN(SyncScheduler); |
411 }; | 436 }; |
412 | 437 |
413 } // namespace browser_sync | 438 } // namespace browser_sync |
414 | 439 |
415 #endif // SYNC_ENGINE_SYNC_SCHEDULER_H_ | 440 #endif // SYNC_ENGINE_SYNC_SCHEDULER_H_ |
OLD | NEW |