| 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 26 matching lines...) Expand all Loading... |
| 37 struct ServerConnectionEvent; | 37 struct ServerConnectionEvent; |
| 38 | 38 |
| 39 struct ConfigurationParams { | 39 struct ConfigurationParams { |
| 40 enum KeystoreKeyStatus { | 40 enum KeystoreKeyStatus { |
| 41 KEYSTORE_KEY_UNNECESSARY, | 41 KEYSTORE_KEY_UNNECESSARY, |
| 42 KEYSTORE_KEY_NEEDED | 42 KEYSTORE_KEY_NEEDED |
| 43 }; | 43 }; |
| 44 ConfigurationParams(); | 44 ConfigurationParams(); |
| 45 ConfigurationParams( | 45 ConfigurationParams( |
| 46 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& source, | 46 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& source, |
| 47 const syncer::ModelTypeSet& types_to_download, | 47 const ModelTypeSet& types_to_download, |
| 48 const syncer::ModelSafeRoutingInfo& routing_info, | 48 const ModelSafeRoutingInfo& routing_info, |
| 49 KeystoreKeyStatus keystore_key_status, | 49 KeystoreKeyStatus keystore_key_status, |
| 50 const base::Closure& ready_task); | 50 const base::Closure& ready_task); |
| 51 ~ConfigurationParams(); | 51 ~ConfigurationParams(); |
| 52 | 52 |
| 53 // Source for the configuration. | 53 // Source for the configuration. |
| 54 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source; | 54 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source; |
| 55 // The types that should be downloaded. | 55 // The types that should be downloaded. |
| 56 syncer::ModelTypeSet types_to_download; | 56 ModelTypeSet types_to_download; |
| 57 // The new routing info (superset of types to be downloaded). | 57 // The new routing info (superset of types to be downloaded). |
| 58 ModelSafeRoutingInfo routing_info; | 58 ModelSafeRoutingInfo routing_info; |
| 59 // Whether we need to perform a GetKey command. | 59 // Whether we need to perform a GetKey command. |
| 60 KeystoreKeyStatus keystore_key_status; | 60 KeystoreKeyStatus keystore_key_status; |
| 61 // Callback to invoke on configuration completion. | 61 // Callback to invoke on configuration completion. |
| 62 base::Closure ready_task; | 62 base::Closure ready_task; |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 class SyncScheduler : public sessions::SyncSession::Delegate { | 65 class SyncScheduler : public sessions::SyncSession::Delegate { |
| 66 public: | 66 public: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // cancel all scheduled tasks. This function can be called from any thread, | 102 // 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 | 103 // and should in fact be called from a thread that isn't the sync loop to |
| 104 // allow preempting ongoing sync cycles. | 104 // allow preempting ongoing sync cycles. |
| 105 // Invokes |callback| from the sync loop once syncer is idle and all tasks | 105 // Invokes |callback| from the sync loop once syncer is idle and all tasks |
| 106 // are cancelled. | 106 // are cancelled. |
| 107 void RequestStop(const base::Closure& callback); | 107 void RequestStop(const base::Closure& callback); |
| 108 | 108 |
| 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 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 ModelTypePayloadMap& types_with_payloads, |
| 117 const tracked_objects::Location& nudge_location); | 117 const tracked_objects::Location& nudge_location); |
| 118 | 118 |
| 119 void CleanupDisabledTypes(); | 119 void CleanupDisabledTypes(); |
| 120 | 120 |
| 121 // Change status of notifications in the SyncSessionContext. | 121 // Change status of notifications in the SyncSessionContext. |
| 122 void set_notifications_enabled(bool notifications_enabled); | 122 void set_notifications_enabled(bool notifications_enabled); |
| 123 | 123 |
| 124 base::TimeDelta sessions_commit_delay() const; | 124 base::TimeDelta sessions_commit_delay() const; |
| 125 | 125 |
| 126 // DDOS avoidance function. Calculates how long we should wait before trying | 126 // DDOS avoidance function. Calculates how long we should wait before trying |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 | 324 |
| 325 // Coalesces the current job with the pending nudge. | 325 // Coalesces the current job with the pending nudge. |
| 326 void InitOrCoalescePendingJob(const SyncSessionJob& job); | 326 void InitOrCoalescePendingJob(const SyncSessionJob& job); |
| 327 | 327 |
| 328 // 'Impl' here refers to real implementation of public functions, running on | 328 // 'Impl' here refers to real implementation of public functions, running on |
| 329 // |thread_|. | 329 // |thread_|. |
| 330 void StopImpl(const base::Closure& callback); | 330 void StopImpl(const base::Closure& callback); |
| 331 void ScheduleNudgeImpl( | 331 void ScheduleNudgeImpl( |
| 332 const base::TimeDelta& delay, | 332 const base::TimeDelta& delay, |
| 333 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, | 333 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, |
| 334 const syncer::ModelTypePayloadMap& types_with_payloads, | 334 const ModelTypePayloadMap& types_with_payloads, |
| 335 bool is_canary_job, const tracked_objects::Location& nudge_location); | 335 bool is_canary_job, const tracked_objects::Location& nudge_location); |
| 336 | 336 |
| 337 // Returns true if the client is currently in exponential backoff. | 337 // Returns true if the client is currently in exponential backoff. |
| 338 bool IsBackingOff() const; | 338 bool IsBackingOff() const; |
| 339 | 339 |
| 340 // Helper to signal all listeners registered with |session_context_|. | 340 // Helper to signal all listeners registered with |session_context_|. |
| 341 void Notify(SyncEngineEvent::EventCause cause); | 341 void Notify(SyncEngineEvent::EventCause cause); |
| 342 | 342 |
| 343 // Callback to change backoff state. | 343 // Callback to change backoff state. |
| 344 void DoCanaryJob(); | 344 void DoCanaryJob(); |
| 345 void Unthrottle(); | 345 void Unthrottle(); |
| 346 | 346 |
| 347 // Executes the pending job. Called whenever an event occurs that may | 347 // Executes the pending job. Called whenever an event occurs that may |
| 348 // change conditions permitting a job to run. Like when network connection is | 348 // change conditions permitting a job to run. Like when network connection is |
| 349 // re-established, mode changes etc. | 349 // re-established, mode changes etc. |
| 350 void DoPendingJobIfPossible(bool is_canary_job); | 350 void DoPendingJobIfPossible(bool is_canary_job); |
| 351 | 351 |
| 352 // Called when the root cause of the current connection error is fixed. | 352 // Called when the root cause of the current connection error is fixed. |
| 353 void OnServerConnectionErrorFixed(); | 353 void OnServerConnectionErrorFixed(); |
| 354 | 354 |
| 355 // The pointer is owned by the caller. | 355 // The pointer is owned by the caller. |
| 356 syncer::sessions::SyncSession* CreateSyncSession( | 356 sessions::SyncSession* CreateSyncSession( |
| 357 const syncer::sessions::SyncSourceInfo& info); | 357 const sessions::SyncSourceInfo& info); |
| 358 | 358 |
| 359 // Creates a session for a poll and performs the sync. | 359 // Creates a session for a poll and performs the sync. |
| 360 void PollTimerCallback(); | 360 void PollTimerCallback(); |
| 361 | 361 |
| 362 // Used to update |connection_code_|, see below. | 362 // Used to update |connection_code_|, see below. |
| 363 void UpdateServerConnectionManagerStatus( | 363 void UpdateServerConnectionManagerStatus( |
| 364 HttpResponse::ServerConnectionCode code); | 364 HttpResponse::ServerConnectionCode code); |
| 365 | 365 |
| 366 // Called once the first time thread_ is started to broadcast an initial | 366 // Called once the first time thread_ is started to broadcast an initial |
| 367 // session snapshot containing data like initial_sync_ended. Important when | 367 // session snapshot containing data like initial_sync_ended. Important when |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 scoped_ptr<Syncer> syncer_; | 422 scoped_ptr<Syncer> syncer_; |
| 423 | 423 |
| 424 sessions::SyncSessionContext *session_context_; | 424 sessions::SyncSessionContext *session_context_; |
| 425 | 425 |
| 426 DISALLOW_COPY_AND_ASSIGN(SyncScheduler); | 426 DISALLOW_COPY_AND_ASSIGN(SyncScheduler); |
| 427 }; | 427 }; |
| 428 | 428 |
| 429 } // namespace syncer | 429 } // namespace syncer |
| 430 | 430 |
| 431 #endif // SYNC_ENGINE_SYNC_SCHEDULER_H_ | 431 #endif // SYNC_ENGINE_SYNC_SCHEDULER_H_ |
| OLD | NEW |