OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_INTERNAL_API_PUBLIC_ATTACHMENTS_TASK_QUEUE_H_ | 5 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_TASK_QUEUE_H_ |
6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_TASK_QUEUE_H_ | 6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_TASK_QUEUE_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 115 |
116 // Cancel |task|. | 116 // Cancel |task|. |
117 // | 117 // |
118 // |task| is removed from the queue and will not be retried. Does not affect | 118 // |task| is removed from the queue and will not be retried. Does not affect |
119 // the backoff delay. | 119 // the backoff delay. |
120 // | 120 // |
121 // May only be called after the HandleTaskCallback has been invoked with | 121 // May only be called after the HandleTaskCallback has been invoked with |
122 // |task|. | 122 // |task|. |
123 void Cancel(const T& task); | 123 void Cancel(const T& task); |
124 | 124 |
125 private: | 125 // Reset any backoff delay and resume dispatching of tasks. |
126 FRIEND_TEST_ALL_PREFIXES(TaskQueueTest, Retry); | 126 // |
| 127 // Useful for when you know the cause of previous failures has been resolved |
| 128 // and you want don't want to wait for the accumulated backoff delay to |
| 129 // elapse. |
| 130 void ResetBackoff(); |
127 | 131 |
128 // Use |timer| for scheduled events. | 132 // Use |timer| for scheduled events. |
129 // | 133 // |
130 // Used in tests. See also MockTimer. | 134 // Used in tests. See also MockTimer. |
131 void SetTimerForTest(scoped_ptr<base::Timer> timer); | 135 void SetTimerForTest(scoped_ptr<base::Timer> timer); |
| 136 |
| 137 private: |
132 void FinishTask(const T& task); | 138 void FinishTask(const T& task); |
133 void ScheduleDispatch(); | 139 void ScheduleDispatch(); |
134 void Dispatch(); | 140 void Dispatch(); |
135 // Return true if we should dispatch tasks. | 141 // Return true if we should dispatch tasks. |
136 bool ShouldDispatch(); | 142 bool ShouldDispatch(); |
137 | 143 |
138 const HandleTaskCallback process_callback_; | 144 const HandleTaskCallback process_callback_; |
139 net::BackoffEntry::Policy backoff_policy_; | 145 net::BackoffEntry::Policy backoff_policy_; |
140 scoped_ptr<net::BackoffEntry> backoff_entry_; | 146 scoped_ptr<net::BackoffEntry> backoff_entry_; |
141 // The number of tasks currently being handled. | 147 // The number of tasks currently being handled. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 } | 217 } |
212 | 218 |
213 template <typename T> | 219 template <typename T> |
214 void TaskQueue<T>::Cancel(const T& task) { | 220 void TaskQueue<T>::Cancel(const T& task) { |
215 DCHECK(CalledOnValidThread()); | 221 DCHECK(CalledOnValidThread()); |
216 FinishTask(task); | 222 FinishTask(task); |
217 ScheduleDispatch(); | 223 ScheduleDispatch(); |
218 } | 224 } |
219 | 225 |
220 template <typename T> | 226 template <typename T> |
| 227 void TaskQueue<T>::ResetBackoff() { |
| 228 backoff_timer_->Stop(); |
| 229 backoff_entry_->Reset(); |
| 230 ScheduleDispatch(); |
| 231 } |
| 232 |
| 233 template <typename T> |
221 void TaskQueue<T>::SetTimerForTest(scoped_ptr<base::Timer> timer) { | 234 void TaskQueue<T>::SetTimerForTest(scoped_ptr<base::Timer> timer) { |
222 DCHECK(CalledOnValidThread()); | 235 DCHECK(CalledOnValidThread()); |
223 DCHECK(timer.get()); | 236 DCHECK(timer.get()); |
224 backoff_timer_ = timer.Pass(); | 237 backoff_timer_ = timer.Pass(); |
225 } | 238 } |
226 | 239 |
227 template <typename T> | 240 template <typename T> |
228 void TaskQueue<T>::FinishTask(const T& task) { | 241 void TaskQueue<T>::FinishTask(const T& task) { |
229 DCHECK(CalledOnValidThread()); | 242 DCHECK(CalledOnValidThread()); |
230 DCHECK_GE(num_in_progress_, 1); | 243 DCHECK_GE(num_in_progress_, 1); |
(...skipping 30 matching lines...) Expand all Loading... |
261 } | 274 } |
262 | 275 |
263 template <typename T> | 276 template <typename T> |
264 bool TaskQueue<T>::ShouldDispatch() { | 277 bool TaskQueue<T>::ShouldDispatch() { |
265 return num_in_progress_ < kMaxConcurrentTasks && !queue_.empty(); | 278 return num_in_progress_ < kMaxConcurrentTasks && !queue_.empty(); |
266 } | 279 } |
267 | 280 |
268 } // namespace syncer | 281 } // namespace syncer |
269 | 282 |
270 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_TASK_QUEUE_H_ | 283 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_TASK_QUEUE_H_ |
OLD | NEW |