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 #ifndef NET_BASE_PRIORITIZED_DISPATCHER_H_ | 5 #ifndef NET_BASE_PRIORITIZED_DISPATCHER_H_ |
6 #define NET_BASE_PRIORITIZED_DISPATCHER_H_ | 6 #define NET_BASE_PRIORITIZED_DISPATCHER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "net/base/net_export.h" | 10 #include "net/base/net_export.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 size_t num_running_jobs() const { return num_running_jobs_; } | 71 size_t num_running_jobs() const { return num_running_jobs_; } |
72 size_t num_queued_jobs() const { return queue_.size(); } | 72 size_t num_queued_jobs() const { return queue_.size(); } |
73 size_t num_priorities() const { return max_running_jobs_.size(); } | 73 size_t num_priorities() const { return max_running_jobs_.size(); } |
74 | 74 |
75 // Adds |job| with |priority| to the dispatcher. If limits permit, |job| is | 75 // Adds |job| with |priority| to the dispatcher. If limits permit, |job| is |
76 // started immediately. Returns handle to the job or null-handle if the job is | 76 // started immediately. Returns handle to the job or null-handle if the job is |
77 // started. The dispatcher does not own |job|, but |job| must live as long as | 77 // started. The dispatcher does not own |job|, but |job| must live as long as |
78 // it is queued in the dispatcher. | 78 // it is queued in the dispatcher. |
79 Handle Add(Job* job, Priority priority); | 79 Handle Add(Job* job, Priority priority); |
80 | 80 |
| 81 // Just like Add, except that it adds Job at the font of queue of jobs with |
| 82 // priorities of |priority|. |
| 83 Handle AddAtHead(Job* job, Priority priority); |
| 84 |
81 // Removes the job with |handle| from the queue. Invalidates |handle|. | 85 // Removes the job with |handle| from the queue. Invalidates |handle|. |
82 // Note: a Handle is valid iff the job is in the queue, i.e. has not Started. | 86 // Note: a Handle is valid iff the job is in the queue, i.e. has not Started. |
83 void Cancel(const Handle& handle); | 87 void Cancel(const Handle& handle); |
84 | 88 |
85 // Cancels and returns the oldest-lowest-priority Job invalidating any | 89 // Cancels and returns the oldest-lowest-priority Job invalidating any |
86 // handles to it. Returns NULL if the queue is empty. | 90 // handles to it. Returns NULL if the queue is empty. |
87 Job* EvictOldestLowest(); | 91 Job* EvictOldestLowest(); |
88 | 92 |
89 // Moves the queued job with |handle| to the end of all values with priority | 93 // Moves the queued job with |handle| to the end of all values with priority |
90 // |priority| and returns the updated handle, or null-handle if it starts the | 94 // |priority| and returns the updated handle, or null-handle if it starts the |
(...skipping 17 matching lines...) Expand all Loading... |
108 std::vector<size_t> max_running_jobs_; | 112 std::vector<size_t> max_running_jobs_; |
109 // Total number of running jobs. | 113 // Total number of running jobs. |
110 size_t num_running_jobs_; | 114 size_t num_running_jobs_; |
111 | 115 |
112 DISALLOW_COPY_AND_ASSIGN(PrioritizedDispatcher); | 116 DISALLOW_COPY_AND_ASSIGN(PrioritizedDispatcher); |
113 }; | 117 }; |
114 | 118 |
115 } // namespace net | 119 } // namespace net |
116 | 120 |
117 #endif // NET_BASE_PRIORITIZED_DISPATCHER_H_ | 121 #endif // NET_BASE_PRIORITIZED_DISPATCHER_H_ |
OLD | NEW |