Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 run the syncer on a thread. | 5 // A class to run the syncer on a thread. |
| 6 #ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD2_H_ | 6 #ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD2_H_ |
| 7 #define CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD2_H_ | 7 #define CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD2_H_ |
| 8 #pragma once | 8 #pragma once |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 // In this mode, the thread only performs configuration tasks. This is | 36 // In this mode, the thread only performs configuration tasks. This is |
| 37 // designed to make the case where we want to download updates for a | 37 // designed to make the case where we want to download updates for a |
| 38 // specific type only, and not continue syncing until we are moved into | 38 // specific type only, and not continue syncing until we are moved into |
| 39 // normal mode. | 39 // normal mode. |
| 40 CONFIGURATION_MODE, | 40 CONFIGURATION_MODE, |
| 41 // Resumes polling and allows nudges, drops configuration tasks. Runs | 41 // Resumes polling and allows nudges, drops configuration tasks. Runs |
| 42 // through entire sync cycle. | 42 // through entire sync cycle. |
| 43 NORMAL_MODE, | 43 NORMAL_MODE, |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 enum JobProcessDecision { | |
| 47 // Indicates we should continue with the current job. | |
| 48 CONTINUE, | |
| 49 // Indicates that we should save it to be processed later. | |
| 50 SAVE, | |
| 51 // Indicates we should drop this job. | |
| 52 DROP, | |
| 53 }; | |
| 54 | |
| 46 // Takes ownership of both |context| and |syncer|. | 55 // Takes ownership of both |context| and |syncer|. |
| 47 SyncerThread(sessions::SyncSessionContext* context, Syncer* syncer); | 56 SyncerThread(sessions::SyncSessionContext* context, Syncer* syncer); |
| 48 virtual ~SyncerThread(); | 57 virtual ~SyncerThread(); |
| 49 | 58 |
| 50 typedef Callback0::Type ModeChangeCallback; | 59 typedef Callback0::Type ModeChangeCallback; |
| 51 | 60 |
| 52 // Change the mode of operation. | 61 // Change the mode of operation. |
| 53 // We don't use a lock when changing modes, so we won't cause currently | 62 // We don't use a lock when changing modes, so we won't cause currently |
| 54 // scheduled jobs to adhere to the new mode. We could protect it, but it | 63 // scheduled jobs to adhere to the new mode. We could protect it, but it |
| 55 // doesn't buy very much as a) a session could already be in progress and it | 64 // doesn't buy very much as a) a session could already be in progress and it |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 | 163 |
| 155 // Helper to FinishSyncSessionJob to schedule the next sync operation. | 164 // Helper to FinishSyncSessionJob to schedule the next sync operation. |
| 156 void ScheduleNextSync(const SyncSessionJob& old_job); | 165 void ScheduleNextSync(const SyncSessionJob& old_job); |
| 157 | 166 |
| 158 // Helper to configure polling intervals. Used by Start and ScheduleNextSync. | 167 // Helper to configure polling intervals. Used by Start and ScheduleNextSync. |
| 159 void AdjustPolling(const SyncSessionJob* old_job); | 168 void AdjustPolling(const SyncSessionJob* old_job); |
| 160 | 169 |
| 161 // Helper to ScheduleNextSync in case of consecutive sync errors. | 170 // Helper to ScheduleNextSync in case of consecutive sync errors. |
| 162 void HandleConsecutiveContinuationError(const SyncSessionJob& old_job); | 171 void HandleConsecutiveContinuationError(const SyncSessionJob& old_job); |
| 163 | 172 |
| 164 // Determines if it is legal to run a sync job for |purpose| at | 173 // Determines if it is legal to run a sync |job|. |
| 165 // |scheduled_start|. This checks current operational mode, backoff or | 174 // This checks current operational mode, backoff or |
| 166 // throttling, freshness (so we don't make redundant syncs), and connection. | 175 // throttling, freshness (so we don't make redundant syncs), and connection. |
| 167 bool ShouldRunJob(SyncSessionJobPurpose purpose, | 176 bool ShouldRunJob(const SyncSessionJob& job); |
| 168 const base::TimeTicks& scheduled_start); | 177 |
| 178 // Saves the job for future executio. | |
| 179 void SaveJob(const SyncSessionJob& job); | |
| 180 | |
| 181 // Decide on whether to run, save or discard the job when we are in | |
| 182 // back off mode. | |
| 183 JobProcessDecision DecideOnJobWhileBackingOff(const SyncSessionJob& job); | |
| 184 | |
| 185 // Decide whether we should run, save or discard the job. | |
| 186 JobProcessDecision ProcessJob(const SyncSessionJob& job); | |
| 187 | |
| 188 // Coalesces the current job with the pending nudge. | |
| 189 void CoalescePendingNudge(const SyncSessionJob& job); | |
| 169 | 190 |
| 170 // 'Impl' here refers to real implementation of public functions, running on | 191 // 'Impl' here refers to real implementation of public functions, running on |
| 171 // |thread_|. | 192 // |thread_|. |
| 172 void StartImpl(Mode mode, linked_ptr<ModeChangeCallback> callback); | 193 void StartImpl(Mode mode, linked_ptr<ModeChangeCallback> callback); |
| 173 void ScheduleNudgeImpl( | 194 void ScheduleNudgeImpl( |
| 174 const base::TimeDelta& delay, | 195 const base::TimeDelta& delay, |
| 175 NudgeSource source, | 196 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, |
| 176 const syncable::ModelTypePayloadMap& types_with_payloads, | 197 const syncable::ModelTypePayloadMap& types_with_payloads, |
| 177 const tracked_objects::Location& nudge_location); | 198 bool is_canary_job, const tracked_objects::Location& nudge_location); |
| 178 void ScheduleConfigImpl(const ModelSafeRoutingInfo& routing_info, | 199 void ScheduleConfigImpl(const ModelSafeRoutingInfo& routing_info, |
| 179 const std::vector<ModelSafeWorker*>& workers); | 200 const std::vector<ModelSafeWorker*>& workers, |
| 201 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source); | |
| 180 void ScheduleClearUserDataImpl(); | 202 void ScheduleClearUserDataImpl(); |
| 181 | 203 |
| 182 // Returns true if the client is currently in exponential backoff. | 204 // Returns true if the client is currently in exponential backoff. |
| 183 bool IsBackingOff() const; | 205 bool IsBackingOff() const; |
| 184 | 206 |
| 185 // Helper to signal all listeners registered with |session_context_|. | 207 // Helper to signal all listeners registered with |session_context_|. |
| 186 void Notify(SyncEngineEvent::EventCause cause); | 208 void Notify(SyncEngineEvent::EventCause cause); |
| 187 | 209 |
| 188 // Callback to change backoff state. | 210 // Callback to change backoff state. |
| 189 void DoCanaryJob(); | 211 void DoCanaryJob(); |
| 190 void Unthrottle(); | 212 void Unthrottle(); |
| 191 | 213 |
| 214 void ScheduleCanaryJob(SyncSessionJob* job); | |
| 215 | |
| 192 // Creates a session for a poll and performs the sync. | 216 // Creates a session for a poll and performs the sync. |
| 193 void PollTimerCallback(); | 217 void PollTimerCallback(); |
| 194 | 218 |
| 195 // Assign |start| and |end| to appropriate SyncerStep values for the | 219 // Assign |start| and |end| to appropriate SyncerStep values for the |
| 196 // specified |purpose|. | 220 // specified |purpose|. |
| 197 void SetSyncerStepsForPurpose(SyncSessionJobPurpose purpose, | 221 void SetSyncerStepsForPurpose(SyncSessionJobPurpose purpose, |
| 198 SyncerStep* start, | 222 SyncerStep* start, |
| 199 SyncerStep* end); | 223 SyncerStep* end); |
| 200 | 224 |
| 201 // Initializes the hookup between the ServerConnectionManager and us. | 225 // Initializes the hookup between the ServerConnectionManager and us. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 // Current wait state. Null if we're not in backoff and not throttled. | 260 // Current wait state. Null if we're not in backoff and not throttled. |
| 237 scoped_ptr<WaitInterval> wait_interval_; | 261 scoped_ptr<WaitInterval> wait_interval_; |
| 238 | 262 |
| 239 scoped_ptr<DelayProvider> delay_provider_; | 263 scoped_ptr<DelayProvider> delay_provider_; |
| 240 | 264 |
| 241 // Invoked to run through the sync cycle. | 265 // Invoked to run through the sync cycle. |
| 242 scoped_ptr<Syncer> syncer_; | 266 scoped_ptr<Syncer> syncer_; |
| 243 | 267 |
| 244 scoped_ptr<sessions::SyncSessionContext> session_context_; | 268 scoped_ptr<sessions::SyncSessionContext> session_context_; |
| 245 | 269 |
| 270 bool saved_nudge_; | |
|
tim (not reviewing)
2011/04/08 18:08:04
think you meant to remove these two fields.
lipalani1
2011/04/08 18:40:23
Done.
| |
| 271 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource saved_source_; | |
| 272 | |
| 246 DISALLOW_COPY_AND_ASSIGN(SyncerThread); | 273 DISALLOW_COPY_AND_ASSIGN(SyncerThread); |
| 247 }; | 274 }; |
| 248 | 275 |
| 249 } // namespace s3 | 276 } // namespace s3 |
| 250 | 277 |
| 251 } // namespace browser_sync | 278 } // namespace browser_sync |
| 252 | 279 |
| 253 // The SyncerThread manages its own internal thread and thus outlives it. We | 280 // The SyncerThread manages its own internal thread and thus outlives it. We |
| 254 // don't need refcounting for posting tasks to this internal thread. | 281 // don't need refcounting for posting tasks to this internal thread. |
| 255 DISABLE_RUNNABLE_METHOD_REFCOUNT(browser_sync::s3::SyncerThread); | 282 DISABLE_RUNNABLE_METHOD_REFCOUNT(browser_sync::s3::SyncerThread); |
| 256 | 283 |
| 257 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD2_H_ | 284 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD2_H_ |
| OLD | NEW |