OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_WEBUI_OPTIONS_CORE_OPTIONS_HANDLER_H_ |
| 6 #define CHROME_BROWSER_WEBUI_OPTIONS_CORE_OPTIONS_HANDLER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <map> |
| 10 #include <string> |
| 11 |
| 12 #include "base/values.h" |
| 13 #include "chrome/browser/dom_ui/options/options_ui.h" |
| 14 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 15 |
| 16 // Core options UI handler. |
| 17 // Handles resource and JS calls common to all options sub-pages. |
| 18 class CoreOptionsHandler : public OptionsPageUIHandler { |
| 19 public: |
| 20 CoreOptionsHandler(); |
| 21 virtual ~CoreOptionsHandler(); |
| 22 |
| 23 // OptionsUIHandler implementation. |
| 24 virtual void GetLocalizedValues(DictionaryValue* localized_strings); |
| 25 virtual void Uninitialize(); |
| 26 |
| 27 // NotificationObserver implementation. |
| 28 virtual void Observe(NotificationType type, |
| 29 const NotificationSource& source, |
| 30 const NotificationDetails& details); |
| 31 |
| 32 // WebUIMessageHandler implementation. |
| 33 virtual void RegisterMessages(); |
| 34 virtual WebUIMessageHandler* Attach(WebUI* web_ui); |
| 35 |
| 36 protected: |
| 37 // Fetches a pref value of given |pref_name|. |
| 38 // Note that caller owns the returned Value. |
| 39 virtual Value* FetchPref(const std::string& pref_name); |
| 40 |
| 41 // Observes a pref of given |pref_name|. |
| 42 virtual void ObservePref(const std::string& pref_name); |
| 43 |
| 44 // Sets a pref |value| to given |pref_name|. |
| 45 virtual void SetPref(const std::string& pref_name, |
| 46 const Value* value, |
| 47 const std::string& metric); |
| 48 |
| 49 // Clears pref value for given |pref_name|. |
| 50 void ClearPref(const std::string& pref_name, const std::string& metric); |
| 51 |
| 52 // Stops observing given preference identified by |path|. |
| 53 virtual void StopObservingPref(const std::string& path); |
| 54 |
| 55 // Records a user metric action for the given value. |
| 56 void ProcessUserMetric(const Value* value, |
| 57 const std::string& metric); |
| 58 |
| 59 typedef std::multimap<std::string, std::wstring> PreferenceCallbackMap; |
| 60 PreferenceCallbackMap pref_callback_map_; |
| 61 private: |
| 62 // Callback for the "coreOptionsInitialize" message. This message will |
| 63 // trigger the Initialize() method of all other handlers so that final |
| 64 // setup can be performed before the page is shown. |
| 65 void HandleInitialize(const ListValue* args); |
| 66 |
| 67 // Callback for the "fetchPrefs" message. This message accepts the list of |
| 68 // preference names passed as the |args| parameter (ListValue). It passes |
| 69 // results dictionary of preference values by calling prefsFetched() JS method |
| 70 // on the page. |
| 71 void HandleFetchPrefs(const ListValue* args); |
| 72 |
| 73 // Callback for the "observePrefs" message. This message initiates |
| 74 // notification observing for given array of preference names. |
| 75 void HandleObservePrefs(const ListValue* args); |
| 76 |
| 77 // Callbacks for the "set<type>Pref" message. This message saves the new |
| 78 // preference value. |args| is an array of parameters as follows: |
| 79 // item 0 - name of the preference. |
| 80 // item 1 - the value of the preference in string form. |
| 81 // item 2 - name of the metric identifier (optional). |
| 82 void HandleSetBooleanPref(const ListValue* args); |
| 83 void HandleSetIntegerPref(const ListValue* args); |
| 84 void HandleSetDoublePref(const ListValue* args); |
| 85 void HandleSetStringPref(const ListValue* args); |
| 86 void HandleSetListPref(const ListValue* args); |
| 87 |
| 88 void HandleSetPref(const ListValue* args, Value::ValueType type); |
| 89 |
| 90 // Callback for the "clearPref" message. This message clears a preference |
| 91 // value. |args| is an array of parameters as follows: |
| 92 // item 0 - name of the preference. |
| 93 // item 1 - name of the metric identifier (optional). |
| 94 void HandleClearPref(const ListValue* args); |
| 95 |
| 96 // Callback for the "coreOptionsUserMetricsAction" message. This records |
| 97 // an action that should be tracked if metrics recording is enabled. |args| |
| 98 // is an array that contains a single item, the name of the metric identifier. |
| 99 void HandleUserMetricsAction(const ListValue* args); |
| 100 |
| 101 void NotifyPrefChanged(const std::string* pref_name); |
| 102 |
| 103 PrefChangeRegistrar registrar_; |
| 104 |
| 105 DISALLOW_COPY_AND_ASSIGN(CoreOptionsHandler); |
| 106 }; |
| 107 |
| 108 #endif // CHROME_BROWSER_WEBUI_OPTIONS_CORE_OPTIONS_HANDLER_H_ |
OLD | NEW |