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

Unified 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 side-by-side diff with in-line comments
Download patch
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..72b29b4772209a244ad83c21cf7d3a44336d6dad
--- /dev/null
+++ b/net/nqe/network_qualities_manager.h
@@ -0,0 +1,69 @@
+// 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.
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.
+class NET_EXPORT_PRIVATE NetworkQualitiesManager {
+ public:
+ NetworkQualitiesManager();
+ ~NetworkQualitiesManager();
+
+ // Adds the network quality |cached_network_quality| of network with id
+ // |network_id| to the cache.
+ void CacheNetworkQualityEstimate(
+ 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_

Powered by Google App Engine
This is Rietveld 408576698