Index: net/nqe/network_qualities_manager.h |
diff --git a/net/nqe/network_qualities_manager.h b/net/nqe/network_qualities_manager.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..18e89a9621a4be707e5ee89428f15380fe0513b7 |
--- /dev/null |
+++ b/net/nqe/network_qualities_manager.h |
@@ -0,0 +1,70 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef NET_NQE_NETWORK_QUALITIES_MANAGER_H_ |
+#define NET_NQE_NETWORK_QUALITIES_MANAGER_H_ |
+ |
+#include <map> |
+ |
+#include "base/macros.h" |
+#include "base/threading/thread_checker.h" |
+#include "net/base/net_export.h" |
+#include "net/nqe/cached_network_quality.h" |
+#include "net/nqe/network_id.h" |
+ |
+namespace net { |
+ |
+namespace nqe { |
+ |
+namespace internal { |
+ |
+// NetworkQualitiesManager holds the network qualities of different networks |
+// in a cache which is backed up by memory. Entries are stored in LRU order, and |
+// older entries may be evicted. |
+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.
|
+ public: |
+ NetworkQualitiesManager(); |
+ ~NetworkQualitiesManager(); |
+ |
+ // 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.
|
+ // |network_id| to the cache. |
bengr
2016/07/21 00:16:24
to the cache. -> .
tbansal1
2016/07/21 01:25:39
Done.
|
+ void CacheNetworkQualityEstimate( |
bengr
2016/07/21 00:16:24
How about AddNetworkQualityEstimate or StoreNetwor
tbansal1
2016/07/21 01:25:40
Obsolete.
|
+ const nqe::internal::NetworkID& network_id, |
+ const nqe::internal::CachedNetworkQuality& cached_network_quality); |
+ |
+ // Returns true if the cached network quality estimate was successfully read |
+ // for network with id |network_id|, and sets |cached_network_quality| to the |
+ // estimate read from the cache. |
+ bool GetCachedNetworkQualityEstimate( |
+ const nqe::internal::NetworkID& network_id, |
+ nqe::internal::CachedNetworkQuality* cached_network_quality); |
+ |
+ private: |
+ // Maximum size of the cache that holds network quality estimates. |
+ // Smaller size may reduce the cache hit rate due to frequent evictions. |
+ // Larger size may affect performance. |
+ static const size_t kMaximumNetworkQualityCacheSize = 10; |
+ |
+ // This does not use a unordered_map or hash_map for code simplicity (key just |
+ // implements operator<, rather than hash and equality) and because the map is |
+ // tiny. |
+ typedef std::map<nqe::internal::NetworkID, |
+ nqe::internal::CachedNetworkQuality> |
+ CachedNetworkQualities; |
+ |
+ // Cache that stores quality of previously seen networks. |
+ CachedNetworkQualities cached_network_qualities_; |
+ |
+ base::ThreadChecker thread_checker_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(NetworkQualitiesManager); |
+}; |
+ |
+} // namespace internal |
+ |
+} // namespace nqe |
+ |
+} // namespace net |
+ |
+#endif // NET_NQE_NETWORK_QUALITIES_MANAGER_H_ |