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

Unified Diff: ios/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
Index: ios/chrome/browser/net/http_server_properties_manager_factory.cc
diff --git a/ios/chrome/browser/net/http_server_properties_manager_factory.cc b/ios/chrome/browser/net/http_server_properties_manager_factory.cc
index bf827e365f3f49af7587853186357a9bdb8dda08..59263a315af6950182024099f23ff4aa83fe5c9a 100644
--- a/ios/chrome/browser/net/http_server_properties_manager_factory.cc
+++ b/ios/chrome/browser/net/http_server_properties_manager_factory.cc
@@ -4,16 +4,59 @@
#include "ios/chrome/browser/net/http_server_properties_manager_factory.h"
+#include "base/prefs/pref_change_registrar.h"
+#include "base/prefs/pref_service.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "ios/chrome/browser/pref_names.h"
#include "ios/web/public/web_thread.h"
#include "net/http/http_server_properties_manager.h"
+namespace {
+
+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
+
// static
net::HttpServerPropertiesManager*
HttpServerPropertiesManagerFactory::CreateManager(PrefService* pref_service) {
return new net::HttpServerPropertiesManager(
- pref_service, prefs::kHttpServerProperties,
+ new PrefServiceAdapter(pref_service), // Transfers ownership.
web::WebThread::GetTaskRunnerForThread(web::WebThread::IO));
}
« no previous file with comments | « components/cronet/android/cronet_url_request_context_adapter.cc ('k') | net/http/http_server_properties_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698