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

Unified Diff: net/nqe/network_qualities_prefs_manager.h

Issue 2322183002: Add Network Quality Estimator (NQE) pref manager (Closed)
Patch Set: Rebased, Addressed kundaji comments Created 4 years, 3 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
new file mode 100644
index 0000000000000000000000000000000000000000..d1a4bfb076979b1e0d1a39742d596cae9e27e675
--- /dev/null
+++ b/net/nqe/network_qualities_prefs_manager.h
@@ -0,0 +1,114 @@
+// 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_PREFS_MANAGER_H_
+#define NET_NQE_NETWORK_QUALITIES_PREFS_MANAGER_H_
+
+#include <memory>
+
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "net/base/net_export.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(
+ const nqe::internal::NetworkID& network_id,
+ const nqe::internal::CachedNetworkQuality& cached_network_quality)>
+ OnChangeInCachedNetworkQualityCallback;
+
+// Using the provided PrefDelegate, NetworkQualitiesPrefsManager creates and
+// updates network quality prefs. Instances of this class must be constructed on
bengr 2016/09/22 23:35:46 network quality prefs -> network quality informati
tbansal1 2016/09/23 17:10:33 Done.
+// the pref thread, and should later be moved to network thread by calling
bengr 2016/09/22 23:35:46 What is the "pref thread?" to -> to the
tbansal1 2016/09/23 17:10:32 Thread that is used to access the prefs (https://c
+// InitializeOnNetworkThread.
+//
+// This class interacts with both the pref thread and the network thread, and
+// propagates network quality pref changes from network thread to the provided
bengr 2016/09/22 23:35:46 from -> from the
tbansal1 2016/09/23 17:10:32 Done.
+// pref delegate on the pref thread.
+//
+// ShutdownOnPrefThread must be called from pref thread before destruction.
bengr 2016/09/22 23:35:46 from -> from the
tbansal1 2016/09/23 17:10:32 Done.
+class NET_EXPORT NetworkQualitiesPrefsManager
+ : public nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver {
+ public:
+ // Provides an interface that must be implemented by the embedder.
+ class NET_EXPORT PrefDelegate {
+ public:
+ // Sets the persistent pref to the given value.
+ virtual void SetDictionaryValue(const base::DictionaryValue& value) = 0;
+ };
+
+ // Create an instance of the NetworkQualitiesPrefsManager. Ownership of
bengr 2016/09/22 23:35:46 Create -> Creates
tbansal1 2016/09/23 17:10:33 Done.
+ // |pref_delegate| is taken by this class. Must be constructed on the Pref
bengr 2016/09/22 23:35:46 is Pref capitalized? Here and elsewhere.
tbansal1 2016/09/23 17:10:32 Not sure, made it lower case.
+ // thread, and then moved to network thread.
+ explicit NetworkQualitiesPrefsManager(
+ std::unique_ptr<PrefDelegate> pref_delegate);
+ ~NetworkQualitiesPrefsManager() override;
+
+ // Initialize on Network thread.
bengr 2016/09/22 23:35:46 on -> on the
tbansal1 2016/09/23 17:10:32 Done.
+ void InitializeOnNetworkThread(
+ NetworkQualityEstimator* network_quality_estimator);
+
+ // Prepare for shutdown. Must be called on the Pref thread before destruction.
+ void ShutdownOnPrefThread();
+
+ private:
+ // -----------
+ // Pref thread
+ // -----------
bengr 2016/09/22 23:35:47 I would change this comment to simply be: // Pref
tbansal1 2016/09/23 17:10:33 Done.
+
+ // Called on pref thread when there is a change in the cached network quality.
+ void OnChangeInCachedNetworkQualityOnPrefThread(
+ const nqe::internal::NetworkID& network_id,
+ const nqe::internal::CachedNetworkQuality& cached_network_quality);
+
+ // Responsible for writing the persistent prefs to the disk.
+ std::unique_ptr<PrefDelegate> pref_delegate_;
+
+ scoped_refptr<base::SequencedTaskRunner> pref_task_runner_;
+
+ // Should be accessed only on the pref thread.
+ base::WeakPtr<NetworkQualitiesPrefsManager> pref_weak_ptr_;
+
+ // --------------
+ // Network thread
+ // --------------
+
+ // nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver
+ // implementation:
+ void OnChangeInCachedNetworkQuality(
+ const nqe::internal::NetworkID& network_id,
+ const nqe::internal::CachedNetworkQuality& cached_network_quality)
+ override;
+
+ NetworkQualityEstimator* network_quality_estimator_;
+
+ scoped_refptr<base::SequencedTaskRunner> network_task_runner_;
+
+ // --------------
+ // Common
+ // --------------
+
+ // Used to get |weak_ptr_| to self on the pref thread.
+ base::WeakPtrFactory<NetworkQualitiesPrefsManager> pref_weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(NetworkQualitiesPrefsManager);
+};
+
+} // namespace net
+
+#endif // NET_NQE_NETWORK_QUALITIES_PREFS_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698