Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / extensions / browser / api / management / management_api.h
blobc8687c2de1655a517179c2847b99997ddc1cf1b6
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_function.h"
16 #include "extensions/browser/extension_registry_observer.h"
18 class ExtensionRegistry;
19 class ExtensionUninstallDialog;
20 struct WebApplicationInfo;
22 namespace extensions {
23 class ExtensionRegistry;
24 class RequirementsChecker;
26 class ManagementFunction : public SyncExtensionFunction {
27 protected:
28 ~ManagementFunction() override {}
31 class AsyncManagementFunction : public AsyncExtensionFunction {
32 protected:
33 ~AsyncManagementFunction() override {}
36 class ManagementGetAllFunction : public ManagementFunction {
37 public:
38 DECLARE_EXTENSION_FUNCTION("management.getAll", MANAGEMENT_GETALL)
40 protected:
41 ~ManagementGetAllFunction() override {}
43 // ExtensionFunction:
44 bool RunSync() override;
47 class ManagementGetFunction : public ManagementFunction {
48 public:
49 DECLARE_EXTENSION_FUNCTION("management.get", MANAGEMENT_GET)
51 protected:
52 ~ManagementGetFunction() override {}
54 // ExtensionFunction:
55 bool RunSync() override;
58 class ManagementGetSelfFunction : public ManagementFunction {
59 public:
60 DECLARE_EXTENSION_FUNCTION("management.getSelf", MANAGEMENT_GETSELF)
62 protected:
63 ~ManagementGetSelfFunction() override {}
65 // ExtensionFunction:
66 bool RunSync() override;
69 class ManagementGetPermissionWarningsByIdFunction : public ManagementFunction {
70 public:
71 DECLARE_EXTENSION_FUNCTION("management.getPermissionWarningsById",
72 MANAGEMENT_GETPERMISSIONWARNINGSBYID)
74 protected:
75 ~ManagementGetPermissionWarningsByIdFunction() override {}
77 // ExtensionFunction:
78 bool RunSync() override;
81 class ManagementGetPermissionWarningsByManifestFunction
82 : public AsyncExtensionFunction {
83 public:
84 DECLARE_EXTENSION_FUNCTION("management.getPermissionWarningsByManifest",
85 MANAGEMENT_GETPERMISSIONWARNINGSBYMANIFEST);
87 // Called when utility process finishes.
88 void OnParseSuccess(scoped_ptr<base::Value> value);
89 void OnParseFailure(const std::string& error);
91 protected:
92 ~ManagementGetPermissionWarningsByManifestFunction() override {}
94 // ExtensionFunction:
95 bool RunAsync() override;
98 class ManagementLaunchAppFunction : public ManagementFunction {
99 public:
100 DECLARE_EXTENSION_FUNCTION("management.launchApp", MANAGEMENT_LAUNCHAPP)
102 protected:
103 ~ManagementLaunchAppFunction() override {}
105 // ExtensionFunction:
106 bool RunSync() override;
109 class ManagementSetEnabledFunction : public UIThreadExtensionFunction {
110 public:
111 DECLARE_EXTENSION_FUNCTION("management.setEnabled", MANAGEMENT_SETENABLED)
113 ManagementSetEnabledFunction();
115 void InstallUIProceed();
116 void InstallUIAbort(bool user_initiated);
118 protected:
119 ~ManagementSetEnabledFunction() override;
121 // ExtensionFunction:
122 ResponseAction Run() override;
124 private:
125 void OnRequirementsChecked(const std::vector<std::string>& requirements);
127 std::string extension_id_;
129 scoped_ptr<InstallPromptDelegate> install_prompt_;
131 scoped_ptr<RequirementsChecker> requirements_checker_;
134 class ManagementUninstallFunctionBase : public UIThreadExtensionFunction {
135 public:
136 ManagementUninstallFunctionBase();
138 static void SetAutoConfirmForTest(bool should_proceed);
140 void OnExtensionUninstallDialogClosed(bool did_start_uninstall,
141 const base::string16& error);
143 protected:
144 ~ManagementUninstallFunctionBase() override;
145 ResponseAction Uninstall(const std::string& extension_id,
146 bool show_confirm_dialog);
148 private:
149 // Uninstalls the extension without showing the dialog.
150 void UninstallExtension();
152 // Finishes and responds to the extension.
153 void Finish(bool did_start_uninstall, const std::string& error);
155 std::string target_extension_id_;
157 scoped_ptr<UninstallDialogDelegate> uninstall_dialog_;
160 class ManagementUninstallFunction : public ManagementUninstallFunctionBase {
161 public:
162 DECLARE_EXTENSION_FUNCTION("management.uninstall", MANAGEMENT_UNINSTALL)
163 ManagementUninstallFunction();
165 private:
166 ~ManagementUninstallFunction() override;
167 ResponseAction Run() override;
170 class ManagementUninstallSelfFunction : public ManagementUninstallFunctionBase {
171 public:
172 DECLARE_EXTENSION_FUNCTION("management.uninstallSelf",
173 MANAGEMENT_UNINSTALLSELF);
174 ManagementUninstallSelfFunction();
176 private:
177 ~ManagementUninstallSelfFunction() override;
178 ResponseAction Run() override;
181 class ManagementCreateAppShortcutFunction : public AsyncManagementFunction {
182 public:
183 DECLARE_EXTENSION_FUNCTION("management.createAppShortcut",
184 MANAGEMENT_CREATEAPPSHORTCUT);
186 ManagementCreateAppShortcutFunction();
188 void OnCloseShortcutPrompt(bool created);
190 static void SetAutoConfirmForTest(bool should_proceed);
192 protected:
193 ~ManagementCreateAppShortcutFunction() override;
195 bool RunAsync() override;
198 class ManagementSetLaunchTypeFunction : public ManagementFunction {
199 public:
200 DECLARE_EXTENSION_FUNCTION("management.setLaunchType",
201 MANAGEMENT_SETLAUNCHTYPE);
203 protected:
204 ~ManagementSetLaunchTypeFunction() override {}
206 bool RunSync() override;
209 class ManagementGenerateAppForLinkFunction : public AsyncManagementFunction {
210 public:
211 DECLARE_EXTENSION_FUNCTION("management.generateAppForLink",
212 MANAGEMENT_GENERATEAPPFORLINK);
214 ManagementGenerateAppForLinkFunction();
216 void FinishCreateBookmarkApp(const Extension* extension,
217 const WebApplicationInfo& web_app_info);
219 protected:
220 ~ManagementGenerateAppForLinkFunction() override;
222 bool RunAsync() override;
224 private:
225 scoped_ptr<AppForLinkDelegate> app_for_link_delegate_;
228 class ManagementEventRouter : public ExtensionRegistryObserver {
229 public:
230 explicit ManagementEventRouter(content::BrowserContext* context);
231 ~ManagementEventRouter() override;
233 private:
234 // ExtensionRegistryObserver implementation.
235 void OnExtensionLoaded(content::BrowserContext* browser_context,
236 const Extension* extension) override;
237 void OnExtensionUnloaded(content::BrowserContext* browser_context,
238 const Extension* extension,
239 UnloadedExtensionInfo::Reason reason) override;
240 void OnExtensionInstalled(content::BrowserContext* browser_context,
241 const Extension* extension,
242 bool is_update) override;
243 void OnExtensionUninstalled(content::BrowserContext* browser_context,
244 const Extension* extension,
245 extensions::UninstallReason reason) override;
247 // Dispatches management api events to listening extensions.
248 void BroadcastEvent(const Extension* extension, const char* event_name);
250 content::BrowserContext* browser_context_;
252 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
253 extension_registry_observer_;
255 DISALLOW_COPY_AND_ASSIGN(ManagementEventRouter);
258 class ManagementAPI : public BrowserContextKeyedAPI,
259 public EventRouter::Observer {
260 public:
261 explicit ManagementAPI(content::BrowserContext* context);
262 ~ManagementAPI() override;
264 // KeyedService implementation.
265 void Shutdown() override;
267 // BrowserContextKeyedAPI implementation.
268 static BrowserContextKeyedAPIFactory<ManagementAPI>* GetFactoryInstance();
270 // EventRouter::Observer implementation.
271 void OnListenerAdded(const EventListenerInfo& details) override;
273 // Returns the ManagementAPI delegate.
274 const ManagementAPIDelegate* GetDelegate() const { return delegate_.get(); }
276 private:
277 friend class BrowserContextKeyedAPIFactory<ManagementAPI>;
279 content::BrowserContext* browser_context_;
281 // BrowserContextKeyedAPI implementation.
282 static const char* service_name() { return "ManagementAPI"; }
283 static const bool kServiceIsNULLWhileTesting = true;
284 static const bool kServiceRedirectedInIncognito = true;
286 // Created lazily upon OnListenerAdded.
287 scoped_ptr<ManagementEventRouter> management_event_router_;
289 scoped_ptr<ManagementAPIDelegate> delegate_;
291 DISALLOW_COPY_AND_ASSIGN(ManagementAPI);
294 } // namespace extensions
296 #endif // EXTENSIONS_BROWSER_API_MANAGEMENT_MANAGEMENT_API_H_