File: webapk_install_service.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (148 lines) | stat: -rw-r--r-- 6,169 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALL_SERVICE_H_
#define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALL_SERVICE_H_

#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>

#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/webapps/browser/android/shortcut_info.h"
#include "components/webapps/browser/installable/installable_metrics.h"
#include "url/gurl.h"

namespace base {
class FilePath;
}

namespace content {
class BrowserContext;
class WebContents;
}

namespace webapps {
enum class WebApkInstallResult;
enum class WebApkUpdateReason;
}  // namespace webapps

class SkBitmap;

// Service which talks to Chrome WebAPK server and Google Play to generate a
// WebAPK on the server, download it, and install it.
class WebApkInstallService : public KeyedService {
 public:
  // Called when the creation/updating of a WebAPK is finished or failed.
  // Parameters:
  // - the result of the installation.
  // - true if Chrome received a "request updates less frequently" directive.
  //   from the WebAPK server.
  // - the package name of the WebAPK.
  using FinishCallback = base::OnceCallback<void(webapps::WebApkInstallResult,
                                                 bool,
                                                 const std::string&)>;

  // Called when the installation of a WebAPK finished or failed.
  using InstallFinishCallback =
      base::OnceCallback<void(webapps::WebApkInstallResult)>;

  explicit WebApkInstallService(content::BrowserContext* browser_context);

  WebApkInstallService(const WebApkInstallService&) = delete;
  WebApkInstallService& operator=(const WebApkInstallService&) = delete;

  ~WebApkInstallService() override;

  // Returns whether an install for |web_manifest_url| is in progress.
  bool IsInstallInProgress(const GURL& manifest_id);

  // Installs WebAPK and adds shortcut to the launcher. It talks to the Chrome
  // WebAPK server to generate a WebAPK on the server and to Google Play to
  // install the downloaded WebAPK.
  void InstallAsync(content::WebContents* web_contents,
                    const webapps::ShortcutInfo& shortcut_info,
                    const SkBitmap& primary_icon,
                    webapps::WebappInstallSource install_source);

  void InstallRestoreAsync(content::WebContents* web_contents,
                           const webapps::ShortcutInfo& shortcut_info,
                           const SkBitmap& primary_icon,
                           webapps::WebappInstallSource install_source,
                           InstallFinishCallback finish_callback);

  // Talks to the Chrome WebAPK server to update a WebAPK on the server and to
  // the Google Play server to install the downloaded WebAPK.
  // |update_request_path| is the path of the file with the update request.
  // Calls |finish_callback| once the update completed or failed.
  void UpdateAsync(const base::FilePath& update_request_path,
                   FinishCallback finish_callback);

 private:
  // Called once the install/update completed or failed.
  void OnFinishedInstall(base::WeakPtr<content::WebContents> web_contents,
                         const webapps::ShortcutInfo& shortcut_info,
                         const SkBitmap& primary_icon,
                         webapps::WebApkInstallResult result,
                         bool relax_updates,
                         const std::string& webapk_package_name);

  void OnFinishedInstallRestore(const webapps::ShortcutInfo& shortcut_info,
                                const SkBitmap& primary_icon,
                                InstallFinishCallback finish_callback,
                                webapps::WebApkInstallResult result,
                                bool /* relax_updates */,
                                const std::string& webapk_package_name);

  // Removes current notifications about an ongoing install and adds a
  // installed-notification if the installation was successful.
  void HandleFinishInstallNotifications(const GURL& manifest_url,
                                        const GURL& url,
                                        const std::u16string& short_name,
                                        const SkBitmap& primary_icon,
                                        bool is_primary_icon_maskable,
                                        webapps::WebApkInstallResult result,
                                        const std::string& webapk_package_name,
                                        bool show_failure_notification);

  // Shows a notification that an install is in progress.
  static void ShowInstallInProgressNotification(
      const GURL& manifest_url,
      const std::u16string& short_name,
      const GURL& url,
      const SkBitmap& primary_icon,
      bool is_primary_icon_maskable);

  // Shows a notification that an install is completed.
  static void ShowInstalledNotification(const GURL& manifest_url,
                                        const std::u16string& short_name,
                                        const GURL& url,
                                        const SkBitmap& primary_icon,
                                        bool is_primary_icon_maskable,
                                        const std::string& package_name);

  // Shows a notification that an install is failed.
  static void ShowInstallFailedNotification(
      const GURL& manifest_url,
      const std::u16string& short_name,
      const GURL& url,
      const SkBitmap& primary_icon,
      bool is_primary_icon_maskable,
      webapps::WebApkInstallResult result);

  raw_ptr<content::BrowserContext> browser_context_;

  // In progress installs's id.
  std::set<GURL> install_ids_;

  // Used to get |weak_ptr_|.
  base::WeakPtrFactory<WebApkInstallService> weak_ptr_factory_{this};
};

#endif  // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALL_SERVICE_H_