OLD | NEW |
---|---|
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_UI_WEBUI_OPTIONS_CORE_OPTIONS_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_CORE_OPTIONS_HANDLER_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CORE_OPTIONS_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CORE_OPTIONS_HANDLER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/prefs/public/pref_change_registrar.h" | 12 #include "base/prefs/public/pref_change_registrar.h" |
13 #include "base/prefs/public/pref_observer.h" | |
14 #include "base/values.h" | 13 #include "base/values.h" |
15 #include "chrome/browser/plugins/plugin_status_pref_setter.h" | 14 #include "chrome/browser/plugins/plugin_status_pref_setter.h" |
16 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
17 #include "chrome/browser/ui/webui/options/options_ui.h" | 16 #include "chrome/browser/ui/webui/options/options_ui.h" |
18 | 17 |
19 namespace options { | 18 namespace options { |
20 | 19 |
21 // Core options UI handler. | 20 // Core options UI handler. |
22 // Handles resource and JS calls common to all options sub-pages. | 21 // Handles resource and JS calls common to all options sub-pages. |
23 class CoreOptionsHandler : public OptionsPageUIHandler, | 22 class CoreOptionsHandler : public OptionsPageUIHandler { |
24 public PrefObserver { | |
25 public: | 23 public: |
26 CoreOptionsHandler(); | 24 CoreOptionsHandler(); |
27 virtual ~CoreOptionsHandler(); | 25 virtual ~CoreOptionsHandler(); |
28 | 26 |
29 // OptionsPageUIHandler implementation. | 27 // OptionsPageUIHandler implementation. |
30 virtual void GetLocalizedValues(DictionaryValue* localized_strings) OVERRIDE; | 28 virtual void GetLocalizedValues(DictionaryValue* localized_strings) OVERRIDE; |
31 virtual void InitializeHandler() OVERRIDE; | 29 virtual void InitializeHandler() OVERRIDE; |
32 virtual void InitializePage() OVERRIDE; | 30 virtual void InitializePage() OVERRIDE; |
33 virtual void Uninitialize() OVERRIDE; | 31 virtual void Uninitialize() OVERRIDE; |
34 | 32 |
35 // PrefObserver implementation. | |
36 virtual void OnPreferenceChanged(PrefServiceBase* service, | |
37 const std::string& pref_name) OVERRIDE; | |
38 | |
39 // WebUIMessageHandler implementation. | 33 // WebUIMessageHandler implementation. |
40 virtual void RegisterMessages() OVERRIDE; | 34 virtual void RegisterMessages() OVERRIDE; |
41 | 35 |
42 void set_handlers_host(OptionsPageUIHandlerHost* handlers_host) { | 36 void set_handlers_host(OptionsPageUIHandlerHost* handlers_host) { |
43 handlers_host_ = handlers_host; | 37 handlers_host_ = handlers_host; |
44 } | 38 } |
45 | 39 |
46 // Adds localized strings to |localized_strings|. | 40 // Adds localized strings to |localized_strings|. |
47 static void GetStaticLocalizedValues( | 41 static void GetStaticLocalizedValues( |
48 base::DictionaryValue* localized_strings); | 42 base::DictionaryValue* localized_strings); |
(...skipping 14 matching lines...) Expand all Loading... | |
63 const base::Value* value, | 57 const base::Value* value, |
64 const std::string& metric); | 58 const std::string& metric); |
65 | 59 |
66 // Clears pref value for given |pref_name|. | 60 // Clears pref value for given |pref_name|. |
67 void ClearPref(const std::string& pref_name, const std::string& metric); | 61 void ClearPref(const std::string& pref_name, const std::string& metric); |
68 | 62 |
69 // Records a user metric action for the given value. | 63 // Records a user metric action for the given value. |
70 void ProcessUserMetric(const base::Value* value, | 64 void ProcessUserMetric(const base::Value* value, |
71 const std::string& metric); | 65 const std::string& metric); |
72 | 66 |
67 // We need to use virtual dispatch as handling of some prefs may be | |
68 // finessed in subclasses. We need to include the PrefServiceBase | |
69 // pointer so that subclasses can know whether we are observing the | |
70 // pref from the local state or not. | |
Mattias Nissler (ping if slow)
2012/12/04 10:47:12
Some people feel strongly about avoiding use of pr
Jói
2012/12/04 10:55:57
The rest of the comments in this file seem to avoi
| |
71 virtual void OnPreferenceChanged(PrefServiceBase* service, | |
72 const std::string& pref_name); | |
73 | |
73 // Notifies registered JS callbacks on change in |pref_name| preference. | 74 // Notifies registered JS callbacks on change in |pref_name| preference. |
74 // |controlling_pref_name| controls if |pref_name| is managed by | 75 // |controlling_pref_name| controls if |pref_name| is managed by |
75 // policy/extension; empty |controlling_pref_name| indicates no other pref is | 76 // policy/extension; empty |controlling_pref_name| indicates no other pref is |
76 // controlling |pref_name|. | 77 // controlling |pref_name|. |
77 void NotifyPrefChanged(const std::string& pref_name, | 78 void NotifyPrefChanged(const std::string& pref_name, |
78 const std::string& controlling_pref_name); | 79 const std::string& controlling_pref_name); |
79 | 80 |
80 // Calls JS callbacks to report a change in the value of the |name| | 81 // Calls JS callbacks to report a change in the value of the |name| |
81 // preference. |value| is the new value for |name|. Called from | 82 // preference. |value| is the new value for |name|. Called from |
82 // Notify*Changed methods to fire off the notifications. | 83 // Notify*Changed methods to fire off the notifications. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 typedef std::map<std::string, base::Callback<bool(const base::Value*)> > | 167 typedef std::map<std::string, base::Callback<bool(const base::Value*)> > |
167 PrefChangeFilterMap; | 168 PrefChangeFilterMap; |
168 PrefChangeFilterMap pref_change_filters_; | 169 PrefChangeFilterMap pref_change_filters_; |
169 | 170 |
170 DISALLOW_COPY_AND_ASSIGN(CoreOptionsHandler); | 171 DISALLOW_COPY_AND_ASSIGN(CoreOptionsHandler); |
171 }; | 172 }; |
172 | 173 |
173 } // namespace options | 174 } // namespace options |
174 | 175 |
175 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CORE_OPTIONS_HANDLER_H_ | 176 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CORE_OPTIONS_HANDLER_H_ |
OLD | NEW |