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_QUALITIES_MANAGER_H_ | |
6 #define NET_NQE_NETWORK_QUALITIES_MANAGER_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 // NetworkQualitiesManager holds the network qualities of different networks | |
23 // in a cache which is backed up by memory. Entries are stored in LRU order, and | |
24 // older entries may be evicted. | |
25 class NET_EXPORT_PRIVATE NetworkQualitiesManager { | |
bengr
2016/07/21 00:16:24
Hmm. Even if this will become a manager, I wonder
tbansal1
2016/07/21 01:25:39
Done.
| |
26 public: | |
27 NetworkQualitiesManager(); | |
28 ~NetworkQualitiesManager(); | |
29 | |
30 // Adds the network quality |cached_network_quality| of network with id | |
bengr
2016/07/21 00:16:24
Adds -> Stores
tbansal1
2016/07/21 01:25:39
Done.
| |
31 // |network_id| to the cache. | |
bengr
2016/07/21 00:16:24
to the cache. -> .
tbansal1
2016/07/21 01:25:39
Done.
| |
32 void CacheNetworkQualityEstimate( | |
bengr
2016/07/21 00:16:24
How about AddNetworkQualityEstimate or StoreNetwor
tbansal1
2016/07/21 01:25:40
Obsolete.
| |
33 const nqe::internal::NetworkID& network_id, | |
34 const nqe::internal::CachedNetworkQuality& cached_network_quality); | |
35 | |
36 // Returns true if the cached network quality estimate was successfully read | |
37 // for network with id |network_id|, and sets |cached_network_quality| to the | |
38 // estimate read from the cache. | |
39 bool GetCachedNetworkQualityEstimate( | |
40 const nqe::internal::NetworkID& network_id, | |
41 nqe::internal::CachedNetworkQuality* cached_network_quality); | |
42 | |
43 private: | |
44 // Maximum size of the cache that holds network quality estimates. | |
45 // Smaller size may reduce the cache hit rate due to frequent evictions. | |
46 // Larger size may affect performance. | |
47 static const size_t kMaximumNetworkQualityCacheSize = 10; | |
48 | |
49 // This does not use a unordered_map or hash_map for code simplicity (key just | |
50 // implements operator<, rather than hash and equality) and because the map is | |
51 // tiny. | |
52 typedef std::map<nqe::internal::NetworkID, | |
53 nqe::internal::CachedNetworkQuality> | |
54 CachedNetworkQualities; | |
55 | |
56 // Cache that stores quality of previously seen networks. | |
57 CachedNetworkQualities cached_network_qualities_; | |
58 | |
59 base::ThreadChecker thread_checker_; | |
60 | |
61 DISALLOW_COPY_AND_ASSIGN(NetworkQualitiesManager); | |
62 }; | |
63 | |
64 } // namespace internal | |
65 | |
66 } // namespace nqe | |
67 | |
68 } // namespace net | |
69 | |
70 #endif // NET_NQE_NETWORK_QUALITIES_MANAGER_H_ | |
OLD | NEW |