Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / extensions / browser / api / management / management_api.h
blob95006b632338712d579c3d4d41250c4ed578762b
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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_BROWSER_API_MANAGEMENT_MANAGEMENT_API_H_
6 #define EXTENSIONS_BROWSER_API_MANAGEMENT_MANAGEMENT_API_H_
8 #include "base/compiler_specific.h"
9 #include "base/scoped_observer.h"
10 #include "base/strings/string16.h"
11 #include "components/keyed_service/core/keyed_service.h"
12 #include "extensions/browser/api/management/management_api_delegate.h"
13 #include "extensions/browser/browser_context_keyed_api_factory.h"
14 #include "extensions/browser/event_router.h"
15 #include "extensions/browser/extension_event_histogram_value.h"
16 #include "extensions/browser/extension_function.h"
17 #include "extensions/browser/extension_registry_observer.h"
19 class ExtensionRegistry;
20 class ExtensionUninstallDialog;
21 struct WebApplicationInfo;
23 namespace extensions {
24 class ExtensionRegistry;
25 class RequirementsChecker;
27 class ManagementFunction : public SyncExtensionFunction {
28 protected:
29 ~ManagementFunction() override {}
32 class AsyncManagementFunction : public AsyncExtensionFunction {
33 protected:
34 ~AsyncManagementFunction() override {}
37 class ManagementGetAllFunction : public ManagementFunction {
38 public:
39 DECLARE_EXTENSION_FUNCTION("management.getAll", MANAGEMENT_GETALL)
41 protected:
42 ~ManagementGetAllFunction() override {}
44 // ExtensionFunction:
45 bool RunSync() override;
48 class ManagementGetFunction : public ManagementFunction {
49 public:
50 DECLARE_EXTENSION_FUNCTION("management.get", MANAGEMENT_GET)
52 protected:
53 ~ManagementGetFunction() override {}
55 // ExtensionFunction:
56 bool RunSync() override;
59 class ManagementGetSelfFunction : public ManagementFunction {
60 public:
61 DECLARE_EXTENSION_FUNCTION("management.getSelf", MANAGEMENT_GETSELF)
63 protected:
64 ~ManagementGetSelfFunction() override {}
66 // ExtensionFunction:
67 bool RunSync() override;
70 class ManagementGetPermissionWarningsByIdFunction : public ManagementFunction {
71 public:
72 DECLARE_EXTENSION_FUNCTION("management.getPermissionWarningsById",
73 MANAGEMENT_GETPERMISSIONWARNINGSBYID)
75 protected:
76 ~ManagementGetPermissionWarningsByIdFunction() override {}
78 // ExtensionFunction:
79 bool RunSync() override;
82 class ManagementGetPermissionWarningsByManifestFunction
83 : public AsyncExtensionFunction {
84 public:
85 DECLARE_EXTENSION_FUNCTION("management.getPermissionWarningsByManifest",
86 MANAGEMENT_GETPERMISSIONWARNINGSBYMANIFEST);
88 // Called when utility process finishes.
89 void OnParseSuccess(scoped_ptr<base::Value> value);
90 void OnParseFailure(const std::string& error);
92 protected:
93 ~ManagementGetPermissionWarningsByManifestFunction() override {}
95 // ExtensionFunction:
96 bool RunAsync() override;
99 class ManagementLaunchAppFunction : public ManagementFunction {
100 public:
101 DECLARE_EXTENSION_FUNCTION("management.launchApp", MANAGEMENT_LAUNCHAPP)
103 protected:
104 ~ManagementLaunchAppFunction() override {}
106 // ExtensionFunction:
107 bool RunSync() override;
110 class ManagementSetEnabledFunction : public UIThreadExtensionFunction {
111 public:
112 DECLARE_EXTENSION_FUNCTION("management.setEnabled", MANAGEMENT_SETENABLED)
114 ManagementSetEnabledFunction();
116 void InstallUIProceed();
117 void InstallUIAbort(bool user_initiated);
119 protected:
120 ~ManagementSetEnabledFunction() override;
122 // ExtensionFunction:
123 ResponseAction Run() override;
125 private:
126 void OnRequirementsChecked(const std::vector<std::string>& requirements);
128 std::string extension_id_;
130 scoped_ptr<InstallPromptDelegate> install_prompt_;
132 scoped_ptr<RequirementsChecker> requirements_checker_;
135 class ManagementUninstallFunctionBase : public UIThreadExtensionFunction {
136 public:
137 ManagementUninstallFunctionBase();
139 void OnExtensionUninstallDialogClosed(bool did_start_uninstall,
140 const base::string16& error);
142 protected:
143 ~ManagementUninstallFunctionBase() override;
144 ResponseAction Uninstall(const std::string& extension_id,
145 bool show_confirm_dialog);
147 private:
148 // Uninstalls the extension without showing the dialog.
149 void UninstallExtension();
151 // Finishes and responds to the extension.
152 void Finish(bool did_start_uninstall, const std::string& error);
154 std::string target_extension_id_;
156 scoped_ptr<UninstallDialogDelegate> uninstall_dialog_;
159 class ManagementUninstallFunction : public ManagementUninstallFunctionBase {
160 public:
161 DECLARE_EXTENSION_FUNCTION("management.uninstall", MANAGEMENT_UNINSTALL)
162 ManagementUninstallFunction();
164 private:
165 ~ManagementUninstallFunction() override;
166 ResponseAction Run() override;
169 class ManagementUninstallSelfFunction : public ManagementUninstallFunctionBase {
170 public:
171 DECLARE_EXTENSION_FUNCTION("management.uninstallSelf",
172 MANAGEMENT_UNINSTALLSELF);
173 ManagementUninstallSelfFunction();
175 private:
176 ~ManagementUninstallSelfFunction() override;
177 ResponseAction Run() override;
180 class ManagementCreateAppShortcutFunction : public AsyncManagementFunction {
181 public:
182 DECLARE_EXTENSION_FUNCTION("management.createAppShortcut",
183 MANAGEMENT_CREATEAPPSHORTCUT);
185 ManagementCreateAppShortcutFunction();
187 void OnCloseShortcutPrompt(bool created);
189 static void SetAutoConfirmForTest(bool should_proceed);
191 protected:
192 ~ManagementCreateAppShortcutFunction() override;
194 bool RunAsync() override;
197 class ManagementSetLaunchTypeFunction : public ManagementFunction {
198 public:
199 DECLARE_EXTENSION_FUNCTION("management.setLaunchType",
200 MANAGEMENT_SETLAUNCHTYPE);
202 protected:
203 ~ManagementSetLaunchTypeFunction() override {}
205 bool RunSync() override;
208 class ManagementGenerateAppForLinkFunction : public AsyncManagementFunction {
209 public:
210 DECLARE_EXTENSION_FUNCTION("management.generateAppForLink",
211 MANAGEMENT_GENERATEAPPFORLINK);
213 ManagementGenerateAppForLinkFunction();
215 void FinishCreateBookmarkApp(const Extension* extension,
216 const WebApplicationInfo& web_app_info);
218 protected:
219 ~ManagementGenerateAppForLinkFunction() override;
221 bool RunAsync() override;
223 private:
224 scoped_ptr<AppForLinkDelegate> app_for_link_delegate_;
227 class ManagementEventRouter : public ExtensionRegistryObserver {
228 public:
229 explicit ManagementEventRouter(content::BrowserContext* context);
230 ~ManagementEventRouter() override;
232 private:
233 // ExtensionRegistryObserver implementation.
234 void OnExtensionLoaded(content::BrowserContext* browser_context,
235 const Extension* extension) override;
236 void OnExtensionUnloaded(content::BrowserContext* browser_context,
237 const Extension* extension,
238 UnloadedExtensionInfo::Reason reason) override;
239 void OnExtensionInstalled(content::BrowserContext* browser_context,
240 const Extension* extension,
241 bool is_update) override;
242 void OnExtensionUninstalled(content::BrowserContext* browser_context,
243 const Extension* extension,
244 extensions::UninstallReason reason) override;
246 // Dispatches management api events to listening extensions.
247 void BroadcastEvent(const Extension* extension,
248 events::HistogramValue histogram_value,
249 const char* event_name);
251 content::BrowserContext* browser_context_;
253 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
254 extension_registry_observer_;
256 DISALLOW_COPY_AND_ASSIGN(ManagementEventRouter);
259 class ManagementAPI : public BrowserContextKeyedAPI,
260 public EventRouter::Observer {
261 public:
262 explicit ManagementAPI(content::BrowserContext* context);
263 ~ManagementAPI() override;
265 // KeyedService implementation.
266 void Shutdown() override;
268 // BrowserContextKeyedAPI implementation.
269 static BrowserContextKeyedAPIFactory<ManagementAPI>* GetFactoryInstance();
271 // EventRouter::Observer implementation.
272 void OnListenerAdded(const EventListenerInfo& details) override;
274 // Returns the ManagementAPI delegate.
275 const ManagementAPIDelegate* GetDelegate() const { return delegate_.get(); }
277 private:
278 friend class BrowserContextKeyedAPIFactory<ManagementAPI>;
280 content::BrowserContext* browser_context_;
282 // BrowserContextKeyedAPI implementation.
283 static const char* service_name() { return "ManagementAPI"; }
284 static const bool kServiceIsNULLWhileTesting = true;
285 static const bool kServiceRedirectedInIncognito = true;
287 // Created lazily upon OnListenerAdded.
288 scoped_ptr<ManagementEventRouter> management_event_router_;
290 scoped_ptr<ManagementAPIDelegate> delegate_;
292 DISALLOW_COPY_AND_ASSIGN(ManagementAPI);
295 } // namespace extensions
297 #endif // EXTENSIONS_BROWSER_API_MANAGEMENT_MANAGEMENT_API_H_