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

Unified Diff: net/nqe/network_qualities_prefs_manager.h

Issue 2369673004: Wire NQE Prefs to Profile (Closed)
Patch Set: Addressed bengr comments Created 4 years, 2 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_prefs_manager.h
diff --git a/net/nqe/network_qualities_prefs_manager.h b/net/nqe/network_qualities_prefs_manager.h
index 9978409606843d1e3d4a0b866ba69932e2bd0674..c903442e35da460441ccf42dc5bd309a24a33d39 100644
--- a/net/nqe/network_qualities_prefs_manager.h
+++ b/net/nqe/network_qualities_prefs_manager.h
@@ -5,26 +5,23 @@
#ifndef NET_NQE_NETWORK_QUALITIES_PREFS_MANAGER_H_
#define NET_NQE_NETWORK_QUALITIES_PREFS_MANAGER_H_
+#include <map>
#include <memory>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
+#include "base/values.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"
#include "net/nqe/network_quality_store.h"
namespace base {
-class DictionaryValue;
class SequencedTaskRunner;
}
namespace net {
-namespace nqe {
-namespace internal {
-class CachedNetworkQuality;
-}
-}
class NetworkQualityEstimator;
typedef base::Callback<void(
@@ -32,6 +29,9 @@ typedef base::Callback<void(
const nqe::internal::CachedNetworkQuality& cached_network_quality)>
OnChangeInCachedNetworkQualityCallback;
+typedef std::map<nqe::internal::NetworkID, nqe::internal::CachedNetworkQuality>
+ ParsedPrefs;
+
// Using the provided PrefDelegate, NetworkQualitiesPrefsManager creates and
// updates network quality information that is stored in prefs. Instances of
// this class must be constructed on the pref thread, and should later be moved
@@ -48,8 +48,13 @@ class NET_EXPORT NetworkQualitiesPrefsManager
// Provides an interface that must be implemented by the embedder.
class NET_EXPORT PrefDelegate {
public:
+ virtual ~PrefDelegate() {}
+
// Sets the persistent pref to the given value.
virtual void SetDictionaryValue(const base::DictionaryValue& value) = 0;
+
+ // Returns the peristent prefs.
+ virtual const base::DictionaryValue& GetDictionaryValue() = 0;
};
// Creates an instance of the NetworkQualitiesPrefsManager. Ownership of
@@ -66,6 +71,10 @@ class NET_EXPORT NetworkQualitiesPrefsManager
// Prepare for shutdown. Must be called on the pref thread before destruction.
void ShutdownOnPrefThread();
+ // Reads the prefs again, parses them into a map of NetworkIDs and
+ // CachedNetworkQualities, and returns the map.
+ ParsedPrefs ForceReadPrefsForTesting() const;
+
private:
// Pref thread members:
// Called on pref thread when there is a change in the cached network quality.
@@ -78,6 +87,9 @@ class NET_EXPORT NetworkQualitiesPrefsManager
scoped_refptr<base::SequencedTaskRunner> pref_task_runner_;
+ // Current prefs on the disk. Should be accessed only on the pref thread.
+ std::unique_ptr<base::DictionaryValue> prefs_;
+
// Should be accessed only on the pref thread.
base::WeakPtr<NetworkQualitiesPrefsManager> pref_weak_ptr_;
@@ -93,6 +105,10 @@ class NET_EXPORT NetworkQualitiesPrefsManager
scoped_refptr<base::SequencedTaskRunner> network_task_runner_;
+ // Network quality prefs read from the disk at the time of startup. Can be
+ // accessed on any thread.
+ const ParsedPrefs read_prefs_startup_;
+
// Used to get |weak_ptr_| to self on the pref thread.
base::WeakPtrFactory<NetworkQualitiesPrefsManager> pref_weak_ptr_factory_;

Powered by Google App Engine
This is Rietveld 408576698