Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(723)

Side by Side Diff: net/nqe/network_quality_store.h

Issue 2128793003: Factor out NetworkID and caching mechanism from n_q_e.{h,cc} (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed asvitkine comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/nqe/network_quality_observation_source.h ('k') | net/nqe/network_quality_store.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_
OLDNEW
« no previous file with comments | « net/nqe/network_quality_observation_source.h ('k') | net/nqe/network_quality_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698