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

Side by Side Diff: net/nqe/network_qualities_manager.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: Rebased Created 4 years, 5 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
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_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.
RyanSturm 2016/07/12 18:45:38 Can you mention that it is LRU in this comment?
tbansal1 2016/07/12 19:40:18 Done.
24 class NET_EXPORT_PRIVATE NetworkQualitiesManager {
25 public:
26 NetworkQualitiesManager();
27 ~NetworkQualitiesManager();
28
29 // Adds the network quality |cached_network_quality| of network with id
30 // |network_id| to the cache.
31 void CacheNetworkQualityEstimate(
32 const nqe::internal::NetworkID& network_id,
33 const nqe::internal::CachedNetworkQuality& cached_network_quality);
34
35 // Returns true if the cached network quality estimate was successfully read
36 // for network with id |network_id|, and sets |cached_network_quality| to the
37 // estimate read from the cache.
38 bool GetCachedNetworkQualityEstimate(
39 const nqe::internal::NetworkID& network_id,
40 nqe::internal::CachedNetworkQuality* cached_network_quality);
41
42 private:
43 // Maximum size of the cache that holds network quality estimates.
44 // Smaller size may reduce the cache hit rate due to frequent evictions.
45 // Larger size may affect performance.
46 static const size_t kMaximumNetworkQualityCacheSize = 10;
47
48 // This does not use a unordered_map or hash_map for code simplicity (key just
49 // implements operator<, rather than hash and equality) and because the map is
50 // tiny.
51 typedef std::map<nqe::internal::NetworkID,
52 nqe::internal::CachedNetworkQuality>
53 CachedNetworkQualities;
54
55 // Cache that stores quality of previously seen networks.
56 CachedNetworkQualities cached_network_qualities_;
57
58 base::ThreadChecker thread_checker_;
59
60 DISALLOW_COPY_AND_ASSIGN(NetworkQualitiesManager);
61 };
62
63 } // namespace internal
64
65 } // namespace nqe
66
67 } // namespace net
68
69 #endif // NET_NQE_NETWORK_QUALITIES_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698