blob: 9c5ef7d53e7a9e8da5c61f3b03530abfd096fb7e [file] [log] [blame]
Nigel Tao192c3302018-07-19 15:17:281// 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 Ng7b4ad0b82018-08-03 15:29:109#include <vector>
Nigel Tao192c3302018-07-19 15:17:2810
11#include "base/macros.h"
Dominick Ng7b4ad0b82018-08-03 15:29:1012#include "base/memory/weak_ptr.h"
13#include "chrome/browser/web_applications/components/pending_app_manager.h"
Nigel Tao192c3302018-07-19 15:17:2814#include "components/keyed_service/core/keyed_service.h"
Giovanni Ortuño Urquidifd7ed2862018-08-29 13:26:4915#include "content/public/browser/notification_observer.h"
16#include "content/public/browser/notification_registrar.h"
Nigel Tao192c3302018-07-19 15:17:2817
18class Profile;
19
Alexey Baskakovfd3894e2018-10-16 06:09:5820namespace content {
21class WebContents;
22}
23
Alexey Baskakov396edb92018-08-02 05:11:4224namespace user_prefs {
25class PrefRegistrySyncable;
26}
27
Nigel Tao192c3302018-07-19 15:17:2828namespace web_app {
29
Alexey Baskakovfd3894e2018-10-16 06:09:5830// Forward declarations of generalized interfaces.
Giovanni Ortuño Urquidi4f86bf272018-07-31 02:09:0331class PendingAppManager;
Alexey Baskakovfd3894e2018-10-16 06:09:5832class InstallManager;
33
34// Forward declarations for new extension-independent subsystems.
35class WebAppRegistrar;
36
37// Forward declarations for legacy extension-based subsystems.
Nigel Tao192c3302018-07-19 15:17:2838class WebAppPolicyManager;
Christopher Lam0999fe352018-09-24 05:01:2639class SystemWebAppManager;
Nigel Tao192c3302018-07-19 15:17:2840
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 Urquidifd7ed2862018-08-29 13:26:4944class WebAppProvider : public KeyedService,
45 public content::NotificationObserver {
Nigel Tao192c3302018-07-19 15:17:2846 public:
47 static WebAppProvider* Get(Profile* profile);
Alexey Baskakovfd3894e2018-10-16 06:09:5848 static WebAppProvider* GetForWebContents(
49 const content::WebContents* web_contents);
Nigel Tao192c3302018-07-19 15:17:2850
Giovanni Ortuño Urquidi8ea2f1e2018-08-06 01:13:0551 explicit WebAppProvider(Profile* profile);
Nigel Tao192c3302018-07-19 15:17:2852
Giovanni Ortuño Urquidi4f86bf272018-07-31 02:09:0353 // Clients can use PendingAppManager to install, uninstall, and update
54 // Web Apps.
55 PendingAppManager& pending_app_manager() { return *pending_app_manager_; }
56
Nigel Tao192c3302018-07-19 15:17:2857 ~WebAppProvider() override;
58
Alexey Baskakov396edb92018-08-02 05:11:4259 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
60
Alexey Baskakovfd3894e2018-10-16 06:09:5861 // 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 Urquidifd7ed2862018-08-29 13:26:4968 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 Urquidi2fb415b02018-08-22 07:18:5174
Nigel Tao192c3302018-07-19 15:17:2875 private:
Alexey Baskakovfd3894e2018-10-16 06:09:5876 // Create extension-independent subsystems.
77 void CreateWebAppsSubsystems(Profile* profile);
78 // ... or create legacy extension-based subsystems.
79 void CreateBookmarkAppsSubsystems(Profile* profile);
80
Dominick Ng4b176fd2018-08-20 16:15:5681 void OnScanForExternalWebApps(
Dominick Ng7b4ad0b82018-08-03 15:29:1082 std::vector<web_app::PendingAppManager::AppInfo>);
83
Alexey Baskakovfd3894e2018-10-16 06:09:5884 // 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 Urquidi4f86bf272018-07-31 02:09:0389 std::unique_ptr<PendingAppManager> pending_app_manager_;
Alexey Baskakovfd3894e2018-10-16 06:09:5890
91 // Legacy extension-based subsystems:
Nigel Tao192c3302018-07-19 15:17:2892 std::unique_ptr<WebAppPolicyManager> web_app_policy_manager_;
Christopher Lam0999fe352018-09-24 05:01:2693 std::unique_ptr<SystemWebAppManager> system_web_app_manager_;
Nigel Tao192c3302018-07-19 15:17:2894
Alexey Baskakov3a5a2cf2018-10-10 02:44:4395 content::NotificationRegistrar notification_registrar_;
Giovanni Ortuño Urquidifd7ed2862018-08-29 13:26:4996
Dominick Ng7b4ad0b82018-08-03 15:29:1097 base::WeakPtrFactory<WebAppProvider> weak_ptr_factory_{this};
98
Nigel Tao192c3302018-07-19 15:17:2899 DISALLOW_COPY_AND_ASSIGN(WebAppProvider);
100};
101
102} // namespace web_app
103
104#endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_PROVIDER_H_