| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 private: | 87 private: |
| 88 enum JobProcessDecision { | 88 enum JobProcessDecision { |
| 89 // Indicates we should continue with the current job. | 89 // Indicates we should continue with the current job. |
| 90 CONTINUE, | 90 CONTINUE, |
| 91 // Indicates that we should save it to be processed later. | 91 // Indicates that we should save it to be processed later. |
| 92 SAVE, | 92 SAVE, |
| 93 // Indicates we should drop this job. | 93 // Indicates we should drop this job. |
| 94 DROP, | 94 DROP, |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 enum JobPriority { |
| 98 // Non-canary jobs respect exponential backoff. |
| 99 NORMAL_PRIORITY, |
| 100 // Canary jobs bypass exponential backoff, so use with extreme caution. |
| 101 CANARY_PRIORITY |
| 102 }; |
| 103 |
| 97 friend class SyncSchedulerTest; | 104 friend class SyncSchedulerTest; |
| 98 friend class SyncSchedulerWhiteboxTest; | 105 friend class SyncSchedulerWhiteboxTest; |
| 99 friend class SyncerTest; | 106 friend class SyncerTest; |
| 100 | 107 |
| 101 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, | 108 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, |
| 102 DropNudgeWhileExponentialBackOff); | 109 DropNudgeWhileExponentialBackOff); |
| 103 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, SaveNudge); | 110 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, SaveNudge); |
| 104 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, | 111 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, |
| 105 SaveNudgeWhileTypeThrottled); | 112 SaveNudgeWhileTypeThrottled); |
| 106 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, ContinueNudge); | 113 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, ContinueNudge); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 void PostDelayedTask(const tracked_objects::Location& from_here, | 172 void PostDelayedTask(const tracked_objects::Location& from_here, |
| 166 const char* name, | 173 const char* name, |
| 167 const base::Closure& task, | 174 const base::Closure& task, |
| 168 base::TimeDelta delay); | 175 base::TimeDelta delay); |
| 169 | 176 |
| 170 // Helper to assemble a job and post a delayed task to sync. | 177 // Helper to assemble a job and post a delayed task to sync. |
| 171 void ScheduleSyncSessionJob(const tracked_objects::Location& loc, | 178 void ScheduleSyncSessionJob(const tracked_objects::Location& loc, |
| 172 scoped_ptr<SyncSessionJob> job); | 179 scoped_ptr<SyncSessionJob> job); |
| 173 | 180 |
| 174 // Invoke the Syncer to perform a sync. | 181 // Invoke the Syncer to perform a sync. |
| 175 bool DoSyncSessionJob(scoped_ptr<SyncSessionJob> job); | 182 bool DoSyncSessionJob(scoped_ptr<SyncSessionJob> job, |
| 183 JobPriority priority); |
| 176 | 184 |
| 177 // Called after the Syncer has performed the sync represented by |job|, to | 185 // Called after the Syncer has performed the sync represented by |job|, to |
| 178 // reset our state. |exited_prematurely| is true if the Syncer did not | 186 // reset our state. |exited_prematurely| is true if the Syncer did not |
| 179 // cycle from job.start_step() to job.end_step(), likely because the | 187 // cycle from job.start_step() to job.end_step(), likely because the |
| 180 // scheduler was forced to quit the job mid-way through. | 188 // scheduler was forced to quit the job mid-way through. |
| 181 bool FinishSyncSessionJob(scoped_ptr<SyncSessionJob> job, | 189 bool FinishSyncSessionJob(scoped_ptr<SyncSessionJob> job, |
| 182 bool exited_prematurely); | 190 bool exited_prematurely); |
| 183 | 191 |
| 184 // Helper to FinishSyncSessionJob to schedule the next sync operation. | 192 // Helper to FinishSyncSessionJob to schedule the next sync operation. |
| 185 // |succeeded| carries the return value of |old_job|->Finish. | 193 // |succeeded| carries the return value of |old_job|->Finish. |
| 186 void ScheduleNextSync(scoped_ptr<SyncSessionJob> finished_job, | 194 void ScheduleNextSync(scoped_ptr<SyncSessionJob> finished_job, |
| 187 bool succeeded); | 195 bool succeeded); |
| 188 | 196 |
| 189 // Helper to configure polling intervals. Used by Start and ScheduleNextSync. | 197 // Helper to configure polling intervals. Used by Start and ScheduleNextSync. |
| 190 void AdjustPolling(const SyncSessionJob* old_job); | 198 void AdjustPolling(const SyncSessionJob* old_job); |
| 191 | 199 |
| 192 // Helper to restart waiting with |wait_interval_|'s timer. | 200 // Helper to restart waiting with |wait_interval_|'s timer. |
| 193 void RestartWaiting(scoped_ptr<SyncSessionJob> job); | 201 void RestartWaiting(scoped_ptr<SyncSessionJob> job); |
| 194 | 202 |
| 195 // Helper to ScheduleNextSync in case of consecutive sync errors. | 203 // Helper to ScheduleNextSync in case of consecutive sync errors. |
| 196 void HandleContinuationError(scoped_ptr<SyncSessionJob> old_job); | 204 void HandleContinuationError(scoped_ptr<SyncSessionJob> old_job); |
| 197 | 205 |
| 198 // Decide whether we should CONTINUE, SAVE or DROP the job. | 206 // Decide whether we should CONTINUE, SAVE or DROP the job. |
| 199 JobProcessDecision DecideOnJob(const SyncSessionJob& job); | 207 JobProcessDecision DecideOnJob(const SyncSessionJob& job, |
| 208 JobPriority priority); |
| 200 | 209 |
| 201 // If DecideOnJob decides that |job| should be SAVEd, this function will | 210 // If DecideOnJob decides that |job| should be SAVEd, this function will |
| 202 // carry out the task of actually "saving" (or coalescing) the job. | 211 // carry out the task of actually "saving" (or coalescing) the job. |
| 203 void HandleSaveJobDecision(scoped_ptr<SyncSessionJob> job); | 212 void HandleSaveJobDecision(scoped_ptr<SyncSessionJob> job); |
| 204 | 213 |
| 205 // Decide on whether to CONTINUE, SAVE or DROP the job when we are in | 214 // Decide on whether to CONTINUE, SAVE or DROP the job when we are in |
| 206 // backoff mode. | 215 // backoff mode. |
| 207 JobProcessDecision DecideWhileInWaitInterval(const SyncSessionJob& job); | 216 JobProcessDecision DecideWhileInWaitInterval(const SyncSessionJob& job, |
| 217 JobPriority priority); |
| 208 | 218 |
| 209 // 'Impl' here refers to real implementation of public functions, running on | 219 // 'Impl' here refers to real implementation of public functions, running on |
| 210 // |thread_|. | 220 // |thread_|. |
| 211 void StopImpl(const base::Closure& callback); | 221 void StopImpl(const base::Closure& callback); |
| 212 void ScheduleNudgeImpl( | 222 void ScheduleNudgeImpl( |
| 213 const base::TimeDelta& delay, | 223 const base::TimeDelta& delay, |
| 214 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, | 224 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, |
| 215 const ModelTypeInvalidationMap& invalidation_map, | 225 const ModelTypeInvalidationMap& invalidation_map, |
| 216 const tracked_objects::Location& nudge_location); | 226 const tracked_objects::Location& nudge_location); |
| 217 | 227 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 // take place during a sync cycle. We call this out because such violations | 343 // take place during a sync cycle. We call this out because such violations |
| 334 // could result in tight sync loops hitting sync servers. | 344 // could result in tight sync loops hitting sync servers. |
| 335 bool no_scheduling_allowed_; | 345 bool no_scheduling_allowed_; |
| 336 | 346 |
| 337 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl); | 347 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl); |
| 338 }; | 348 }; |
| 339 | 349 |
| 340 } // namespace syncer | 350 } // namespace syncer |
| 341 | 351 |
| 342 #endif // SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ | 352 #endif // SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ |
| OLD | NEW |