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

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: trailing space 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"
13 #include "base/observer_list.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/non_thread_safe.h" 15 #include "base/threading/non_thread_safe.h"
15 #include "chrome/browser/chromeos/settings/cros_settings_names.h" 16 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
16 #include "chrome/browser/chromeos/settings/cros_settings_provider.h" 17 #include "chrome/browser/chromeos/settings/cros_settings_provider.h"
17 #include "content/public/browser/notification_observer.h"
18 18
19 namespace base { 19 namespace base {
20 class DictionaryValue; 20 class DictionaryValue;
21 class ListValue; 21 class ListValue;
22 class Value; 22 class Value;
23 } 23 }
24 24
25 namespace chromeos { 25 namespace chromeos {
26 26
27 class DeviceSettingsService; 27 class DeviceSettingsService;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 // Helper function for the whitelist op. Implemented here because we will need 87 // 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| 88 // 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. 89 // It respects whitelists so foo@bar.baz will match *@bar.baz too.
90 bool FindEmailInList(const std::string& path, const std::string& email) const; 90 bool FindEmailInList(const std::string& path, const std::string& email) const;
91 91
92 // Adding/removing of providers. 92 // Adding/removing of providers.
93 bool AddSettingsProvider(CrosSettingsProvider* provider); 93 bool AddSettingsProvider(CrosSettingsProvider* provider);
94 bool RemoveSettingsProvider(CrosSettingsProvider* provider); 94 bool RemoveSettingsProvider(CrosSettingsProvider* provider);
95 95
96 // If the pref at the given |path| changes, we call the observer's Observe 96 // Add an observer Callback for changes for the given |path|.
97 // method with NOTIFICATION_SYSTEM_SETTING_CHANGED. 97 typedef base::CallbackRegistry<void>::Subscription ObserverSubscription;
98 void AddSettingsObserver(const char* path, 98 scoped_ptr<ObserverSubscription> AddSettingsObserver(
99 content::NotificationObserver* obs); 99 const std::string& path,
100 void RemoveSettingsObserver(const char* path, 100 const base::Closure& callback);
101 content::NotificationObserver* obs);
102 101
103 // Returns the provider that handles settings with the |path| or prefix. 102 // Returns the provider that handles settings with the |path| or prefix.
104 CrosSettingsProvider* GetProvider(const std::string& path) const; 103 CrosSettingsProvider* GetProvider(const std::string& path) const;
105 104
106 private: 105 private:
107 friend class CrosSettingsTest; 106 friend class CrosSettingsTest;
108 107
109 // Fires system setting change notification. 108 // Fires system setting change callback.
110 void FireObservers(const std::string& path); 109 void FireObservers(const std::string& path);
111 110
112 // List of ChromeOS system settings providers. 111 // List of ChromeOS system settings providers.
113 std::vector<CrosSettingsProvider*> providers_; 112 std::vector<CrosSettingsProvider*> providers_;
114 113
115 // A map from settings names to a list of observers. Observers get fired in 114 // A map from settings names to a list of observers. Observers get fired in
116 // the order they are added. 115 // the order they are added.
117 typedef ObserverList<content::NotificationObserver, true> 116 typedef base::hash_map<std::string, base::CallbackRegistry<void>*>
118 NotificationObserverList;
119 typedef base::hash_map<std::string, NotificationObserverList*>
120 SettingsObserverMap; 117 SettingsObserverMap;
121 SettingsObserverMap settings_observers_; 118 SettingsObserverMap settings_observers_;
122 119
123 DISALLOW_COPY_AND_ASSIGN(CrosSettings); 120 DISALLOW_COPY_AND_ASSIGN(CrosSettings);
124 }; 121 };
125 122
126 // Helper class for tests. Initializes the CrosSettings singleton on 123 // Helper class for tests. Initializes the CrosSettings singleton on
127 // construction and tears it down again on destruction. 124 // construction and tears it down again on destruction.
128 class ScopedTestCrosSettings { 125 class ScopedTestCrosSettings {
129 public: 126 public:
130 ScopedTestCrosSettings(); 127 ScopedTestCrosSettings();
131 ~ScopedTestCrosSettings(); 128 ~ScopedTestCrosSettings();
132 129
133 private: 130 private:
134 DISALLOW_COPY_AND_ASSIGN(ScopedTestCrosSettings); 131 DISALLOW_COPY_AND_ASSIGN(ScopedTestCrosSettings);
135 }; 132 };
136 133
137 } // namespace chromeos 134 } // namespace chromeos
138 135
139 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_CROS_SETTINGS_H_ 136 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_CROS_SETTINGS_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/device_status_collector.cc ('k') | chrome/browser/chromeos/settings/cros_settings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698