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

Side by Side Diff: chrome/browser/extensions/api/preference/preference_api.h

Issue 11682005: Remove some Profile-keyed factory boilerplate: management omnibox preference push_messaging. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__
6 #define CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ 6 #define CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/prefs/public/pref_change_registrar.h" 10 #include "base/prefs/public/pref_change_registrar.h"
11 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
11 #include "chrome/browser/extensions/event_router.h" 12 #include "chrome/browser/extensions/event_router.h"
12 #include "chrome/browser/extensions/extension_function.h" 13 #include "chrome/browser/extensions/extension_function.h"
13 #include "chrome/browser/profiles/profile_keyed_service.h"
14 #include "content/public/browser/notification_observer.h" 14 #include "content/public/browser/notification_observer.h"
15 15
16 class PrefService; 16 class PrefService;
17 17
18 namespace base { 18 namespace base {
19 class Value; 19 class Value;
20 } 20 }
21 21
22 namespace extensions { 22 namespace extensions {
23 23
24 class PreferenceEventRouter { 24 class PreferenceEventRouter {
25 public: 25 public:
26 explicit PreferenceEventRouter(Profile* profile); 26 explicit PreferenceEventRouter(Profile* profile);
27 virtual ~PreferenceEventRouter(); 27 virtual ~PreferenceEventRouter();
28 28
29 private: 29 private:
30 void OnPrefChanged(PrefServiceBase* pref_service, 30 void OnPrefChanged(PrefServiceBase* pref_service,
31 const std::string& pref_key); 31 const std::string& pref_key);
32 32
33 PrefChangeRegistrar registrar_; 33 PrefChangeRegistrar registrar_;
34 PrefChangeRegistrar incognito_registrar_; 34 PrefChangeRegistrar incognito_registrar_;
35 35
36 // Weak, owns us (transitively via ExtensionService). 36 // Weak, owns us (transitively via ExtensionService).
37 Profile* profile_; 37 Profile* profile_;
38 38
39 DISALLOW_COPY_AND_ASSIGN(PreferenceEventRouter); 39 DISALLOW_COPY_AND_ASSIGN(PreferenceEventRouter);
40 }; 40 };
41 41
42 class PreferenceAPI : public ProfileKeyedService, 42 class PreferenceAPI : public ProfileKeyedAPI,
43 public EventRouter::Observer { 43 public EventRouter::Observer {
44 public: 44 public:
45 explicit PreferenceAPI(Profile* profile); 45 explicit PreferenceAPI(Profile* profile);
46 virtual ~PreferenceAPI(); 46 virtual ~PreferenceAPI();
47 47
48 // ProfileKeyedService implementation. 48 // ProfileKeyedService implementation.
49 virtual void Shutdown() OVERRIDE; 49 virtual void Shutdown() OVERRIDE;
50 50
51 // EventRouter::Observer implementation. 51 // EventRouter::Observer implementation.
52 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; 52 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE;
53 53
54 private: 54 private:
55 friend class ProfileKeyedAPIFactory<PreferenceAPI>;
56
55 Profile* profile_; 57 Profile* profile_;
56 58
59 // ProfileKeyedAPI implementation.
60 static const char* service_name() {
61 return "PreferenceAPI";
62 }
63 static const bool kServiceIsNULLWhileTesting = true;
64
57 // Created lazily upon OnListenerAdded. 65 // Created lazily upon OnListenerAdded.
58 scoped_ptr<PreferenceEventRouter> preference_event_router_; 66 scoped_ptr<PreferenceEventRouter> preference_event_router_;
67
68 DISALLOW_COPY_AND_ASSIGN(PreferenceAPI);
59 }; 69 };
60 70
71 template <>
72 ProfileKeyedAPIFactory<PreferenceAPI>*
73 ProfileKeyedAPIFactory<PreferenceAPI>::GetInstance();
74
61 class PrefTransformerInterface { 75 class PrefTransformerInterface {
62 public: 76 public:
63 virtual ~PrefTransformerInterface() {} 77 virtual ~PrefTransformerInterface() {}
64 78
65 // Converts the representation of a preference as seen by the extension 79 // Converts the representation of a preference as seen by the extension
66 // into a representation that is used in the pref stores of the browser. 80 // into a representation that is used in the pref stores of the browser.
67 // Returns the pref store representation in case of success or sets 81 // Returns the pref store representation in case of success or sets
68 // |error| and returns NULL otherwise. |bad_message| is passed to simulate 82 // |error| and returns NULL otherwise. |bad_message| is passed to simulate
69 // the behavior of EXTENSION_FUNCTION_VALIDATE. It is never NULL. 83 // the behavior of EXTENSION_FUNCTION_VALIDATE. It is never NULL.
70 // The ownership of the returned value is passed to the caller. 84 // The ownership of the returned value is passed to the caller.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 protected: 139 protected:
126 virtual ~ClearPreferenceFunction(); 140 virtual ~ClearPreferenceFunction();
127 141
128 // ExtensionFunction: 142 // ExtensionFunction:
129 virtual bool RunImpl() OVERRIDE; 143 virtual bool RunImpl() OVERRIDE;
130 }; 144 };
131 145
132 } // namespace extensions 146 } // namespace extensions
133 147
134 #endif // CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ 148 #endif // CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698