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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // In this mode, the thread only performs configuration tasks. This is | 43 // 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 | 44 // 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 | 45 // specific type only, and not continue syncing until we are moved into |
46 // normal mode. | 46 // normal mode. |
47 CONFIGURATION_MODE, | 47 CONFIGURATION_MODE, |
48 // Resumes polling and allows nudges, drops configuration tasks. Runs | 48 // Resumes polling and allows nudges, drops configuration tasks. Runs |
49 // through entire sync cycle. | 49 // through entire sync cycle. |
50 NORMAL_MODE, | 50 NORMAL_MODE, |
51 }; | 51 }; |
52 | 52 |
| 53 struct ConfigureParams { |
| 54 ConfigureParams(); |
| 55 ConfigureParams( |
| 56 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& source, |
| 57 const syncable::ModelTypeSet& types_to_config, |
| 58 const browser_sync::ModelSafeRoutingInfo& routing_info, |
| 59 bool need_cleanup, |
| 60 bool need_encryption_key, |
| 61 const base::Closure& ready_task); |
| 62 ~ConfigureParams(); |
| 63 |
| 64 // Source for the configuration. |
| 65 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source; |
| 66 // The types that should be downloaded. |
| 67 syncable::ModelTypeSet types_to_config; |
| 68 // The new routing info (superset of types to be downloaded). |
| 69 ModelSafeRoutingInfo routing_info; |
| 70 // Whether we need to perform a CleanupDisabledTypes command. |
| 71 bool need_cleanup; |
| 72 // Whether we need to perform a GetKey command. |
| 73 bool need_encryption_key; |
| 74 // Callback to invoke on configuration completion. |
| 75 base::Closure ready_task; |
| 76 }; |
| 77 |
53 // All methods of SyncScheduler must be called on the same thread | 78 // All methods of SyncScheduler must be called on the same thread |
54 // (except for RequestEarlyExit()). | 79 // (except for RequestEarlyExit()). |
55 | 80 |
56 // |name| is a display string to identify the syncer thread. Takes | 81 // |name| is a display string to identify the syncer thread. Takes |
57 // |ownership of |syncer|. | 82 // |ownership of |syncer|. |
58 SyncScheduler(const std::string& name, | 83 SyncScheduler(const std::string& name, |
59 sessions::SyncSessionContext* context, Syncer* syncer); | 84 sessions::SyncSessionContext* context, Syncer* syncer); |
60 | 85 |
61 // Calls Stop(). | 86 // Calls Stop(). |
62 virtual ~SyncScheduler(); | 87 virtual ~SyncScheduler(); |
63 | 88 |
64 // Start the scheduler with the given mode. If the scheduler is | 89 // Start the scheduler with the given mode. If the scheduler is |
65 // already started, switch to the given mode, although some | 90 // already started, switch to the given mode, although some |
66 // scheduled tasks from the old mode may still run. If non-NULL, | 91 // scheduled tasks from the old mode may still run. |
67 // |callback| will be invoked when the mode has been changed to | 92 void Start(Mode mode); |
68 // |mode|. Takes ownership of |callback|. | 93 |
69 void Start(Mode mode, const base::Closure& callback); | 94 // Performs the configuration tasks specified by |params|. |
| 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 ScheduleConfig( | |
91 syncable::ModelTypeSet types, | |
92 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source); | |
93 | 115 |
94 void ScheduleClearUserData(); | 116 void ScheduleClearUserData(); |
95 // If this is called before Start(), the cleanup is guaranteed to | |
96 // happen before the Start finishes. | |
97 // | |
98 // TODO(akalin): Figure out how to test this. | |
99 void ScheduleCleanupDisabledTypes(); | |
100 | 117 |
101 // Change status of notifications in the SyncSessionContext. | 118 // Change status of notifications in the SyncSessionContext. |
102 void set_notifications_enabled(bool notifications_enabled); | 119 void set_notifications_enabled(bool notifications_enabled); |
103 | 120 |
104 base::TimeDelta sessions_commit_delay() const; | 121 base::TimeDelta sessions_commit_delay() const; |
105 | 122 |
106 // DDOS avoidance function. Calculates how long we should wait before trying | 123 // DDOS avoidance function. Calculates how long we should wait before trying |
107 // again after a failed sync attempt, where the last delay was |base_delay|. | 124 // again after a failed sync attempt, where the last delay was |base_delay|. |
108 // TODO(tim): Look at URLRequestThrottlerEntryInterface. | 125 // TODO(tim): Look at URLRequestThrottlerEntryInterface. |
109 static base::TimeDelta GetRecommendedDelay(const base::TimeDelta& base_delay); | 126 static base::TimeDelta GetRecommendedDelay(const base::TimeDelta& base_delay); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 SyncSessionJob(SyncSessionJobPurpose purpose, base::TimeTicks start, | 181 SyncSessionJob(SyncSessionJobPurpose purpose, base::TimeTicks start, |
165 linked_ptr<sessions::SyncSession> session, bool is_canary_job, | 182 linked_ptr<sessions::SyncSession> session, bool is_canary_job, |
166 const tracked_objects::Location& nudge_location); | 183 const tracked_objects::Location& nudge_location); |
167 ~SyncSessionJob(); | 184 ~SyncSessionJob(); |
168 static const char* GetPurposeString(SyncSessionJobPurpose purpose); | 185 static const char* GetPurposeString(SyncSessionJobPurpose purpose); |
169 | 186 |
170 SyncSessionJobPurpose purpose; | 187 SyncSessionJobPurpose purpose; |
171 base::TimeTicks scheduled_start; | 188 base::TimeTicks scheduled_start; |
172 linked_ptr<sessions::SyncSession> session; | 189 linked_ptr<sessions::SyncSession> session; |
173 bool is_canary_job; | 190 bool is_canary_job; |
| 191 ConfigureParams config_params; |
174 | 192 |
175 // This is the location the job came from. Used for debugging. | 193 // This is the location the job came from. Used for debugging. |
176 // In case of multiple nudges getting coalesced this stores the | 194 // In case of multiple nudges getting coalesced this stores the |
177 // first location that came in. | 195 // first location that came in. |
178 tracked_objects::Location from_here; | 196 tracked_objects::Location from_here; |
179 }; | 197 }; |
180 friend class SyncSchedulerTest; | 198 friend class SyncSchedulerTest; |
181 friend class SyncSchedulerWhiteboxTest; | 199 friend class SyncSchedulerWhiteboxTest; |
182 friend class SyncerTest; | 200 friend class SyncerTest; |
183 | 201 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 JobProcessDecision DecideWhileInWaitInterval(const SyncSessionJob& job); | 321 JobProcessDecision DecideWhileInWaitInterval(const SyncSessionJob& job); |
304 | 322 |
305 // Saves the job for future execution. Note: It drops all the poll jobs. | 323 // Saves the job for future execution. Note: It drops all the poll jobs. |
306 void SaveJob(const SyncSessionJob& job); | 324 void SaveJob(const SyncSessionJob& job); |
307 | 325 |
308 // Coalesces the current job with the pending nudge. | 326 // Coalesces the current job with the pending nudge. |
309 void InitOrCoalescePendingJob(const SyncSessionJob& job); | 327 void InitOrCoalescePendingJob(const SyncSessionJob& job); |
310 | 328 |
311 // 'Impl' here refers to real implementation of public functions, running on | 329 // 'Impl' here refers to real implementation of public functions, running on |
312 // |thread_|. | 330 // |thread_|. |
313 void StartImpl(Mode mode, const base::Closure& callback); | 331 void StartImpl(Mode mode); |
314 void StopImpl(const base::Closure& callback); | 332 void StopImpl(const base::Closure& callback); |
315 void ScheduleNudgeImpl( | 333 void ScheduleNudgeImpl( |
316 const base::TimeDelta& delay, | 334 const base::TimeDelta& delay, |
317 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, | 335 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, |
318 const syncable::ModelTypePayloadMap& types_with_payloads, | 336 const syncable::ModelTypePayloadMap& types_with_payloads, |
319 bool is_canary_job, const tracked_objects::Location& nudge_location); | 337 bool is_canary_job, const tracked_objects::Location& nudge_location); |
320 void ScheduleConfigImpl(const ModelSafeRoutingInfo& routing_info, | 338 void ScheduleConfigImpl(const ModelSafeRoutingInfo& routing_info, |
321 const std::vector<ModelSafeWorker*>& workers, | 339 const std::vector<ModelSafeWorker*>& workers, |
322 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source); | 340 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source); |
323 void ScheduleClearUserDataImpl(); | 341 void ScheduleClearUserDataImpl(); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 scoped_ptr<Syncer> syncer_; | 428 scoped_ptr<Syncer> syncer_; |
411 | 429 |
412 sessions::SyncSessionContext *session_context_; | 430 sessions::SyncSessionContext *session_context_; |
413 | 431 |
414 DISALLOW_COPY_AND_ASSIGN(SyncScheduler); | 432 DISALLOW_COPY_AND_ASSIGN(SyncScheduler); |
415 }; | 433 }; |
416 | 434 |
417 } // namespace browser_sync | 435 } // namespace browser_sync |
418 | 436 |
419 #endif // SYNC_ENGINE_SYNC_SCHEDULER_H_ | 437 #endif // SYNC_ENGINE_SYNC_SCHEDULER_H_ |
OLD | NEW |