Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 1 | // Copyright 2018 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. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_PROVIDER_H_ |
| 6 | #define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_PROVIDER_H_ |
| 7 | |
| 8 | #include <memory> |
Dominick Ng | 7b4ad0b8 | 2018-08-03 15:29:10 | [diff] [blame] | 9 | #include <vector> |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 10 | |
| 11 | #include "base/macros.h" |
Dominick Ng | 7b4ad0b8 | 2018-08-03 15:29:10 | [diff] [blame] | 12 | #include "base/memory/weak_ptr.h" |
| 13 | #include "chrome/browser/web_applications/components/pending_app_manager.h" |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 14 | #include "components/keyed_service/core/keyed_service.h" |
Giovanni Ortuño Urquidi | fd7ed286 | 2018-08-29 13:26:49 | [diff] [blame] | 15 | #include "content/public/browser/notification_observer.h" |
| 16 | #include "content/public/browser/notification_registrar.h" |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 17 | |
| 18 | class Profile; |
| 19 | |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 20 | namespace content { |
| 21 | class WebContents; |
| 22 | } |
| 23 | |
Alexey Baskakov | 396edb9 | 2018-08-02 05:11:42 | [diff] [blame] | 24 | namespace user_prefs { |
| 25 | class PrefRegistrySyncable; |
| 26 | } |
| 27 | |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 28 | namespace web_app { |
| 29 | |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 30 | // Forward declarations of generalized interfaces. |
Giovanni Ortuño Urquidi | 4f86bf27 | 2018-07-31 02:09:03 | [diff] [blame] | 31 | class PendingAppManager; |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 32 | class InstallManager; |
| 33 | |
| 34 | // Forward declarations for new extension-independent subsystems. |
| 35 | class WebAppRegistrar; |
| 36 | |
| 37 | // Forward declarations for legacy extension-based subsystems. |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 38 | class WebAppPolicyManager; |
Christopher Lam | 0999fe35 | 2018-09-24 05:01:26 | [diff] [blame] | 39 | class SystemWebAppManager; |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 40 | |
| 41 | // Connects Web App features, such as the installation of default and |
| 42 | // policy-managed web apps, with Profiles (as WebAppProvider is a |
| 43 | // Profile-linked KeyedService) and their associated PrefService. |
Giovanni Ortuño Urquidi | fd7ed286 | 2018-08-29 13:26:49 | [diff] [blame] | 44 | class WebAppProvider : public KeyedService, |
| 45 | public content::NotificationObserver { |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 46 | public: |
| 47 | static WebAppProvider* Get(Profile* profile); |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 48 | static WebAppProvider* GetForWebContents( |
| 49 | const content::WebContents* web_contents); |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 50 | |
Giovanni Ortuño Urquidi | 8ea2f1e | 2018-08-06 01:13:05 | [diff] [blame] | 51 | explicit WebAppProvider(Profile* profile); |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 52 | |
Giovanni Ortuño Urquidi | 4f86bf27 | 2018-07-31 02:09:03 | [diff] [blame] | 53 | // Clients can use PendingAppManager to install, uninstall, and update |
| 54 | // Web Apps. |
| 55 | PendingAppManager& pending_app_manager() { return *pending_app_manager_; } |
| 56 | |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 57 | ~WebAppProvider() override; |
| 58 | |
Alexey Baskakov | 396edb9 | 2018-08-02 05:11:42 | [diff] [blame] | 59 | static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 60 | |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 61 | // Returns true if a bookmark can be installed for a given |web_contents|. |
| 62 | static bool CanInstallWebApp(const content::WebContents* web_contents); |
| 63 | |
| 64 | // Starts a bookmark installation process for a given |web_contents|. |
| 65 | static void InstallWebApp(content::WebContents* web_contents, |
| 66 | bool force_shortcut_app); |
| 67 | |
Giovanni Ortuño Urquidi | fd7ed286 | 2018-08-29 13:26:49 | [diff] [blame] | 68 | void Reset(); |
| 69 | |
| 70 | // content::NotificationObserver |
| 71 | void Observe(int type, |
| 72 | const content::NotificationSource& source, |
| 73 | const content::NotificationDetails& details) override; |
Giovanni Ortuño Urquidi | 2fb415b0 | 2018-08-22 07:18:51 | [diff] [blame] | 74 | |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 75 | private: |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 76 | // Create extension-independent subsystems. |
| 77 | void CreateWebAppsSubsystems(Profile* profile); |
| 78 | // ... or create legacy extension-based subsystems. |
| 79 | void CreateBookmarkAppsSubsystems(Profile* profile); |
| 80 | |
Dominick Ng | 4b176fd | 2018-08-20 16:15:56 | [diff] [blame] | 81 | void OnScanForExternalWebApps( |
Dominick Ng | 7b4ad0b8 | 2018-08-03 15:29:10 | [diff] [blame] | 82 | std::vector<web_app::PendingAppManager::AppInfo>); |
| 83 | |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 84 | // New extension-independent subsystems: |
| 85 | std::unique_ptr<WebAppRegistrar> registrar_; |
| 86 | |
| 87 | // New generalized subsystems: |
| 88 | std::unique_ptr<InstallManager> install_manager_; |
Giovanni Ortuño Urquidi | 4f86bf27 | 2018-07-31 02:09:03 | [diff] [blame] | 89 | std::unique_ptr<PendingAppManager> pending_app_manager_; |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 90 | |
| 91 | // Legacy extension-based subsystems: |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 92 | std::unique_ptr<WebAppPolicyManager> web_app_policy_manager_; |
Christopher Lam | 0999fe35 | 2018-09-24 05:01:26 | [diff] [blame] | 93 | std::unique_ptr<SystemWebAppManager> system_web_app_manager_; |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 94 | |
Alexey Baskakov | 3a5a2cf | 2018-10-10 02:44:43 | [diff] [blame] | 95 | content::NotificationRegistrar notification_registrar_; |
Giovanni Ortuño Urquidi | fd7ed286 | 2018-08-29 13:26:49 | [diff] [blame] | 96 | |
Dominick Ng | 7b4ad0b8 | 2018-08-03 15:29:10 | [diff] [blame] | 97 | base::WeakPtrFactory<WebAppProvider> weak_ptr_factory_{this}; |
| 98 | |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 99 | DISALLOW_COPY_AND_ASSIGN(WebAppProvider); |
| 100 | }; |
| 101 | |
| 102 | } // namespace web_app |
| 103 | |
| 104 | #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_PROVIDER_H_ |