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 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 // The meat and potatoes. Both of these methods will post a delayed task | 109 // The meat and potatoes. Both of these methods will post a delayed task |
110 // to attempt the actual nudge (see ScheduleNudgeImpl). | 110 // to attempt the actual nudge (see ScheduleNudgeImpl). |
111 void ScheduleNudgeAsync(const base::TimeDelta& delay, NudgeSource source, | 111 void ScheduleNudgeAsync(const base::TimeDelta& delay, NudgeSource source, |
112 syncer::ModelTypeSet types, | 112 syncer::ModelTypeSet types, |
113 const tracked_objects::Location& nudge_location); | 113 const tracked_objects::Location& nudge_location); |
114 void ScheduleNudgeWithPayloadsAsync( | 114 void ScheduleNudgeWithPayloadsAsync( |
115 const base::TimeDelta& delay, NudgeSource source, | 115 const base::TimeDelta& delay, NudgeSource source, |
116 const syncer::ModelTypePayloadMap& types_with_payloads, | 116 const syncer::ModelTypePayloadMap& types_with_payloads, |
117 const tracked_objects::Location& nudge_location); | 117 const tracked_objects::Location& nudge_location); |
118 | 118 |
119 void CleanupDisabledTypes(); | |
120 | |
121 // Change status of notifications in the SyncSessionContext. | 119 // Change status of notifications in the SyncSessionContext. |
122 void set_notifications_enabled(bool notifications_enabled); | 120 void set_notifications_enabled(bool notifications_enabled); |
123 | 121 |
124 base::TimeDelta sessions_commit_delay() const; | 122 base::TimeDelta sessions_commit_delay() const; |
125 | 123 |
126 // DDOS avoidance function. Calculates how long we should wait before trying | 124 // 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|. | 125 // again after a failed sync attempt, where the last delay was |base_delay|. |
128 // TODO(tim): Look at URLRequestThrottlerEntryInterface. | 126 // TODO(tim): Look at URLRequestThrottlerEntryInterface. |
129 static base::TimeDelta GetRecommendedDelay(const base::TimeDelta& base_delay); | 127 static base::TimeDelta GetRecommendedDelay(const base::TimeDelta& base_delay); |
130 | 128 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 enum SyncSessionJobPurpose { | 161 enum SyncSessionJobPurpose { |
164 // Uninitialized state, should never be hit in practice. | 162 // Uninitialized state, should never be hit in practice. |
165 UNKNOWN = -1, | 163 UNKNOWN = -1, |
166 // Our poll timer schedules POLL jobs periodically based on a server | 164 // Our poll timer schedules POLL jobs periodically based on a server |
167 // assigned poll interval. | 165 // assigned poll interval. |
168 POLL, | 166 POLL, |
169 // A nudge task can come from a variety of components needing to force | 167 // A nudge task can come from a variety of components needing to force |
170 // a sync. The source is inferable from |session.source()|. | 168 // a sync. The source is inferable from |session.source()|. |
171 NUDGE, | 169 NUDGE, |
172 // Typically used for fetching updates for a subset of the enabled types | 170 // Typically used for fetching updates for a subset of the enabled types |
173 // during initial sync or reconfiguration. We don't run all steps of | 171 // during initial sync or reconfiguration. |
174 // the sync cycle for these (e.g. CleanupDisabledTypes is skipped). | |
175 CONFIGURATION, | 172 CONFIGURATION, |
176 // The user disabled some types and we have to clean up the data | |
177 // for those. | |
178 CLEANUP_DISABLED_TYPES, | |
179 }; | 173 }; |
180 SyncSessionJob(); | 174 SyncSessionJob(); |
181 SyncSessionJob(SyncSessionJobPurpose purpose, base::TimeTicks start, | 175 SyncSessionJob(SyncSessionJobPurpose purpose, base::TimeTicks start, |
182 linked_ptr<sessions::SyncSession> session, bool is_canary_job, | 176 linked_ptr<sessions::SyncSession> session, bool is_canary_job, |
183 const ConfigurationParams& config_params, | 177 const ConfigurationParams& config_params, |
184 const tracked_objects::Location& nudge_location); | 178 const tracked_objects::Location& nudge_location); |
185 ~SyncSessionJob(); | 179 ~SyncSessionJob(); |
186 static const char* GetPurposeString(SyncSessionJobPurpose purpose); | 180 static const char* GetPurposeString(SyncSessionJobPurpose purpose); |
187 | 181 |
188 SyncSessionJobPurpose purpose; | 182 SyncSessionJobPurpose purpose; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 // Helper to assemble a job and post a delayed task to sync. | 278 // Helper to assemble a job and post a delayed task to sync. |
285 void ScheduleSyncSessionJob(const SyncSessionJob& job); | 279 void ScheduleSyncSessionJob(const SyncSessionJob& job); |
286 | 280 |
287 // Invoke the Syncer to perform a sync. | 281 // Invoke the Syncer to perform a sync. |
288 void DoSyncSessionJob(const SyncSessionJob& job); | 282 void DoSyncSessionJob(const SyncSessionJob& job); |
289 | 283 |
290 // Called after the Syncer has performed the sync represented by |job|, to | 284 // Called after the Syncer has performed the sync represented by |job|, to |
291 // reset our state. | 285 // reset our state. |
292 void FinishSyncSessionJob(const SyncSessionJob& job); | 286 void FinishSyncSessionJob(const SyncSessionJob& job); |
293 | 287 |
294 // Record important state that might be needed in future syncs, such as which | |
295 // data types may require cleanup. | |
296 void UpdateCarryoverSessionState(const SyncSessionJob& old_job); | |
297 | |
298 // Helper to FinishSyncSessionJob to schedule the next sync operation. | 288 // Helper to FinishSyncSessionJob to schedule the next sync operation. |
299 void ScheduleNextSync(const SyncSessionJob& old_job); | 289 void ScheduleNextSync(const SyncSessionJob& old_job); |
300 | 290 |
301 // Helper to configure polling intervals. Used by Start and ScheduleNextSync. | 291 // Helper to configure polling intervals. Used by Start and ScheduleNextSync. |
302 void AdjustPolling(const SyncSessionJob* old_job); | 292 void AdjustPolling(const SyncSessionJob* old_job); |
303 | 293 |
304 // Helper to restart waiting with |wait_interval_|'s timer. | 294 // Helper to restart waiting with |wait_interval_|'s timer. |
305 void RestartWaiting(); | 295 void RestartWaiting(); |
306 | 296 |
307 // Helper to ScheduleNextSync in case of consecutive sync errors. | 297 // Helper to ScheduleNextSync in case of consecutive sync errors. |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 scoped_ptr<Syncer> syncer_; | 412 scoped_ptr<Syncer> syncer_; |
423 | 413 |
424 sessions::SyncSessionContext *session_context_; | 414 sessions::SyncSessionContext *session_context_; |
425 | 415 |
426 DISALLOW_COPY_AND_ASSIGN(SyncScheduler); | 416 DISALLOW_COPY_AND_ASSIGN(SyncScheduler); |
427 }; | 417 }; |
428 | 418 |
429 } // namespace syncer | 419 } // namespace syncer |
430 | 420 |
431 #endif // SYNC_ENGINE_SYNC_SCHEDULER_H_ | 421 #endif // SYNC_ENGINE_SYNC_SCHEDULER_H_ |
OLD | NEW |