File: install_from_sync_command.h

package info (click to toggle)
chromium 140.0.7339.185-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,193,740 kB
  • sloc: cpp: 35,093,945; ansic: 7,161,670; javascript: 4,199,694; python: 1,441,797; asm: 949,904; xml: 747,515; pascal: 187,748; perl: 88,691; sh: 88,248; objc: 79,953; sql: 52,714; cs: 44,599; fortran: 24,137; makefile: 22,114; tcl: 15,277; php: 13,980; yacc: 9,000; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (142 lines) | stat: -rw-r--r-- 5,191 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
// Copyright 2022 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_WEB_APPLICATIONS_COMMANDS_INSTALL_FROM_SYNC_COMMAND_H_
#define CHROME_BROWSER_WEB_APPLICATIONS_COMMANDS_INSTALL_FROM_SYNC_COMMAND_H_

#include <memory>
#include <string>
#include <vector>

#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "chrome/browser/web_applications/commands/web_app_command.h"
#include "chrome/browser/web_applications/jobs/manifest_to_web_app_install_info_job.h"
#include "chrome/browser/web_applications/locks/shared_web_contents_with_app_lock.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom.h"
#include "chrome/browser/web_applications/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "chrome/browser/web_applications/web_app_install_params.h"
#include "chrome/browser/web_applications/web_app_logging.h"
#include "components/webapps/browser/installable/installable_logging.h"
#include "third_party/skia/include/core/SkColor.h"
#include "url/gurl.h"

class Profile;

namespace webapps {
class WebAppUrlLoader;
enum class WebAppUrlLoaderResult;
}  // namespace webapps

namespace web_app {

class WebAppDataRetriever;

// Installs a web app using data from sync. This command will first try to
// fetch a manifest from the app's start URL to get the latest metadata. If that
// fails, it will fall back to using the information provided from sync data to
// ensure the app is installed.
class InstallFromSyncCommand
    : public WebAppCommand<SharedWebContentsWithAppLock,
                           const webapps::AppId&,
                           webapps::InstallResultCode> {
 public:
  struct Params {
    Params() = delete;
    ~Params();
    Params(const Params&);
    Params(const webapps::AppId& app_id,
           const webapps::ManifestId& manifest_id,
           const GURL& start_url,
           const std::string& title,
           const GURL& scope,
           const std::optional<SkColor>& theme_color,
           const std::optional<mojom::UserDisplayMode>& user_display_mode,
           const std::vector<apps::IconInfo>& manifest_icons,
           const std::vector<apps::IconInfo>& trusted_icons);
    const webapps::AppId app_id;
    const webapps::ManifestId manifest_id;
    const GURL start_url;
    const std::string title;
    const GURL scope;
    const std::optional<SkColor> theme_color;
    const std::optional<mojom::UserDisplayMode> user_display_mode;
    const std::vector<apps::IconInfo> manifest_icons;
    const std::vector<apps::IconInfo> trusted_icons;
  };
  using DataRetrieverFactory =
      base::RepeatingCallback<std::unique_ptr<WebAppDataRetriever>()>;

  InstallFromSyncCommand(Profile* profile,
                         const Params& params,
                         OnceInstallCallback install_callback);
  ~InstallFromSyncCommand() override;

  void SetFallbackTriggeredForTesting(
      base::OnceCallback<void(webapps::InstallResultCode code)> callback);

  // WebAppCommand:
 protected:
  void StartWithLock(
      std::unique_ptr<SharedWebContentsWithAppLock> lock) override;

 private:
  void OnWebAppUrlLoadedGetWebAppInstallInfo(
      webapps::WebAppUrlLoaderResult result);

  void OnGetWebAppInstallInfo(std::unique_ptr<WebAppInstallInfo> web_app_info);

  void OnDidPerformInstallableCheck(
      std::unique_ptr<WebAppInstallInfo> page_info,
      blink::mojom::ManifestPtr opt_manifest,
      bool valid_manifest_for_web_app,
      webapps::InstallableStatusCode error_code);

  enum class FinalizeMode { kNormalWebAppInfo, kFallbackWebAppInfo };

  void OnWebAppInstallInfoRetrievedMergeAndFinalizeInstall(
      std::unique_ptr<WebAppInstallInfo> install_info);

  void OnIconsRetrievedForFallbackInfo(
      IconsDownloadedResult result,
      IconsMap icons_map,
      DownloadedIconsHttpResults icons_http_results);

  void FinalizeInstall(FinalizeMode mode);

  void OnInstallFinalized(FinalizeMode mode,
                          const webapps::AppId& app_id,
                          webapps::InstallResultCode code);

  void InstallFallback(webapps::InstallResultCode error_code);

  void ReportResultAndDestroy(const webapps::AppId& app_id,
                              webapps::InstallResultCode code);

  std::unique_ptr<SharedWebContentsWithAppLock> lock_;

  const raw_ptr<Profile> profile_;
  const Params params_;

  std::unique_ptr<webapps::WebAppUrlLoader> url_loader_;
  std::unique_ptr<WebAppDataRetriever> data_retriever_;
  std::unique_ptr<ManifestToWebAppInstallInfoJob> manifest_to_install_info_job_;

  std::unique_ptr<WebAppInstallInfo> install_info_;
  std::unique_ptr<WebAppInstallInfo> fallback_install_info_;

  InstallErrorLogEntry install_error_log_entry_;

  base::OnceCallback<void(webapps::InstallResultCode code)>
      fallback_triggered_for_testing_;

  base::WeakPtrFactory<InstallFromSyncCommand> weak_ptr_factory_{this};
};

}  // namespace web_app

#endif  // CHROME_BROWSER_WEB_APPLICATIONS_COMMANDS_INSTALL_FROM_SYNC_COMMAND_H_