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

Side by Side 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: includes 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/net/http_server_properties_manager_factory.h" 5 #include "chrome/browser/net/http_server_properties_manager_factory.h"
6 6
7 #include "base/bind.h"
8 #include "base/prefs/pref_change_registrar.h"
9 #include "base/prefs/pref_service.h"
7 #include "chrome/common/pref_names.h" 10 #include "chrome/common/pref_names.h"
8 #include "components/pref_registry/pref_registry_syncable.h" 11 #include "components/pref_registry/pref_registry_syncable.h"
9 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
10 #include "net/http/http_server_properties_manager.h" 13 #include "net/http/http_server_properties_manager.h"
11 14
15 namespace {
16
17 // Connects the HttpServerPropertiesManager's storage to the Chrome prefs.
18 class PrefServiceAdapter
19 : public net::HttpServerPropertiesManager::PrefDelegate {
20 public:
21 explicit PrefServiceAdapter(PrefService* pref_service)
22 : pref_service_(pref_service),
23 path_(prefs::kHttpServerProperties) {
24 pref_change_registrar_.Init(pref_service_);
25 }
26
27 ~PrefServiceAdapter() override {
28 }
29
30 // PrefDelegate implementation.
31 bool HasServerProperties() override {
32 return pref_service_->HasPrefPath(path_);
33 }
34 const base::DictionaryValue& GetServerProperties() const override {
35 // Guaranteed not to return null when the pref is registered
36 // (RegisterProfilePrefs was called).
37 return *pref_service_->GetDictionary(path_);
38 }
39 void SetServerProperties(const base::Value& value) override {
40 return pref_service_->Set(path_, value);
41 }
42 void StartListeningForUpdates(const base::Closure& callback) override {
43 pref_change_registrar_.Add(path_, callback);
44 }
45 void StopListeningForUpdates() override {
46 pref_change_registrar_.RemoveAll();
47 }
48
49 private:
50 PrefService* pref_service_;
51 std::string path_;
52 PrefChangeRegistrar pref_change_registrar_;
53
54 DISALLOW_COPY_AND_ASSIGN(PrefServiceAdapter);
55 };
56
57 } // namespace
58
12 namespace chrome_browser_net { 59 namespace chrome_browser_net {
13 60
14 /* static */ 61 /* static */
15 net::HttpServerPropertiesManager* 62 net::HttpServerPropertiesManager*
16 HttpServerPropertiesManagerFactory::CreateManager(PrefService* pref_service) { 63 HttpServerPropertiesManagerFactory::CreateManager(PrefService* pref_service) {
17 using content::BrowserThread; 64 using content::BrowserThread;
18 return new net::HttpServerPropertiesManager( 65 return new net::HttpServerPropertiesManager(
19 pref_service, 66 new PrefServiceAdapter(pref_service), // Transfers ownership.
20 prefs::kHttpServerProperties,
21 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); 67 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
22 } 68 }
23 69
24 /* static */ 70 /* static */
25 void HttpServerPropertiesManagerFactory::RegisterProfilePrefs( 71 void HttpServerPropertiesManagerFactory::RegisterProfilePrefs(
26 user_prefs::PrefRegistrySyncable* registry) { 72 user_prefs::PrefRegistrySyncable* registry) {
27 registry->RegisterDictionaryPref(prefs::kHttpServerProperties); 73 registry->RegisterDictionaryPref(prefs::kHttpServerProperties);
28 } 74 }
29 75
30 } // namespace chrome_browser_net 76 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698