Chromium Code Reviews| 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 ConfigureParams { | |
|
tim (not reviewing)
2012/06/14 00:26:53
nit - ConfigurationParams, to match method
Nicolas Zea
2012/06/14 22:35:52
Done.
| |
| 41 ConfigureParams(); | |
| 42 ConfigureParams( | |
| 43 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& source, | |
| 44 const syncable::ModelTypeSet& types_to_config, | |
| 45 const browser_sync::ModelSafeRoutingInfo& routing_info, | |
| 46 bool need_encryption_key, | |
| 47 const base::Closure& ready_task); | |
| 48 ~ConfigureParams(); | |
| 49 | |
| 50 // Source for the configuration. | |
| 51 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source; | |
| 52 // The types that should be downloaded. | |
| 53 syncable::ModelTypeSet types_to_config; | |
| 54 // The new routing info (superset of types to be downloaded). | |
| 55 ModelSafeRoutingInfo routing_info; | |
| 56 // Whether we need to perform a GetKey command. | |
| 57 bool need_encryption_key; | |
| 58 // Callback to invoke on configuration completion. | |
| 59 base::Closure ready_task; | |
| 60 }; | |
| 61 | |
| 40 class SyncScheduler : public sessions::SyncSession::Delegate { | 62 class SyncScheduler : public sessions::SyncSession::Delegate { |
| 41 public: | 63 public: |
| 42 enum Mode { | 64 enum Mode { |
| 43 // In this mode, the thread only performs configuration tasks. This is | 65 // 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 | 66 // 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 | 67 // specific type only, and not continue syncing until we are moved into |
| 46 // normal mode. | 68 // normal mode. |
| 47 CONFIGURATION_MODE, | 69 CONFIGURATION_MODE, |
| 48 // Resumes polling and allows nudges, drops configuration tasks. Runs | 70 // Resumes polling and allows nudges, drops configuration tasks. Runs |
| 49 // through entire sync cycle. | 71 // through entire sync cycle. |
| 50 NORMAL_MODE, | 72 NORMAL_MODE, |
| 51 }; | 73 }; |
| 52 | 74 |
| 53 // All methods of SyncScheduler must be called on the same thread | 75 // All methods of SyncScheduler must be called on the same thread |
| 54 // (except for RequestEarlyExit()). | 76 // (except for RequestEarlyExit()). |
| 55 | 77 |
| 56 // |name| is a display string to identify the syncer thread. Takes | 78 // |name| is a display string to identify the syncer thread. Takes |
| 57 // |ownership of |syncer|. | 79 // |ownership of |syncer|. |
| 58 SyncScheduler(const std::string& name, | 80 SyncScheduler(const std::string& name, |
| 59 sessions::SyncSessionContext* context, Syncer* syncer); | 81 sessions::SyncSessionContext* context, Syncer* syncer); |
| 60 | 82 |
| 61 // Calls Stop(). | 83 // Calls Stop(). |
| 62 virtual ~SyncScheduler(); | 84 virtual ~SyncScheduler(); |
| 63 | 85 |
| 64 // Start the scheduler with the given mode. If the scheduler is | 86 // Start the scheduler with the given mode. If the scheduler is |
| 65 // already started, switch to the given mode, although some | 87 // already started, switch to the given mode, although some |
| 66 // scheduled tasks from the old mode may still run. If non-NULL, | 88 // scheduled tasks from the old mode may still run. |
| 67 // |callback| will be invoked when the mode has been changed to | 89 void Start(Mode mode); |
| 68 // |mode|. Takes ownership of |callback|. | 90 |
| 69 void Start(Mode mode, const base::Closure& callback); | 91 // Schedules the configuration task specified by |params|. Returns true if |
| 92 // the configuration task executed immediately, false if it had to be | |
| 93 // scheduled for a later attempt. |params.ready_task| is invoked whenever the | |
| 94 // configuration task executes. | |
| 95 // Note: must already be in CONFIGURATION mode. | |
| 96 bool ScheduleConfiguration(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. Both of these methods will post a delayed task | 106 // The meat and potatoes. Both of these methods will post a delayed task |
| 80 // to attempt the actual nudge (see ScheduleNudgeImpl). | 107 // to attempt the actual nudge (see ScheduleNudgeImpl). |
| 81 void ScheduleNudgeAsync(const base::TimeDelta& delay, NudgeSource source, | 108 void ScheduleNudgeAsync(const base::TimeDelta& delay, NudgeSource source, |
| 82 syncable::ModelTypeSet types, | 109 syncable::ModelTypeSet types, |
| 83 const tracked_objects::Location& nudge_location); | 110 const tracked_objects::Location& nudge_location); |
| 84 void ScheduleNudgeWithPayloadsAsync( | 111 void ScheduleNudgeWithPayloadsAsync( |
| 85 const base::TimeDelta& delay, NudgeSource source, | 112 const base::TimeDelta& delay, NudgeSource source, |
| 86 const syncable::ModelTypePayloadMap& types_with_payloads, | 113 const syncable::ModelTypePayloadMap& types_with_payloads, |
| 87 const tracked_objects::Location& nudge_location); | 114 const tracked_objects::Location& nudge_location); |
| 88 | 115 |
| 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 | 116 // TODO(tim): remove this. crbug.com/131336 |
| 98 void ClearUserData(); | 117 void ClearUserData(); |
| 99 | 118 |
| 100 void CleanupDisabledTypes(); | 119 void CleanupDisabledTypes(); |
| 101 | 120 |
| 102 // Change status of notifications in the SyncSessionContext. | 121 // Change status of notifications in the SyncSessionContext. |
| 103 void set_notifications_enabled(bool notifications_enabled); | 122 void set_notifications_enabled(bool notifications_enabled); |
| 104 | 123 |
| 105 base::TimeDelta sessions_commit_delay() const; | 124 base::TimeDelta sessions_commit_delay() const; |
| 106 | 125 |
| (...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 | 176 // during initial sync or reconfiguration. We don't run all steps of |
| 158 // the sync cycle for these (e.g. CleanupDisabledTypes is skipped). | 177 // the sync cycle for these (e.g. CleanupDisabledTypes is skipped). |
| 159 CONFIGURATION, | 178 CONFIGURATION, |
| 160 // The user disabled some types and we have to clean up the data | 179 // The user disabled some types and we have to clean up the data |
| 161 // for those. | 180 // for those. |
| 162 CLEANUP_DISABLED_TYPES, | 181 CLEANUP_DISABLED_TYPES, |
| 163 }; | 182 }; |
| 164 SyncSessionJob(); | 183 SyncSessionJob(); |
| 165 SyncSessionJob(SyncSessionJobPurpose purpose, base::TimeTicks start, | 184 SyncSessionJob(SyncSessionJobPurpose purpose, base::TimeTicks start, |
| 166 linked_ptr<sessions::SyncSession> session, bool is_canary_job, | 185 linked_ptr<sessions::SyncSession> session, bool is_canary_job, |
| 186 ConfigureParams config_params, | |
| 167 const tracked_objects::Location& nudge_location); | 187 const tracked_objects::Location& nudge_location); |
| 168 ~SyncSessionJob(); | 188 ~SyncSessionJob(); |
| 169 static const char* GetPurposeString(SyncSessionJobPurpose purpose); | 189 static const char* GetPurposeString(SyncSessionJobPurpose purpose); |
| 170 | 190 |
| 171 SyncSessionJobPurpose purpose; | 191 SyncSessionJobPurpose purpose; |
| 172 base::TimeTicks scheduled_start; | 192 base::TimeTicks scheduled_start; |
| 173 linked_ptr<sessions::SyncSession> session; | 193 linked_ptr<sessions::SyncSession> session; |
| 174 bool is_canary_job; | 194 bool is_canary_job; |
| 195 ConfigureParams config_params; | |
| 175 | 196 |
| 176 // This is the location the job came from. Used for debugging. | 197 // This is the location the job came from. Used for debugging. |
| 177 // In case of multiple nudges getting coalesced this stores the | 198 // In case of multiple nudges getting coalesced this stores the |
| 178 // first location that came in. | 199 // first location that came in. |
| 179 tracked_objects::Location from_here; | 200 tracked_objects::Location from_here; |
| 180 }; | 201 }; |
| 181 friend class SyncSchedulerTest; | 202 friend class SyncSchedulerTest; |
| 182 friend class SyncSchedulerWhiteboxTest; | 203 friend class SyncSchedulerWhiteboxTest; |
| 183 friend class SyncerTest; | 204 friend class SyncerTest; |
| 184 | 205 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 scoped_ptr<Syncer> syncer_; | 427 scoped_ptr<Syncer> syncer_; |
| 407 | 428 |
| 408 sessions::SyncSessionContext *session_context_; | 429 sessions::SyncSessionContext *session_context_; |
| 409 | 430 |
| 410 DISALLOW_COPY_AND_ASSIGN(SyncScheduler); | 431 DISALLOW_COPY_AND_ASSIGN(SyncScheduler); |
| 411 }; | 432 }; |
| 412 | 433 |
| 413 } // namespace browser_sync | 434 } // namespace browser_sync |
| 414 | 435 |
| 415 #endif // SYNC_ENGINE_SYNC_SCHEDULER_H_ | 436 #endif // SYNC_ENGINE_SYNC_SCHEDULER_H_ |
| OLD | NEW |