| 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 EXTENSIONS_BROWSER_UPDATER_REQUEST_QUEUE_H_ | 5 #ifndef EXTENSIONS_BROWSER_UPDATER_REQUEST_QUEUE_H_ |
| 6 #define EXTENSIONS_BROWSER_UPDATER_REQUEST_QUEUE_H_ | 6 #define EXTENSIONS_BROWSER_UPDATER_REQUEST_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 <utility> | 12 #include <utility> |
| 12 | 13 |
| 13 #include "base/callback.h" | 14 #include "base/callback.h" |
| 14 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
| 18 #include "net/base/backoff_entry.h" | 18 #include "net/base/backoff_entry.h" |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 | 21 |
| 22 // This class keeps track of a queue of requests, and contains the logic to | 22 // This class keeps track of a queue of requests, and contains the logic to |
| 23 // retry requests with some backoff policy. Each request has a | 23 // retry requests with some backoff policy. Each request has a |
| 24 // net::BackoffEntry instance associated with it. | 24 // net::BackoffEntry instance associated with it. |
| 25 // | 25 // |
| (...skipping 18 matching lines...) Expand all Loading... |
| 44 const base::Closure& start_request_callback); | 44 const base::Closure& start_request_callback); |
| 45 ~RequestQueue(); | 45 ~RequestQueue(); |
| 46 | 46 |
| 47 // Returns the request that is currently being processed. | 47 // Returns the request that is currently being processed. |
| 48 T* active_request(); | 48 T* active_request(); |
| 49 | 49 |
| 50 // Returns the number of times the current request has been retried already. | 50 // Returns the number of times the current request has been retried already. |
| 51 int active_request_failure_count(); | 51 int active_request_failure_count(); |
| 52 | 52 |
| 53 // Signals RequestQueue that processing of the current request has completed. | 53 // Signals RequestQueue that processing of the current request has completed. |
| 54 scoped_ptr<T> reset_active_request(); | 54 std::unique_ptr<T> reset_active_request(); |
| 55 | 55 |
| 56 // Add the given request to the queue, and starts the next request if no | 56 // Add the given request to the queue, and starts the next request if no |
| 57 // request is currently being processed. | 57 // request is currently being processed. |
| 58 void ScheduleRequest(scoped_ptr<T> request); | 58 void ScheduleRequest(std::unique_ptr<T> request); |
| 59 | 59 |
| 60 bool empty() const; | 60 bool empty() const; |
| 61 size_t size() const; | 61 size_t size() const; |
| 62 | 62 |
| 63 // Returns the earliest release time of all requests currently in the queue. | 63 // Returns the earliest release time of all requests currently in the queue. |
| 64 base::TimeTicks NextReleaseTime() const; | 64 base::TimeTicks NextReleaseTime() const; |
| 65 | 65 |
| 66 // Starts the next request, if no request is currently active. This will | 66 // Starts the next request, if no request is currently active. This will |
| 67 // synchronously call the start_request_callback if the release time of the | 67 // synchronously call the start_request_callback if the release time of the |
| 68 // earliest available request is in the past, otherwise it will call that | 68 // earliest available request is in the past, otherwise it will call that |
| (...skipping 17 matching lines...) Expand all Loading... |
| 86 Request(net::BackoffEntry* backoff_entry, T* request) | 86 Request(net::BackoffEntry* backoff_entry, T* request) |
| 87 : backoff_entry(backoff_entry), request(request) {} | 87 : backoff_entry(backoff_entry), request(request) {} |
| 88 linked_ptr<net::BackoffEntry> backoff_entry; | 88 linked_ptr<net::BackoffEntry> backoff_entry; |
| 89 linked_ptr<T> request; | 89 linked_ptr<T> request; |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 // Compares the release time of two pending requests. | 92 // Compares the release time of two pending requests. |
| 93 static bool CompareRequests(const Request& a, const Request& b); | 93 static bool CompareRequests(const Request& a, const Request& b); |
| 94 | 94 |
| 95 // Pushes a request with a given backoff entry onto the queue. | 95 // Pushes a request with a given backoff entry onto the queue. |
| 96 void PushImpl(scoped_ptr<T> request, | 96 void PushImpl(std::unique_ptr<T> request, |
| 97 scoped_ptr<net::BackoffEntry> backoff_entry); | 97 std::unique_ptr<net::BackoffEntry> backoff_entry); |
| 98 | 98 |
| 99 // The backoff policy used to determine backoff delays. | 99 // The backoff policy used to determine backoff delays. |
| 100 const net::BackoffEntry::Policy* backoff_policy_; | 100 const net::BackoffEntry::Policy* backoff_policy_; |
| 101 | 101 |
| 102 // Callback to call when a new request has become the active request. | 102 // Callback to call when a new request has become the active request. |
| 103 base::Closure start_request_callback_; | 103 base::Closure start_request_callback_; |
| 104 | 104 |
| 105 // Priority queue of pending requests. Not using std::priority_queue since | 105 // Priority queue of pending requests. Not using std::priority_queue since |
| 106 // the code needs to be able to iterate over all pending requests. | 106 // the code needs to be able to iterate over all pending requests. |
| 107 std::deque<Request> pending_requests_; | 107 std::deque<Request> pending_requests_; |
| 108 | 108 |
| 109 // Active request and its associated backoff entry. | 109 // Active request and its associated backoff entry. |
| 110 scoped_ptr<T> active_request_; | 110 std::unique_ptr<T> active_request_; |
| 111 scoped_ptr<net::BackoffEntry> active_backoff_entry_; | 111 std::unique_ptr<net::BackoffEntry> active_backoff_entry_; |
| 112 | 112 |
| 113 // Timer to schedule calls to StartNextRequest, if the first pending request | 113 // Timer to schedule calls to StartNextRequest, if the first pending request |
| 114 // hasn't passed its release time yet. | 114 // hasn't passed its release time yet. |
| 115 base::Timer timer_; | 115 base::Timer timer_; |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 // Iterator class that wraps a std::deque<> iterator, only giving access to the | 118 // Iterator class that wraps a std::deque<> iterator, only giving access to the |
| 119 // actual request part of each item. | 119 // actual request part of each item. |
| 120 template <typename T> | 120 template <typename T> |
| 121 class RequestQueue<T>::iterator { | 121 class RequestQueue<T>::iterator { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 135 typedef std::deque<typename RequestQueue<T>::Request> Container; | 135 typedef std::deque<typename RequestQueue<T>::Request> Container; |
| 136 | 136 |
| 137 explicit iterator(const typename Container::iterator& it) : it_(it) {} | 137 explicit iterator(const typename Container::iterator& it) : it_(it) {} |
| 138 | 138 |
| 139 typename Container::iterator it_; | 139 typename Container::iterator it_; |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 } // namespace extensions | 142 } // namespace extensions |
| 143 | 143 |
| 144 #endif // EXTENSIONS_BROWSER_UPDATER_REQUEST_QUEUE_H_ | 144 #endif // EXTENSIONS_BROWSER_UPDATER_REQUEST_QUEUE_H_ |
| OLD | NEW |