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

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: rebase 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 // ProfileKeyedAPI implementation.
52 static ProfileKeyedAPIFactory<PreferenceAPI>* GetFactoryInstance();
53
51 // EventRouter::Observer implementation. 54 // EventRouter::Observer implementation.
52 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; 55 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE;
53 56
54 private: 57 private:
58 friend class ProfileKeyedAPIFactory<PreferenceAPI>;
59
55 Profile* profile_; 60 Profile* profile_;
56 61
62 // ProfileKeyedAPI implementation.
63 static const char* service_name() {
64 return "PreferenceAPI";
65 }
66 static const bool kServiceIsNULLWhileTesting = true;
67
57 // Created lazily upon OnListenerAdded. 68 // Created lazily upon OnListenerAdded.
58 scoped_ptr<PreferenceEventRouter> preference_event_router_; 69 scoped_ptr<PreferenceEventRouter> preference_event_router_;
70
71 DISALLOW_COPY_AND_ASSIGN(PreferenceAPI);
59 }; 72 };
60 73
61 class PrefTransformerInterface { 74 class PrefTransformerInterface {
62 public: 75 public:
63 virtual ~PrefTransformerInterface() {} 76 virtual ~PrefTransformerInterface() {}
64 77
65 // Converts the representation of a preference as seen by the extension 78 // 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. 79 // 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 80 // Returns the pref store representation in case of success or sets
68 // |error| and returns NULL otherwise. |bad_message| is passed to simulate 81 // |error| and returns NULL otherwise. |bad_message| is passed to simulate
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 protected: 138 protected:
126 virtual ~ClearPreferenceFunction(); 139 virtual ~ClearPreferenceFunction();
127 140
128 // ExtensionFunction: 141 // ExtensionFunction:
129 virtual bool RunImpl() OVERRIDE; 142 virtual bool RunImpl() OVERRIDE;
130 }; 143 };
131 144
132 } // namespace extensions 145 } // namespace extensions
133 146
134 #endif // CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ 147 #endif // CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698