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

Side by Side Diff: chrome/browser/extensions/api/management/management_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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/management/management_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_MANAGEMENT_MANAGEMENT_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
9 #include "chrome/browser/extensions/event_router.h" 10 #include "chrome/browser/extensions/event_router.h"
10 #include "chrome/browser/extensions/extension_function.h" 11 #include "chrome/browser/extensions/extension_function.h"
11 #include "chrome/browser/extensions/extension_install_prompt.h" 12 #include "chrome/browser/extensions/extension_install_prompt.h"
12 #include "chrome/browser/extensions/extension_uninstall_dialog.h" 13 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
13 #include "chrome/browser/profiles/profile_keyed_service.h" 14 #include "chrome/browser/profiles/profile_keyed_service.h"
14 #include "content/public/browser/notification_observer.h" 15 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h" 16 #include "content/public/browser/notification_registrar.h"
16 17
17 class ExtensionService; 18 class ExtensionService;
18 class ExtensionUninstallDialog; 19 class ExtensionUninstallDialog;
19 20
20 class ExtensionManagementFunction : public SyncExtensionFunction { 21 namespace extensions {
22
23 class ManagementFunction : public SyncExtensionFunction {
21 protected: 24 protected:
22 virtual ~ExtensionManagementFunction() {} 25 virtual ~ManagementFunction() {}
23 26
24 ExtensionService* service(); 27 ExtensionService* service();
25 }; 28 };
26 29
27 class AsyncExtensionManagementFunction : public AsyncExtensionFunction { 30 class AsyncManagementFunction : public AsyncExtensionFunction {
28 protected: 31 protected:
29 virtual ~AsyncExtensionManagementFunction() {} 32 virtual ~AsyncManagementFunction() {}
30 33
31 ExtensionService* service(); 34 ExtensionService* service();
32 }; 35 };
33 36
34 class GetAllExtensionsFunction : public ExtensionManagementFunction { 37 class GetAllExtensionsFunction : public ManagementFunction {
35 public: 38 public:
36 DECLARE_EXTENSION_FUNCTION_NAME("management.getAll"); 39 DECLARE_EXTENSION_FUNCTION_NAME("management.getAll");
37 40
38 protected: 41 protected:
39 virtual ~GetAllExtensionsFunction() {} 42 virtual ~GetAllExtensionsFunction() {}
40 43
41 // ExtensionFunction: 44 // ExtensionFunction:
42 virtual bool RunImpl() OVERRIDE; 45 virtual bool RunImpl() OVERRIDE;
43 }; 46 };
44 47
45 class GetExtensionByIdFunction : public ExtensionManagementFunction { 48 class GetExtensionByIdFunction : public ManagementFunction {
46 public: 49 public:
47 DECLARE_EXTENSION_FUNCTION_NAME("management.get"); 50 DECLARE_EXTENSION_FUNCTION_NAME("management.get");
48 51
49 protected: 52 protected:
50 virtual ~GetExtensionByIdFunction() {} 53 virtual ~GetExtensionByIdFunction() {}
51 54
52 // ExtensionFunction: 55 // ExtensionFunction:
53 virtual bool RunImpl() OVERRIDE; 56 virtual bool RunImpl() OVERRIDE;
54 }; 57 };
55 58
56 class GetPermissionWarningsByIdFunction : public ExtensionManagementFunction { 59 class GetPermissionWarningsByIdFunction : public ManagementFunction {
57 public: 60 public:
58 DECLARE_EXTENSION_FUNCTION_NAME("management.getPermissionWarningsById"); 61 DECLARE_EXTENSION_FUNCTION_NAME("management.getPermissionWarningsById");
59 62
60 protected: 63 protected:
61 virtual ~GetPermissionWarningsByIdFunction() {} 64 virtual ~GetPermissionWarningsByIdFunction() {}
62 65
63 // ExtensionFunction: 66 // ExtensionFunction:
64 virtual bool RunImpl() OVERRIDE; 67 virtual bool RunImpl() OVERRIDE;
65 }; 68 };
66 69
67 class GetPermissionWarningsByManifestFunction : public AsyncExtensionFunction { 70 class GetPermissionWarningsByManifestFunction : public AsyncExtensionFunction {
68 public: 71 public:
69 DECLARE_EXTENSION_FUNCTION_NAME( 72 DECLARE_EXTENSION_FUNCTION_NAME(
70 "management.getPermissionWarningsByManifest"); 73 "management.getPermissionWarningsByManifest");
71 74
72 // Called when utility process finishes. 75 // Called when utility process finishes.
73 void OnParseSuccess(base::DictionaryValue* parsed_manifest); 76 void OnParseSuccess(base::DictionaryValue* parsed_manifest);
74 void OnParseFailure(const std::string& error); 77 void OnParseFailure(const std::string& error);
75 78
76 protected: 79 protected:
77 virtual ~GetPermissionWarningsByManifestFunction() {} 80 virtual ~GetPermissionWarningsByManifestFunction() {}
78 81
79 // ExtensionFunction: 82 // ExtensionFunction:
80 virtual bool RunImpl() OVERRIDE; 83 virtual bool RunImpl() OVERRIDE;
81 }; 84 };
82 85
83 class LaunchAppFunction : public ExtensionManagementFunction { 86 class LaunchAppFunction : public ManagementFunction {
84 public: 87 public:
85 DECLARE_EXTENSION_FUNCTION_NAME("management.launchApp"); 88 DECLARE_EXTENSION_FUNCTION_NAME("management.launchApp");
86 89
87 protected: 90 protected:
88 virtual ~LaunchAppFunction() {} 91 virtual ~LaunchAppFunction() {}
89 92
90 // ExtensionFunction: 93 // ExtensionFunction:
91 virtual bool RunImpl() OVERRIDE; 94 virtual bool RunImpl() OVERRIDE;
92 }; 95 };
93 96
94 class SetEnabledFunction : public AsyncExtensionManagementFunction, 97 class SetEnabledFunction : public AsyncManagementFunction,
95 public ExtensionInstallPrompt::Delegate { 98 public ExtensionInstallPrompt::Delegate {
96 public: 99 public:
97 DECLARE_EXTENSION_FUNCTION_NAME("management.setEnabled"); 100 DECLARE_EXTENSION_FUNCTION_NAME("management.setEnabled");
98 101
99 SetEnabledFunction(); 102 SetEnabledFunction();
100 103
101 protected: 104 protected:
102 virtual ~SetEnabledFunction(); 105 virtual ~SetEnabledFunction();
103 106
104 // ExtensionFunction: 107 // ExtensionFunction:
105 virtual bool RunImpl() OVERRIDE; 108 virtual bool RunImpl() OVERRIDE;
106 109
107 // ExtensionInstallPrompt::Delegate. 110 // ExtensionInstallPrompt::Delegate.
108 virtual void InstallUIProceed() OVERRIDE; 111 virtual void InstallUIProceed() OVERRIDE;
109 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; 112 virtual void InstallUIAbort(bool user_initiated) OVERRIDE;
110 113
111 private: 114 private:
112 std::string extension_id_; 115 std::string extension_id_;
113 116
114 // Used for prompting to re-enable items with permissions escalation updates. 117 // Used for prompting to re-enable items with permissions escalation updates.
115 scoped_ptr<ExtensionInstallPrompt> install_prompt_; 118 scoped_ptr<ExtensionInstallPrompt> install_prompt_;
116 }; 119 };
117 120
118 class UninstallFunction : public AsyncExtensionManagementFunction, 121 class UninstallFunction : public AsyncManagementFunction,
119 public ExtensionUninstallDialog::Delegate { 122 public ExtensionUninstallDialog::Delegate {
120 public: 123 public:
121 DECLARE_EXTENSION_FUNCTION_NAME("management.uninstall"); 124 DECLARE_EXTENSION_FUNCTION_NAME("management.uninstall");
122 125
123 UninstallFunction(); 126 UninstallFunction();
124 static void SetAutoConfirmForTest(bool should_proceed); 127 static void SetAutoConfirmForTest(bool should_proceed);
125 128
126 // ExtensionUninstallDialog::Delegate implementation. 129 // ExtensionUninstallDialog::Delegate implementation.
127 virtual void ExtensionUninstallAccepted() OVERRIDE; 130 virtual void ExtensionUninstallAccepted() OVERRIDE;
128 virtual void ExtensionUninstallCanceled() OVERRIDE; 131 virtual void ExtensionUninstallCanceled() OVERRIDE;
129 132
130 private: 133 private:
131 virtual ~UninstallFunction(); 134 virtual ~UninstallFunction();
132 135
133 virtual bool RunImpl() OVERRIDE; 136 virtual bool RunImpl() OVERRIDE;
134 137
135 // If should_uninstall is true, this method does the actual uninstall. 138 // If should_uninstall is true, this method does the actual uninstall.
136 // If |show_uninstall_dialog|, then this function will be called by one of the 139 // If |show_uninstall_dialog|, then this function will be called by one of the
137 // Accepted/Canceled callbacks. Otherwise, it's called directly from RunImpl. 140 // Accepted/Canceled callbacks. Otherwise, it's called directly from RunImpl.
138 void Finish(bool should_uninstall); 141 void Finish(bool should_uninstall);
139 142
140 std::string extension_id_; 143 std::string extension_id_;
141 scoped_ptr<ExtensionUninstallDialog> extension_uninstall_dialog_; 144 scoped_ptr<ExtensionUninstallDialog> extension_uninstall_dialog_;
142 }; 145 };
143 146
144 class ExtensionManagementEventRouter : public content::NotificationObserver { 147 class ManagementEventRouter : public content::NotificationObserver {
145 public: 148 public:
146 explicit ExtensionManagementEventRouter(Profile* profile); 149 explicit ManagementEventRouter(Profile* profile);
147 virtual ~ExtensionManagementEventRouter(); 150 virtual ~ManagementEventRouter();
148 151
149 private: 152 private:
150 // content::NotificationObserver implementation. 153 // content::NotificationObserver implementation.
151 virtual void Observe(int type, 154 virtual void Observe(int type,
152 const content::NotificationSource& source, 155 const content::NotificationSource& source,
153 const content::NotificationDetails& details) OVERRIDE; 156 const content::NotificationDetails& details) OVERRIDE;
154 157
155 content::NotificationRegistrar registrar_; 158 content::NotificationRegistrar registrar_;
156 159
157 Profile* profile_; 160 Profile* profile_;
158 161
159 DISALLOW_COPY_AND_ASSIGN(ExtensionManagementEventRouter); 162 DISALLOW_COPY_AND_ASSIGN(ManagementEventRouter);
160 }; 163 };
161 164
162 class ExtensionManagementAPI : public ProfileKeyedService, 165 class ManagementAPI : public ProfileKeyedAPI,
163 public extensions::EventRouter::Observer { 166 public extensions::EventRouter::Observer {
164 public: 167 public:
165 explicit ExtensionManagementAPI(Profile* profile); 168 explicit ManagementAPI(Profile* profile);
166 virtual ~ExtensionManagementAPI(); 169 virtual ~ManagementAPI();
167 170
168 // ProfileKeyedService implementation. 171 // ProfileKeyedService implementation.
169 virtual void Shutdown() OVERRIDE; 172 virtual void Shutdown() OVERRIDE;
170 173
171 // EventRouter::Observer implementation. 174 // EventRouter::Observer implementation.
172 virtual void OnListenerAdded(const extensions::EventListenerInfo& details) 175 virtual void OnListenerAdded(const extensions::EventListenerInfo& details)
173 OVERRIDE; 176 OVERRIDE;
174 177
175 private: 178 private:
179 friend class ProfileKeyedAPIFactory<ManagementAPI>;
180
176 Profile* profile_; 181 Profile* profile_;
177 182
183 // ProfileKeyedAPI implementation.
184 static const char* service_name() {
185 return "ManagementAPI";
186 }
187 static const bool kServiceIsNULLWhileTesting = true;
188
178 // Created lazily upon OnListenerAdded. 189 // Created lazily upon OnListenerAdded.
179 scoped_ptr<ExtensionManagementEventRouter> management_event_router_; 190 scoped_ptr<ManagementEventRouter> management_event_router_;
191
192 DISALLOW_COPY_AND_ASSIGN(ManagementAPI);
180 }; 193 };
181 194
195 template<>
196 ProfileKeyedAPIFactory<ManagementAPI>*
197 ProfileKeyedAPIFactory<ManagementAPI>::GetInstance();
Jeffrey Yasskin 2013/01/03 23:10:42 Late question: Why does this need to be a method o
Yoyo Zhou 2013/01/03 23:52:58 Good question. I think that's something I would ad
198
199 } // namespace extensions
200
182 #endif // CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_ 201 #endif // CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/management/management_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698