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

Side by Side Diff: chrome/browser/extensions/api/font_settings/font_settings_api.h

Issue 11345008: Remove content::NotificationObserver dependency from most Prefs code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head for commit Created 8 years, 1 month 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 // Defines the classes to realize the Font Settings Extension API as specified 5 // Defines the classes to realize the Font Settings Extension API as specified
6 // in the extension API JSON. 6 // in the extension API JSON.
7 7
8 #ifndef CHROME_BROWSER_EXTENSIONS_API_FONT_SETTINGS_FONT_SETTINGS_API_H__ 8 #ifndef CHROME_BROWSER_EXTENSIONS_API_FONT_SETTINGS_FONT_SETTINGS_API_H__
9 #define CHROME_BROWSER_EXTENSIONS_API_FONT_SETTINGS_FONT_SETTINGS_API_H__ 9 #define CHROME_BROWSER_EXTENSIONS_API_FONT_SETTINGS_FONT_SETTINGS_API_H__
10 10
11 #include <map> 11 #include <map>
12 #include <string> 12 #include <string>
13 #include <utility> 13 #include <utility>
14 14
15 #include "base/prefs/public/pref_change_registrar.h" 15 #include "base/prefs/public/pref_change_registrar.h"
16 #include "base/prefs/public/pref_observer.h"
16 #include "chrome/browser/extensions/extension_function.h" 17 #include "chrome/browser/extensions/extension_function.h"
17 #include "chrome/browser/prefs/pref_service.h" 18 #include "chrome/browser/prefs/pref_service.h"
18 19
19 namespace extensions { 20 namespace extensions {
20 21
21 // This class observes pref changed events on a profile and dispatches the 22 // This class observes pref changed events on a profile and dispatches the
22 // corresponding extension API events to extensions. 23 // corresponding extension API events to extensions.
23 class FontSettingsEventRouter : public content::NotificationObserver { 24 class FontSettingsEventRouter : public PrefObserver {
24 public: 25 public:
25 // Constructor for observing pref changed events on |profile|. Stores a 26 // Constructor for observing pref changed events on |profile|. Stores a
26 // pointer to |profile| but does not take ownership. |profile| must be 27 // pointer to |profile| but does not take ownership. |profile| must be
27 // non-NULL and remain alive for the lifetime of the instance. Init() must be 28 // non-NULL and remain alive for the lifetime of the instance. Init() must be
28 // called to start observing pref changed events. 29 // called to start observing pref changed events.
29 explicit FontSettingsEventRouter(Profile* profile); 30 explicit FontSettingsEventRouter(Profile* profile);
30 virtual ~FontSettingsEventRouter(); 31 virtual ~FontSettingsEventRouter();
31 32
32 // Starts observing pref changed events on the profile. Must not be called 33 // Starts observing pref changed events on the profile. Must not be called
33 // more than once. 34 // more than once.
34 void Init(); 35 void Init();
35 36
36 private: 37 private:
37 typedef std::pair<std::string, std::string> EventAndKeyPair; 38 typedef std::pair<std::string, std::string> EventAndKeyPair;
38 // Map of pref name to a pair of event name and key (defined in the extension 39 // Map of pref name to a pair of event name and key (defined in the extension
39 // API) for dispatching a pref changed event. For example, 40 // API) for dispatching a pref changed event. For example,
40 // "webkit.webprefs.default_font_size" to ("onDefaultFontSizedChanged", 41 // "webkit.webprefs.default_font_size" to ("onDefaultFontSizedChanged",
41 // "pixelSize"). 42 // "pixelSize").
42 typedef std::map<std::string, EventAndKeyPair> PrefEventMap; 43 typedef std::map<std::string, EventAndKeyPair> PrefEventMap;
43 44
44 // Observes browser pref |pref_name|. When a change is observed, dispatches 45 // Observes browser pref |pref_name|. When a change is observed, dispatches
45 // event |event_name| to extensions. A JavaScript object is passed to the 46 // event |event_name| to extensions. A JavaScript object is passed to the
46 // extension event function with the new value of the pref in property |key|. 47 // extension event function with the new value of the pref in property |key|.
47 void AddPrefToObserve(const char* pref_name, 48 void AddPrefToObserve(const char* pref_name,
48 const char* event_name, 49 const char* event_name,
49 const char* key); 50 const char* key);
50 51
51 // content::NotificationObserver implementation. 52 // PrefObserver implementation.
52 virtual void Observe(int type, 53 virtual void OnPreferenceChanged(PrefServiceBase* service,
53 const content::NotificationSource& source, 54 const std::string& pref_name) OVERRIDE;
54 const content::NotificationDetails& details) OVERRIDE;
55 55
56 // Dispatches a changed event for the font setting for |generic_family| and 56 // Dispatches a changed event for the font setting for |generic_family| and
57 // |script| to extensions. The new value of the setting is the value of 57 // |script| to extensions. The new value of the setting is the value of
58 // browser pref |pref_name|. If the pref changed on the incognito profile, 58 // browser pref |pref_name|. If the pref changed on the incognito profile,
59 // |incognito| must be set to true for extensions to get the appropriate 59 // |incognito| must be set to true for extensions to get the appropriate
60 // event. 60 // event.
61 void OnFontNamePrefChanged(PrefService* pref_service, 61 void OnFontNamePrefChanged(PrefServiceBase* pref_service,
62 const std::string& pref_name, 62 const std::string& pref_name,
63 const std::string& generic_family, 63 const std::string& generic_family,
64 const std::string& script, 64 const std::string& script,
65 bool incognito); 65 bool incognito);
66 66
67 // Dispatches the setting changed event |event_name| to extensions. The new 67 // Dispatches the setting changed event |event_name| to extensions. The new
68 // value of the setting is the value of browser pref |pref_name|. This value 68 // value of the setting is the value of browser pref |pref_name|. This value
69 // is passed in the JavaScript object argument to the extension event function 69 // is passed in the JavaScript object argument to the extension event function
70 // under the key |key|. If the pref changed on the incognito profile, 70 // under the key |key|. If the pref changed on the incognito profile,
71 // |incognito| must be set to true for extensions to get the appropriate 71 // |incognito| must be set to true for extensions to get the appropriate
72 // event. 72 // event.
73 void OnFontPrefChanged(PrefService* pref_service, 73 void OnFontPrefChanged(PrefServiceBase* pref_service,
74 const std::string& pref_name, 74 const std::string& pref_name,
75 const std::string& event_name, 75 const std::string& event_name,
76 const std::string& key, 76 const std::string& key,
77 bool incognito); 77 bool incognito);
78 78
79 // Manages pref observation registration. 79 // Manages pref observation registration.
80 PrefChangeRegistrar registrar_; 80 PrefChangeRegistrar registrar_;
81 81
82 // Maps browser pref names to extension API <event name, key> pairs. 82 // Maps browser pref names to extension API <event name, key> pairs.
83 PrefEventMap pref_event_map_; 83 PrefEventMap pref_event_map_;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 virtual ~SetMinimumFontSizeFunction() {} 294 virtual ~SetMinimumFontSizeFunction() {}
295 295
296 // SetFontPrefExtensionFunction: 296 // SetFontPrefExtensionFunction:
297 virtual const char* GetPrefName() OVERRIDE; 297 virtual const char* GetPrefName() OVERRIDE;
298 virtual const char* GetKey() OVERRIDE; 298 virtual const char* GetKey() OVERRIDE;
299 }; 299 };
300 300
301 } // namespace extensions 301 } // namespace extensions
302 302
303 #endif // CHROME_BROWSER_EXTENSIONS_API_FONT_SETTINGS_FONT_SETTINGS_API_H__ 303 #endif // CHROME_BROWSER_EXTENSIONS_API_FONT_SETTINGS_FONT_SETTINGS_API_H__
OLDNEW
« no previous file with comments | « chrome/browser/content_settings/cookie_settings.cc ('k') | chrome/browser/extensions/api/font_settings/font_settings_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698