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

Side by Side Diff: chrome/browser/chromeos/settings/cros_settings.h

Issue 23494053: Remove NOTIFICATION_SYSTEM_SETTING_CHANGED, switch CrosSettings to base::CallbackRegistry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: oops Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_CROS_SETTINGS_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_CROS_SETTINGS_H_
6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_CROS_SETTINGS_H_ 6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_CROS_SETTINGS_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
12 #include "base/callback_registry.h"
12 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
14 #include "base/memory/scoped_ptr.h"
13 #include "base/observer_list.h" 15 #include "base/observer_list.h"
Mattias Nissler (ping if slow) 2013/09/18 09:09:48 remove
14 #include "base/threading/non_thread_safe.h" 16 #include "base/threading/non_thread_safe.h"
15 #include "chrome/browser/chromeos/settings/cros_settings_names.h" 17 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
16 #include "chrome/browser/chromeos/settings/cros_settings_provider.h" 18 #include "chrome/browser/chromeos/settings/cros_settings_provider.h"
17 #include "content/public/browser/notification_observer.h" 19 #include "content/public/browser/notification_observer.h"
Mattias Nissler (ping if slow) 2013/09/18 09:09:48 remove
18 20
19 namespace base { 21 namespace base {
20 class DictionaryValue; 22 class DictionaryValue;
21 class ListValue; 23 class ListValue;
22 class Value; 24 class Value;
23 } 25 }
24 26
25 namespace chromeos { 27 namespace chromeos {
26 28
27 class DeviceSettingsService; 29 class DeviceSettingsService;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 88
87 // Helper function for the whitelist op. Implemented here because we will need 89 // Helper function for the whitelist op. Implemented here because we will need
88 // this in a few places. The functions searches for |email| in the pref |path| 90 // this in a few places. The functions searches for |email| in the pref |path|
89 // It respects whitelists so foo@bar.baz will match *@bar.baz too. 91 // It respects whitelists so foo@bar.baz will match *@bar.baz too.
90 bool FindEmailInList(const std::string& path, const std::string& email) const; 92 bool FindEmailInList(const std::string& path, const std::string& email) const;
91 93
92 // Adding/removing of providers. 94 // Adding/removing of providers.
93 bool AddSettingsProvider(CrosSettingsProvider* provider); 95 bool AddSettingsProvider(CrosSettingsProvider* provider);
94 bool RemoveSettingsProvider(CrosSettingsProvider* provider); 96 bool RemoveSettingsProvider(CrosSettingsProvider* provider);
95 97
96 // If the pref at the given |path| changes, we call the observer's Observe 98 // Add an observer Callback for changes for the given |path|.
97 // method with NOTIFICATION_SYSTEM_SETTING_CHANGED. 99 typedef base::CallbackRegistry<void>::Subscription ObserverSubscription;
98 void AddSettingsObserver(const char* path, 100 scoped_ptr<ObserverSubscription> AddSettingsObserver(
99 content::NotificationObserver* obs); 101 const char* path, const base::Closure& callback);
Mattias Nissler (ping if slow) 2013/09/18 09:09:48 nit: parameters on separate lines
Avi (use Gerrit) 2013/09/18 16:41:44 Done.
100 void RemoveSettingsObserver(const char* path,
101 content::NotificationObserver* obs);
102 102
103 // Returns the provider that handles settings with the |path| or prefix. 103 // Returns the provider that handles settings with the |path| or prefix.
104 CrosSettingsProvider* GetProvider(const std::string& path) const; 104 CrosSettingsProvider* GetProvider(const std::string& path) const;
105 105
106 private: 106 private:
107 friend class CrosSettingsTest; 107 friend class CrosSettingsTest;
108 108
109 // Fires system setting change notification. 109 // Fires system setting change notification.
110 void FireObservers(const std::string& path); 110 void FireObservers(const std::string& path);
111 111
112 // List of ChromeOS system settings providers. 112 // List of ChromeOS system settings providers.
113 std::vector<CrosSettingsProvider*> providers_; 113 std::vector<CrosSettingsProvider*> providers_;
114 114
115 // A map from settings names to a list of observers. Observers get fired in 115 // A map from settings names to a list of observers. Observers get fired in
116 // the order they are added. 116 // the order they are added.
117 typedef ObserverList<content::NotificationObserver, true> 117 typedef base::hash_map<std::string, base::CallbackRegistry<void>*>
118 NotificationObserverList;
119 typedef base::hash_map<std::string, NotificationObserverList*>
120 SettingsObserverMap; 118 SettingsObserverMap;
121 SettingsObserverMap settings_observers_; 119 SettingsObserverMap settings_observers_;
122 120
123 DISALLOW_COPY_AND_ASSIGN(CrosSettings); 121 DISALLOW_COPY_AND_ASSIGN(CrosSettings);
124 }; 122 };
125 123
126 // Helper class for tests. Initializes the CrosSettings singleton on 124 // Helper class for tests. Initializes the CrosSettings singleton on
127 // construction and tears it down again on destruction. 125 // construction and tears it down again on destruction.
128 class ScopedTestCrosSettings { 126 class ScopedTestCrosSettings {
129 public: 127 public:
130 ScopedTestCrosSettings(); 128 ScopedTestCrosSettings();
131 ~ScopedTestCrosSettings(); 129 ~ScopedTestCrosSettings();
132 130
133 private: 131 private:
134 DISALLOW_COPY_AND_ASSIGN(ScopedTestCrosSettings); 132 DISALLOW_COPY_AND_ASSIGN(ScopedTestCrosSettings);
135 }; 133 };
136 134
137 } // namespace chromeos 135 } // namespace chromeos
138 136
139 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_CROS_SETTINGS_H_ 137 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_CROS_SETTINGS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698