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 | 396edb9 | 2018-08-02 05:11:42 | [diff] [blame] | 20 | namespace user_prefs { |
| 21 | class PrefRegistrySyncable; |
| 22 | } |
| 23 | |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 24 | namespace web_app { |
| 25 | |
Giovanni Ortuño Urquidi | 4f86bf27 | 2018-07-31 02:09:03 | [diff] [blame] | 26 | class PendingAppManager; |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 27 | class WebAppPolicyManager; |
Christopher Lam | 0999fe35 | 2018-09-24 05:01:26 | [diff] [blame^] | 28 | class SystemWebAppManager; |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 29 | |
| 30 | // Connects Web App features, such as the installation of default and |
| 31 | // policy-managed web apps, with Profiles (as WebAppProvider is a |
| 32 | // Profile-linked KeyedService) and their associated PrefService. |
Giovanni Ortuño Urquidi | fd7ed286 | 2018-08-29 13:26:49 | [diff] [blame] | 33 | class WebAppProvider : public KeyedService, |
| 34 | public content::NotificationObserver { |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 35 | public: |
| 36 | static WebAppProvider* Get(Profile* profile); |
| 37 | |
Giovanni Ortuño Urquidi | 8ea2f1e | 2018-08-06 01:13:05 | [diff] [blame] | 38 | explicit WebAppProvider(Profile* profile); |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 39 | |
Giovanni Ortuño Urquidi | 4f86bf27 | 2018-07-31 02:09:03 | [diff] [blame] | 40 | // Clients can use PendingAppManager to install, uninstall, and update |
| 41 | // Web Apps. |
| 42 | PendingAppManager& pending_app_manager() { return *pending_app_manager_; } |
| 43 | |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 44 | ~WebAppProvider() override; |
| 45 | |
Alexey Baskakov | 396edb9 | 2018-08-02 05:11:42 | [diff] [blame] | 46 | static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 47 | |
Giovanni Ortuño Urquidi | fd7ed286 | 2018-08-29 13:26:49 | [diff] [blame] | 48 | void Reset(); |
| 49 | |
| 50 | // content::NotificationObserver |
| 51 | void Observe(int type, |
| 52 | const content::NotificationSource& source, |
| 53 | const content::NotificationDetails& details) override; |
Giovanni Ortuño Urquidi | 2fb415b0 | 2018-08-22 07:18:51 | [diff] [blame] | 54 | |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 55 | private: |
Dominick Ng | 4b176fd | 2018-08-20 16:15:56 | [diff] [blame] | 56 | void OnScanForExternalWebApps( |
Dominick Ng | 7b4ad0b8 | 2018-08-03 15:29:10 | [diff] [blame] | 57 | std::vector<web_app::PendingAppManager::AppInfo>); |
| 58 | |
Giovanni Ortuño Urquidi | 4f86bf27 | 2018-07-31 02:09:03 | [diff] [blame] | 59 | std::unique_ptr<PendingAppManager> pending_app_manager_; |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 60 | std::unique_ptr<WebAppPolicyManager> web_app_policy_manager_; |
Christopher Lam | 0999fe35 | 2018-09-24 05:01:26 | [diff] [blame^] | 61 | std::unique_ptr<SystemWebAppManager> system_web_app_manager_; |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 62 | |
Giovanni Ortuño Urquidi | fd7ed286 | 2018-08-29 13:26:49 | [diff] [blame] | 63 | content::NotificationRegistrar registrar_; |
| 64 | |
Dominick Ng | 7b4ad0b8 | 2018-08-03 15:29:10 | [diff] [blame] | 65 | base::WeakPtrFactory<WebAppProvider> weak_ptr_factory_{this}; |
| 66 | |
Nigel Tao | 192c330 | 2018-07-19 15:17:28 | [diff] [blame] | 67 | DISALLOW_COPY_AND_ASSIGN(WebAppProvider); |
| 68 | }; |
| 69 | |
| 70 | } // namespace web_app |
| 71 | |
| 72 | #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_PROVIDER_H_ |