OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_NQE_NETWORK_QUALITY_STORE_H_ |
| 6 #define NET_NQE_NETWORK_QUALITY_STORE_H_ |
| 7 |
| 8 #include <map> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/threading/thread_checker.h" |
| 12 #include "net/base/net_export.h" |
| 13 #include "net/nqe/cached_network_quality.h" |
| 14 #include "net/nqe/network_id.h" |
| 15 |
| 16 namespace net { |
| 17 |
| 18 namespace nqe { |
| 19 |
| 20 namespace internal { |
| 21 |
| 22 // NetworkQualityStore holds the network qualities of different networks in |
| 23 // memory. Entries are stored in LRU order, and older entries may be evicted. |
| 24 class NET_EXPORT_PRIVATE NetworkQualityStore { |
| 25 public: |
| 26 NetworkQualityStore(); |
| 27 ~NetworkQualityStore(); |
| 28 |
| 29 // Stores the network quality |cached_network_quality| of network with ID |
| 30 // |network_id|. |
| 31 void Add(const nqe::internal::NetworkID& network_id, |
| 32 const nqe::internal::CachedNetworkQuality& cached_network_quality); |
| 33 |
| 34 // Returns true if the network quality estimate was successfully read |
| 35 // for a network with ID |network_id|, and sets |cached_network_quality| to |
| 36 // the estimate read. |
| 37 bool GetById(const nqe::internal::NetworkID& network_id, |
| 38 nqe::internal::CachedNetworkQuality* cached_network_quality); |
| 39 |
| 40 private: |
| 41 // Maximum size of the store that holds network quality estimates. |
| 42 // A smaller size may reduce the cache hit rate due to frequent evictions. |
| 43 // A larger size may affect performance. |
| 44 static const size_t kMaximumNetworkQualityCacheSize = 10; |
| 45 |
| 46 // This does not use an unordered_map or hash_map for code simplicity (the key |
| 47 // just implements operator<, rather than hash and equality) and because the |
| 48 // map is tiny. |
| 49 typedef std::map<nqe::internal::NetworkID, |
| 50 nqe::internal::CachedNetworkQuality> |
| 51 CachedNetworkQualities; |
| 52 |
| 53 // Data structure that stores the qualities of networks. |
| 54 CachedNetworkQualities cached_network_qualities_; |
| 55 |
| 56 base::ThreadChecker thread_checker_; |
| 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(NetworkQualityStore); |
| 59 }; |
| 60 |
| 61 } // namespace internal |
| 62 |
| 63 } // namespace nqe |
| 64 |
| 65 } // namespace net |
| 66 |
| 67 #endif // NET_NQE_NETWORK_QUALITY_STORE_H_ |
OLD | NEW |