| 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 COMPONENTS_SYNC_CORE_ATTACHMENTS_TASK_QUEUE_H_ |
| 6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_TASK_QUEUE_H_ | 6 #define COMPONENTS_SYNC_CORE_ATTACHMENTS_TASK_QUEUE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <deque> | 10 #include <deque> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <utility> | 13 #include <utility> |
| 14 | 14 |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/callback.h" | 16 #include "base/callback.h" |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 DCHECK_EQ(1U, num_erased); | 249 DCHECK_EQ(1U, num_erased); |
| 250 } | 250 } |
| 251 | 251 |
| 252 template <typename T> | 252 template <typename T> |
| 253 void TaskQueue<T>::ScheduleDispatch() { | 253 void TaskQueue<T>::ScheduleDispatch() { |
| 254 DCHECK(CalledOnValidThread()); | 254 DCHECK(CalledOnValidThread()); |
| 255 if (backoff_timer_->IsRunning() || !ShouldDispatch()) { | 255 if (backoff_timer_->IsRunning() || !ShouldDispatch()) { |
| 256 return; | 256 return; |
| 257 } | 257 } |
| 258 | 258 |
| 259 backoff_timer_->Start( | 259 backoff_timer_->Start(FROM_HERE, backoff_entry_->GetTimeUntilRelease(), |
| 260 FROM_HERE, backoff_entry_->GetTimeUntilRelease(), dispatch_closure_); | 260 dispatch_closure_); |
| 261 } | 261 } |
| 262 | 262 |
| 263 template <typename T> | 263 template <typename T> |
| 264 void TaskQueue<T>::Dispatch() { | 264 void TaskQueue<T>::Dispatch() { |
| 265 DCHECK(CalledOnValidThread()); | 265 DCHECK(CalledOnValidThread()); |
| 266 if (!ShouldDispatch()) { | 266 if (!ShouldDispatch()) { |
| 267 return; | 267 return; |
| 268 } | 268 } |
| 269 | 269 |
| 270 DCHECK(!queue_.empty()); | 270 DCHECK(!queue_.empty()); |
| 271 const T& task = queue_.front(); | 271 const T& task = queue_.front(); |
| 272 ++num_in_progress_; | 272 ++num_in_progress_; |
| 273 DCHECK_LE(num_in_progress_, kMaxConcurrentTasks); | 273 DCHECK_LE(num_in_progress_, kMaxConcurrentTasks); |
| 274 base::ThreadTaskRunnerHandle::Get()->PostTask( | 274 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 275 FROM_HERE, base::Bind(process_callback_, task)); | 275 FROM_HERE, base::Bind(process_callback_, task)); |
| 276 queue_.pop_front(); | 276 queue_.pop_front(); |
| 277 } | 277 } |
| 278 | 278 |
| 279 template <typename T> | 279 template <typename T> |
| 280 bool TaskQueue<T>::ShouldDispatch() { | 280 bool TaskQueue<T>::ShouldDispatch() { |
| 281 return num_in_progress_ < kMaxConcurrentTasks && !queue_.empty(); | 281 return num_in_progress_ < kMaxConcurrentTasks && !queue_.empty(); |
| 282 } | 282 } |
| 283 | 283 |
| 284 } // namespace syncer | 284 } // namespace syncer |
| 285 | 285 |
| 286 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_TASK_QUEUE_H_ | 286 #endif // COMPONENTS_SYNC_CORE_ATTACHMENTS_TASK_QUEUE_H_ |
| OLD | NEW |