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

Unified Diff: chrome/browser/net/http_server_properties_manager_factory.cc

Issue 1626673002: Separate prefs from HttpServerPropertiesManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: NET_EXPORT Created 4 years, 11 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 | « no previous file | components/cronet/android/cronet_url_request_context_adapter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/net/http_server_properties_manager_factory.cc
diff --git a/chrome/browser/net/http_server_properties_manager_factory.cc b/chrome/browser/net/http_server_properties_manager_factory.cc
index ecd09e180443b6a78f8057c3c4d6b0f94268c37c..5c566d7cb7c7f2e5df8ca1a57bb8ccc072dc6cc4 100644
--- a/chrome/browser/net/http_server_properties_manager_factory.cc
+++ b/chrome/browser/net/http_server_properties_manager_factory.cc
@@ -4,11 +4,57 @@
#include "chrome/browser/net/http_server_properties_manager_factory.h"
+#include "base/prefs/pref_change_registrar.h"
+#include "base/prefs/pref_service.h"
#include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "content/public/browser/browser_thread.h"
#include "net/http/http_server_properties_manager.h"
+namespace {
+
+// Connects the HttpServerPropertiesManager's storage to the Chrome prefs.
+class PrefServiceAdapter
+ : public net::HttpServerPropertiesManager::PrefDelegate {
+ public:
+ explicit PrefServiceAdapter(PrefService* pref_service)
+ : pref_service_(pref_service),
+ path_(prefs::kHttpServerProperties) {
+ pref_change_registrar_.Init(pref_service_);
+ }
+
+ ~PrefServiceAdapter() override {
+ }
+
+ // PrefDelegate implementation.
+ bool HasServerProperties() override {
+ return pref_service_->HasPrefPath(path_);
+ }
+ const base::DictionaryValue& GetServerProperties() const override {
+ // Guaranteed not to return null when the pref is registered
+ // (RegisterProfilePrefs was called).
+ return *pref_service_->GetDictionary(path_);
+ }
+ void SetServerProperties(const base::DictionaryValue& value) override {
+ return pref_service_->Set(path_, value);
+ }
+ void StartListeningForUpdates(const base::Closure& callback) override {
+ pref_change_registrar_.Add(path_, callback);
+ }
+ void StopListeningForUpdates() override {
+ pref_change_registrar_.RemoveAll();
+ }
+
+ private:
+ PrefService* pref_service_;
+ const std::string path_;
+ PrefChangeRegistrar pref_change_registrar_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrefServiceAdapter);
+};
+
+} // namespace
+
namespace chrome_browser_net {
/* static */
@@ -16,8 +62,7 @@ net::HttpServerPropertiesManager*
HttpServerPropertiesManagerFactory::CreateManager(PrefService* pref_service) {
using content::BrowserThread;
return new net::HttpServerPropertiesManager(
- pref_service,
- prefs::kHttpServerProperties,
+ new PrefServiceAdapter(pref_service), // Transfers ownership.
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
}
« no previous file with comments | « no previous file | components/cronet/android/cronet_url_request_context_adapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698