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

Unified Diff: net/nqe/network_quality_store.h

Issue 2261813002: Add a network quality cache observer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/nqe/network_quality_estimator_unittest.cc ('k') | net/nqe/network_quality_store.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/nqe/network_quality_store.h
diff --git a/net/nqe/network_quality_store.h b/net/nqe/network_quality_store.h
index 8ac78e97a280ff1e61510a138988b42675d8c7cf..6b71a646b46e7815a29424da7fba6d1c4156d4d5 100644
--- a/net/nqe/network_quality_store.h
+++ b/net/nqe/network_quality_store.h
@@ -8,9 +8,11 @@
#include <map>
#include "base/macros.h"
+#include "base/observer_list.h"
#include "base/threading/thread_checker.h"
#include "net/base/net_export.h"
#include "net/nqe/cached_network_quality.h"
+#include "net/nqe/effective_connection_type.h"
#include "net/nqe/network_id.h"
namespace net {
@@ -23,6 +25,25 @@ namespace internal {
// memory. Entries are stored in LRU order, and older entries may be evicted.
class NET_EXPORT_PRIVATE NetworkQualityStore {
public:
+ // Observes changes in the cached network qualities.
+ class NET_EXPORT NetworkQualitiesCacheObserver {
+ public:
+ // Notifies the observer of a change in the cached network quality. The
+ // observer must register and unregister itself on the IO thread. All the
+ // observers would be notified on the IO thread. |network_id| is the ID of
+ // the network whose cached quality is being reported.
+ virtual void OnChangeInCachedNetworkQuality(
+ const nqe::internal::NetworkID& network_id,
+ const nqe::internal::CachedNetworkQuality& cached_network_quality) = 0;
+
+ protected:
+ NetworkQualitiesCacheObserver() {}
+ virtual ~NetworkQualitiesCacheObserver() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NetworkQualitiesCacheObserver);
+ };
+
NetworkQualityStore();
~NetworkQualityStore();
@@ -37,6 +58,14 @@ class NET_EXPORT_PRIVATE NetworkQualityStore {
bool GetById(const nqe::internal::NetworkID& network_id,
nqe::internal::CachedNetworkQuality* cached_network_quality);
+ // Adds and removes |observer| from the list of cache observers. The
+ // observers are notified on the same thread on which it was added. Addition
+ // and removal of the observer must happen on the same thread.
+ void AddNetworkQualitiesCacheObserver(
+ NetworkQualitiesCacheObserver* observer);
+ void RemoveNetworkQualitiesCacheObserver(
+ NetworkQualitiesCacheObserver* observer);
+
private:
// Maximum size of the store that holds network quality estimates.
// A smaller size may reduce the cache hit rate due to frequent evictions.
@@ -53,6 +82,10 @@ class NET_EXPORT_PRIVATE NetworkQualityStore {
// Data structure that stores the qualities of networks.
CachedNetworkQualities cached_network_qualities_;
+ // Observer list for changes in the cached network quality.
+ base::ObserverList<NetworkQualitiesCacheObserver>
+ network_qualities_cache_observer_list_;
+
base::ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(NetworkQualityStore);
« no previous file with comments | « net/nqe/network_quality_estimator_unittest.cc ('k') | net/nqe/network_quality_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698