| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #ifndef SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ | 5 #ifndef SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ |
| 6 #define SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ | 6 #define SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // Helpers that log before posting to |sync_loop_|. These will only post | 162 // Helpers that log before posting to |sync_loop_|. These will only post |
| 163 // the task in between calls to Start/Stop. | 163 // the task in between calls to Start/Stop. |
| 164 void PostTask(const tracked_objects::Location& from_here, | 164 void PostTask(const tracked_objects::Location& from_here, |
| 165 const char* name, | 165 const char* name, |
| 166 const base::Closure& task); | 166 const base::Closure& task); |
| 167 void PostDelayedTask(const tracked_objects::Location& from_here, | 167 void PostDelayedTask(const tracked_objects::Location& from_here, |
| 168 const char* name, | 168 const char* name, |
| 169 const base::Closure& task, | 169 const base::Closure& task, |
| 170 base::TimeDelta delay); | 170 base::TimeDelta delay); |
| 171 | 171 |
| 172 // Helper to assemble a job and post a delayed task to sync. | 172 // Invoke the Syncer to perform a non-poll job. |
| 173 void ScheduleSyncSessionJob(const tracked_objects::Location& loc, | |
| 174 scoped_ptr<SyncSessionJob> job); | |
| 175 | |
| 176 // Invoke the Syncer to perform a sync. | |
| 177 bool DoSyncSessionJob(scoped_ptr<SyncSessionJob> job, | 173 bool DoSyncSessionJob(scoped_ptr<SyncSessionJob> job, |
| 178 JobPriority priority); | 174 JobPriority priority); |
| 179 | 175 |
| 176 // Returns whether or not it's safe to run a poll job at this time. |
| 177 bool ShouldPoll(); |
| 178 |
| 179 // Invoke the Syncer to perform a poll job. |
| 180 void DoPollSyncSessionJob(scoped_ptr<SyncSessionJob> job); |
| 181 |
| 180 // Called after the Syncer has performed the sync represented by |job|, to | 182 // Called after the Syncer has performed the sync represented by |job|, to |
| 181 // reset our state. |exited_prematurely| is true if the Syncer did not | 183 // reset our state. |exited_prematurely| is true if the Syncer did not |
| 182 // cycle from job.start_step() to job.end_step(), likely because the | 184 // cycle from job.start_step() to job.end_step(), likely because the |
| 183 // scheduler was forced to quit the job mid-way through. | 185 // scheduler was forced to quit the job mid-way through. |
| 184 bool FinishSyncSessionJob(scoped_ptr<SyncSessionJob> job, | 186 bool FinishSyncSessionJob(SyncSessionJob* job, |
| 185 bool exited_prematurely); | 187 bool exited_prematurely); |
| 186 | 188 |
| 187 // Helper to FinishSyncSessionJob to schedule the next sync operation. | 189 // Helper to schedule retries of a failed configure or nudge job. |
| 188 // |succeeded| carries the return value of |old_job|->Finish. | 190 void ScheduleNextSync(scoped_ptr<SyncSessionJob> finished_job); |
| 189 void ScheduleNextSync(scoped_ptr<SyncSessionJob> finished_job, | |
| 190 bool succeeded); | |
| 191 | 191 |
| 192 // Helper to configure polling intervals. Used by Start and ScheduleNextSync. | 192 // Helper to configure polling intervals. Used by Start and ScheduleNextSync. |
| 193 void AdjustPolling(const SyncSessionJob* old_job); | 193 void AdjustPolling(const SyncSessionJob* old_job); |
| 194 | 194 |
| 195 // Helper to restart waiting with |wait_interval_|'s timer. | 195 // Helper to restart waiting with |wait_interval_|'s timer. |
| 196 void RestartWaiting(scoped_ptr<SyncSessionJob> job); | 196 void RestartWaiting(scoped_ptr<SyncSessionJob> job); |
| 197 | 197 |
| 198 // Helper to ScheduleNextSync in case of consecutive sync errors. | 198 // Helper to ScheduleNextSync in case of consecutive sync errors. |
| 199 void HandleContinuationError(scoped_ptr<SyncSessionJob> old_job); | 199 void HandleContinuationError(scoped_ptr<SyncSessionJob> old_job); |
| 200 | 200 |
| 201 // Decide whether we should CONTINUE, SAVE or DROP the job. | 201 // Decide whether we should CONTINUE, SAVE or DROP the job. |
| 202 JobProcessDecision DecideOnJob(const SyncSessionJob& job, | 202 JobProcessDecision DecideOnJob(const SyncSessionJob& job, |
| 203 JobPriority priority); | 203 JobPriority priority); |
| 204 | 204 |
| 205 // If DecideOnJob decides that |job| should be SAVEd, this function will | 205 // If DecideOnJob decides that |job| should be SAVEd, this function will |
| 206 // carry out the task of actually "saving" (or coalescing) the job. | 206 // carry out the task of actually "saving" (or coalescing) the job. |
| 207 void HandleSaveJobDecision(scoped_ptr<SyncSessionJob> job); | 207 void HandleSaveJobDecision(scoped_ptr<SyncSessionJob> job); |
| 208 | 208 |
| 209 // Decide on whether to CONTINUE, SAVE or DROP the job when we are in | 209 // Decide on whether to CONTINUE, SAVE or DROP the job when we are in |
| 210 // backoff mode. | 210 // backoff mode. |
| 211 JobProcessDecision DecideWhileInWaitInterval(const SyncSessionJob& job, | 211 JobProcessDecision DecideWhileInWaitInterval(const SyncSessionJob& job, |
| 212 JobPriority priority); | 212 JobPriority priority); |
| 213 | 213 |
| 214 // 'Impl' here refers to real implementation of public functions, running on | 214 // 'Impl' here refers to real implementation of public functions, running on |
| 215 // |thread_|. | 215 // |thread_|. |
| 216 void StopImpl(const base::Closure& callback); | 216 void StopImpl(const base::Closure& callback); |
| 217 |
| 218 // If the scheduler's current state supports it, this will create a job based |
| 219 // on the passed in parameters and coalesce it with any other pending jobs, |
| 220 // then post a delayed task to run it. It may also choose to drop the job or |
| 221 // save it for later, depending on the scheduler's current state. |
| 217 void ScheduleNudgeImpl( | 222 void ScheduleNudgeImpl( |
| 218 const base::TimeDelta& delay, | 223 const base::TimeDelta& delay, |
| 219 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, | 224 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, |
| 220 const ModelTypeInvalidationMap& invalidation_map, | 225 const ModelTypeInvalidationMap& invalidation_map, |
| 221 const tracked_objects::Location& nudge_location); | 226 const tracked_objects::Location& nudge_location); |
| 222 | 227 |
| 223 // Returns true if the client is currently in exponential backoff. | 228 // Returns true if the client is currently in exponential backoff. |
| 224 bool IsBackingOff() const; | 229 bool IsBackingOff() const; |
| 225 | 230 |
| 226 // Helper to signal all listeners registered with |session_context_|. | 231 // Helper to signal all listeners registered with |session_context_|. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 // take place during a sync cycle. We call this out because such violations | 341 // take place during a sync cycle. We call this out because such violations |
| 337 // could result in tight sync loops hitting sync servers. | 342 // could result in tight sync loops hitting sync servers. |
| 338 bool no_scheduling_allowed_; | 343 bool no_scheduling_allowed_; |
| 339 | 344 |
| 340 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl); | 345 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl); |
| 341 }; | 346 }; |
| 342 | 347 |
| 343 } // namespace syncer | 348 } // namespace syncer |
| 344 | 349 |
| 345 #endif // SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ | 350 #endif // SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ |
| OLD | NEW |