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 | |
Alexey Baskakov | 7f4bffa | 2019-01-08 02:12:38 | [diff] [blame^] | 11 | #include "base/callback.h" |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 12 | #include "base/macros.h" |
Dominick Ng | 7b4ad0b8 | 2018-08-03 15:29:10 | [diff] [blame] | 13 | #include "base/memory/weak_ptr.h" |
| 14 | #include "chrome/browser/web_applications/components/pending_app_manager.h" |
Becca Hughes | 6f49429 | 2018-12-19 10:57:21 | [diff] [blame] | 15 | #include "chrome/browser/web_applications/components/web_app_helpers.h" |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 16 | #include "components/keyed_service/core/keyed_service.h" |
Giovanni Ortuño Urquidi | fd7ed286 | 2018-08-29 13:26:49 | [diff] [blame] | 17 | #include "content/public/browser/notification_observer.h" |
| 18 | #include "content/public/browser/notification_registrar.h" |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 19 | |
| 20 | class Profile; |
| 21 | |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 22 | namespace content { |
| 23 | class WebContents; |
| 24 | } |
| 25 | |
Alexey Baskakov | 396edb9 | 2018-08-02 05:11:42 | [diff] [blame] | 26 | namespace user_prefs { |
| 27 | class PrefRegistrySyncable; |
| 28 | } |
| 29 | |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 30 | namespace web_app { |
| 31 | |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 32 | // Forward declarations of generalized interfaces. |
Giovanni Ortuño Urquidi | 4f86bf27 | 2018-07-31 02:09:03 | [diff] [blame] | 33 | class PendingAppManager; |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 34 | class InstallManager; |
Becca Hughes | 6f49429 | 2018-12-19 10:57:21 | [diff] [blame] | 35 | class WebAppAudioFocusIdMap; |
Alexey Baskakov | fbe86f4 | 2018-12-10 00:56:03 | [diff] [blame] | 36 | class WebAppTabHelperBase; |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 37 | |
| 38 | // Forward declarations for new extension-independent subsystems. |
Alexey Baskakov | ac8c4b0 | 2018-11-07 06:10:02 | [diff] [blame] | 39 | class WebAppDatabase; |
| 40 | class WebAppDatabaseFactory; |
Alexey Baskakov | f14ab187 | 2018-11-28 07:37:19 | [diff] [blame] | 41 | class WebAppIconManager; |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 42 | class WebAppRegistrar; |
| 43 | |
| 44 | // Forward declarations for legacy extension-based subsystems. |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 45 | class WebAppPolicyManager; |
Christopher Lam | 0999fe35 | 2018-09-24 05:01:26 | [diff] [blame] | 46 | class SystemWebAppManager; |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 47 | |
| 48 | // Connects Web App features, such as the installation of default and |
| 49 | // policy-managed web apps, with Profiles (as WebAppProvider is a |
| 50 | // Profile-linked KeyedService) and their associated PrefService. |
Giovanni Ortuño Urquidi | fd7ed286 | 2018-08-29 13:26:49 | [diff] [blame] | 51 | class WebAppProvider : public KeyedService, |
| 52 | public content::NotificationObserver { |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 53 | public: |
| 54 | static WebAppProvider* Get(Profile* profile); |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 55 | static WebAppProvider* GetForWebContents(content::WebContents* web_contents); |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 56 | |
Giovanni Ortuño Urquidi | 8ea2f1e | 2018-08-06 01:13:05 | [diff] [blame] | 57 | explicit WebAppProvider(Profile* profile); |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 58 | |
Giovanni Ortuño Urquidi | 4f86bf27 | 2018-07-31 02:09:03 | [diff] [blame] | 59 | // Clients can use PendingAppManager to install, uninstall, and update |
| 60 | // Web Apps. |
| 61 | PendingAppManager& pending_app_manager() { return *pending_app_manager_; } |
| 62 | |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 63 | ~WebAppProvider() override; |
| 64 | |
Alexey Baskakov | 396edb9 | 2018-08-02 05:11:42 | [diff] [blame] | 65 | static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
Alexey Baskakov | fbe86f4 | 2018-12-10 00:56:03 | [diff] [blame] | 66 | static WebAppTabHelperBase* CreateTabHelper( |
| 67 | content::WebContents* web_contents); |
Alexey Baskakov | 396edb9 | 2018-08-02 05:11:42 | [diff] [blame] | 68 | |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 69 | // Returns true if a bookmark can be installed for a given |web_contents|. |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 70 | static bool CanInstallWebApp(content::WebContents* web_contents); |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 71 | |
| 72 | // Starts a bookmark installation process for a given |web_contents|. |
| 73 | static void InstallWebApp(content::WebContents* web_contents, |
| 74 | bool force_shortcut_app); |
| 75 | |
Giovanni Ortuño Urquidi | fd7ed286 | 2018-08-29 13:26:49 | [diff] [blame] | 76 | void Reset(); |
| 77 | |
| 78 | // content::NotificationObserver |
| 79 | void Observe(int type, |
| 80 | const content::NotificationSource& source, |
| 81 | const content::NotificationDetails& details) override; |
Giovanni Ortuño Urquidi | 2fb415b0 | 2018-08-22 07:18:51 | [diff] [blame] | 82 | |
Alexey Baskakov | 7f4bffa | 2019-01-08 02:12:38 | [diff] [blame^] | 83 | // Fires when app registry becomes ready. |
| 84 | // Consider to use base::ObserverList or extensions::OneShotEvent if many |
| 85 | // subscribers needed. |
| 86 | void SetRegistryReadyCallback(base::OnceClosure callback); |
| 87 | |
Alexey Baskakov | da22037 | 2019-01-08 00:21:16 | [diff] [blame] | 88 | // Count a number of all apps which are installed by user (non-default). |
Alexey Baskakov | 7f4bffa | 2019-01-08 02:12:38 | [diff] [blame^] | 89 | // Requires app registry to be in a ready state. |
Alexey Baskakov | da22037 | 2019-01-08 00:21:16 | [diff] [blame] | 90 | int CountUserInstalledApps() const; |
| 91 | |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 92 | private: |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 93 | // Create extension-independent subsystems. |
| 94 | void CreateWebAppsSubsystems(Profile* profile); |
| 95 | // ... or create legacy extension-based subsystems. |
| 96 | void CreateBookmarkAppsSubsystems(Profile* profile); |
| 97 | |
Alexey Baskakov | 7f4bffa | 2019-01-08 02:12:38 | [diff] [blame^] | 98 | void OnRegistryReady(); |
| 99 | |
Dominick Ng | 4b176fd | 2018-08-20 16:15:56 | [diff] [blame] | 100 | void OnScanForExternalWebApps( |
Dominick Ng | 7b4ad0b8 | 2018-08-03 15:29:10 | [diff] [blame] | 101 | std::vector<web_app::PendingAppManager::AppInfo>); |
| 102 | |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 103 | // New extension-independent subsystems: |
Becca Hughes | 6f49429 | 2018-12-19 10:57:21 | [diff] [blame] | 104 | std::unique_ptr<WebAppAudioFocusIdMap> audio_focus_id_map_; |
Alexey Baskakov | ac8c4b0 | 2018-11-07 06:10:02 | [diff] [blame] | 105 | std::unique_ptr<WebAppDatabaseFactory> database_factory_; |
| 106 | std::unique_ptr<WebAppDatabase> database_; |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 107 | std::unique_ptr<WebAppRegistrar> registrar_; |
Alexey Baskakov | f14ab187 | 2018-11-28 07:37:19 | [diff] [blame] | 108 | std::unique_ptr<WebAppIconManager> icon_manager_; |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 109 | |
| 110 | // New generalized subsystems: |
| 111 | std::unique_ptr<InstallManager> install_manager_; |
Giovanni Ortuño Urquidi | 4f86bf27 | 2018-07-31 02:09:03 | [diff] [blame] | 112 | std::unique_ptr<PendingAppManager> pending_app_manager_; |
Alexey Baskakov | fd3894e | 2018-10-16 06:09:58 | [diff] [blame] | 113 | |
| 114 | // Legacy extension-based subsystems: |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 115 | std::unique_ptr<WebAppPolicyManager> web_app_policy_manager_; |
Christopher Lam | 0999fe35 | 2018-09-24 05:01:26 | [diff] [blame] | 116 | std::unique_ptr<SystemWebAppManager> system_web_app_manager_; |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 117 | |
Alexey Baskakov | 3a5a2cf | 2018-10-10 02:44:43 | [diff] [blame] | 118 | content::NotificationRegistrar notification_registrar_; |
Giovanni Ortuño Urquidi | fd7ed286 | 2018-08-29 13:26:49 | [diff] [blame] | 119 | |
Alexey Baskakov | 7f4bffa | 2019-01-08 02:12:38 | [diff] [blame^] | 120 | base::OnceClosure registry_ready_callback_; |
| 121 | bool registry_is_ready_ = false; |
| 122 | |
Alexey Baskakov | da22037 | 2019-01-08 00:21:16 | [diff] [blame] | 123 | Profile* profile_; |
| 124 | |
Dominick Ng | 7b4ad0b8 | 2018-08-03 15:29:10 | [diff] [blame] | 125 | base::WeakPtrFactory<WebAppProvider> weak_ptr_factory_{this}; |
| 126 | |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 127 | DISALLOW_COPY_AND_ASSIGN(WebAppProvider); |
| 128 | }; |
| 129 | |
| 130 | } // namespace web_app |
| 131 | |
| 132 | #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_PROVIDER_H_ |