OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "net/base/prioritized_dispatcher.h" | 5 #include "net/base/prioritized_dispatcher.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace net { | 9 namespace net { |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 DCHECK(job); | 38 DCHECK(job); |
39 DCHECK_LT(priority, num_priorities()); | 39 DCHECK_LT(priority, num_priorities()); |
40 if (num_running_jobs_ < max_running_jobs_[priority]) { | 40 if (num_running_jobs_ < max_running_jobs_[priority]) { |
41 ++num_running_jobs_; | 41 ++num_running_jobs_; |
42 job->Start(); | 42 job->Start(); |
43 return Handle(); | 43 return Handle(); |
44 } | 44 } |
45 return queue_.Insert(job, priority); | 45 return queue_.Insert(job, priority); |
46 } | 46 } |
47 | 47 |
| 48 PrioritizedDispatcher::Handle PrioritizedDispatcher::AddAtHead( |
| 49 Job* job, Priority priority) { |
| 50 DCHECK(job); |
| 51 DCHECK_LT(priority, num_priorities()); |
| 52 if (num_running_jobs_ < max_running_jobs_[priority]) { |
| 53 ++num_running_jobs_; |
| 54 job->Start(); |
| 55 return Handle(); |
| 56 } |
| 57 return queue_.InsertAtFront(job, priority); |
| 58 } |
| 59 |
48 void PrioritizedDispatcher::Cancel(const Handle& handle) { | 60 void PrioritizedDispatcher::Cancel(const Handle& handle) { |
49 queue_.Erase(handle); | 61 queue_.Erase(handle); |
50 } | 62 } |
51 | 63 |
52 PrioritizedDispatcher::Job* PrioritizedDispatcher::EvictOldestLowest() { | 64 PrioritizedDispatcher::Job* PrioritizedDispatcher::EvictOldestLowest() { |
53 Handle handle = queue_.FirstMin(); | 65 Handle handle = queue_.FirstMin(); |
54 if (handle.is_null()) | 66 if (handle.is_null()) |
55 return NULL; | 67 return NULL; |
56 Job* job = handle.value(); | 68 Job* job = handle.value(); |
57 Cancel(handle); | 69 Cancel(handle); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 if (num_running_jobs_ >= max_running_jobs_[job_priority]) | 104 if (num_running_jobs_ >= max_running_jobs_[job_priority]) |
93 return false; | 105 return false; |
94 Job* job = handle.value(); | 106 Job* job = handle.value(); |
95 queue_.Erase(handle); | 107 queue_.Erase(handle); |
96 ++num_running_jobs_; | 108 ++num_running_jobs_; |
97 job->Start(); | 109 job->Start(); |
98 return true; | 110 return true; |
99 } | 111 } |
100 | 112 |
101 } // namespace net | 113 } // namespace net |
OLD | NEW |