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)); |
} |