| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 COMPONENTS_PRECACHE_CORE_FETCHER_POOL_H_ | 5 #ifndef COMPONENTS_PRECACHE_CORE_FETCHER_POOL_H_ |
| 6 #define COMPONENTS_PRECACHE_CORE_FETCHER_POOL_H_ | 6 #define COMPONENTS_PRECACHE_CORE_FETCHER_POOL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <unordered_map> | 9 #include <unordered_map> |
| 10 | 10 |
| 11 #include "base/gtest_prod_util.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 | 13 |
| 13 namespace precache { | 14 namespace precache { |
| 14 | 15 |
| 15 // FetcherPool that accepts a limited number of elements. | 16 // FetcherPool that accepts a limited number of elements. |
| 16 // | 17 // |
| 17 // FetcherPool is particularly suited for having multiple URLFetchers running | 18 // FetcherPool is particularly suited for having multiple URLFetchers running |
| 18 // in parallel. | 19 // in parallel. |
| 19 // | 20 // |
| 20 // It doesn't enqueue the elements above a defined capacity. The callsite must | 21 // It doesn't enqueue the elements above a defined capacity. The callsite must |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 61 |
| 61 // Deletes all the elements in the pool. | 62 // Deletes all the elements in the pool. |
| 62 void DeleteAll() { elements_.clear(); } | 63 void DeleteAll() { elements_.clear(); } |
| 63 | 64 |
| 64 // Returns true iff the pool is empty. | 65 // Returns true iff the pool is empty. |
| 65 bool IsEmpty() const { return elements_.empty(); } | 66 bool IsEmpty() const { return elements_.empty(); } |
| 66 | 67 |
| 67 // Returns true iff the pool can accept a new element. | 68 // Returns true iff the pool can accept a new element. |
| 68 bool IsAvailable() const { return max_size_ > elements_.size(); } | 69 bool IsAvailable() const { return max_size_ > elements_.size(); } |
| 69 | 70 |
| 71 // Returns the maximum size of the pool. |
| 72 size_t max_size() const { return max_size_; } |
| 73 |
| 70 private: | 74 private: |
| 71 const size_t max_size_; | 75 const size_t max_size_; |
| 72 std::unordered_map<const T*, std::unique_ptr<T>> elements_; | 76 std::unordered_map<const T*, std::unique_ptr<T>> elements_; |
| 73 | 77 |
| 74 DISALLOW_COPY_AND_ASSIGN(FetcherPool); | 78 DISALLOW_COPY_AND_ASSIGN(FetcherPool); |
| 75 }; | 79 }; |
| 76 | 80 |
| 77 } // namespace precache | 81 } // namespace precache |
| 78 | 82 |
| 79 #endif // COMPONENTS_PRECACHE_CORE_FETCHER_POOL_H_ | 83 #endif // COMPONENTS_PRECACHE_CORE_FETCHER_POOL_H_ |
| OLD | NEW |