File: app_install_service_ash.h

package info (click to toggle)
chromium 139.0.7258.127-1~deb13u1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,096 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (136 lines) | stat: -rw-r--r-- 5,272 bytes parent folder | download | duplicates (6)
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
// Copyright 2023 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_APPS_APP_SERVICE_APP_INSTALL_APP_INSTALL_SERVICE_ASH_H_
#define CHROME_BROWSER_APPS_APP_SERVICE_APP_INSTALL_APP_INSTALL_SERVICE_ASH_H_

#include <iosfwd>
#include <optional>

#include "base/functional/callback_forward.h"
#include "base/memory/raw_ref.h"
#include "base/memory/weak_ptr.h"
#include "build/build_config.h"
#include "chrome/browser/apps/almanac_api_client/device_info_manager.h"
#include "chrome/browser/apps/app_service/app_install/app_install_almanac_endpoint.h"
#include "chrome/browser/apps/app_service/app_install/app_install_service.h"
#include "chrome/browser/apps/app_service/app_install/arc_app_installer.h"
#include "chrome/browser/apps/app_service/app_install/web_app_installer.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/native_window_tracker.h"

static_assert(BUILDFLAG(IS_CHROMEOS));

namespace ash::app_install {
class AppInstallDialog;
}

namespace apps {

// These values are persisted to logs.
// Entries should not be renumbered and numeric values should never be reused.
// Additions to this enum must be added to the corresponding enum XML in:
// tools/metrics/histograms/metadata/apps/enums.xml
enum class AppInstallResult {
  kUnknown = 0,
  kSuccess = 1,
  kAlmanacFetchFailed = 2,  // Connection error trying to contact server.
  kAppDataCorrupted = 3,    // Server response failed validity checks.
  kAppProviderNotAvailable = 4,
  kAppTypeNotSupported = 5,
  kInstallParametersInvalid = 6,
  kInstallDialogNotAccepted = 7,
  kAppTypeInstallFailed = 8,
  kUserTypeNotPermitted = 9,
  kBadAppRequest = 10,  // Server rejected request.
  kInstallUrlFallback = 11,
  kMaxValue = kInstallUrlFallback,
};

class AppInstallServiceAsh : public AppInstallService {
 public:
  static base::OnceCallback<void(PackageId)>& InstallAppCallbackForTesting();

  explicit AppInstallServiceAsh(Profile& profile);
  AppInstallServiceAsh(const AppInstallServiceAsh&) = delete;
  AppInstallServiceAsh& operator=(const AppInstallServiceAsh&) = delete;
  ~AppInstallServiceAsh() override;

  // AppInstallService:
  void InstallAppWithFallback(AppInstallSurface surface,
                              std::string serialized_package_id,
                              std::optional<WindowIdentifier> anchor_window,
                              base::OnceClosure callback) override;

  void InstallApp(AppInstallSurface surface,
                  PackageId package_id,
                  std::optional<gfx::NativeWindow> anchor_window,
                  base::OnceClosure callback) override;

  void InstallAppHeadless(
      AppInstallSurface surface,
      PackageId package_id,
      base::OnceCallback<void(bool success)> callback) override;

  void InstallAppHeadless(
      AppInstallSurface surface,
      AppInstallData data,
      base::OnceCallback<void(bool success)> callback) override;

 private:
  bool CanUserInstall() const;
  bool MaybeLaunchApp(const PackageId& package_id);
  void FetchAppInstallData(
      PackageId package_id,
      app_install_almanac_endpoint::GetAppInstallInfoCallback data_callback);

  void PerformInstallHeadless(AppInstallSurface surface,
                              PackageId expected_package_id,
                              base::OnceCallback<void(bool success)> callback,
                              base::expected<AppInstallData, QueryError> data);

  void ShowDialogAndInstall(
      AppInstallSurface surface,
      PackageId expected_package_id,
      std::optional<gfx::NativeWindow> anchor_window,
      std::unique_ptr<views::NativeWindowTracker> anchor_window_tracker,
      base::OnceCallback<void(AppInstallResult)> callback,
      base::expected<AppInstallData, QueryError> data);
  void InstallIfDialogAccepted(
      AppInstallSurface surface,
      AppInstallData data,
      base::WeakPtr<ash::app_install::AppInstallDialog> dialog,
      base::OnceCallback<void(AppInstallResult)> callback,
      bool dialog_accepted);
  void ProcessInstallResult(
      AppInstallSurface surface,
      AppInstallData data,
      base::WeakPtr<ash::app_install::AppInstallDialog> dialog,
      base::OnceCallback<void(AppInstallResult)> callback,
      bool install_success);

  // Installs the requested app from the given `data`. This method is
  // called by both headless and dialog-based flows, and assumes that all
  // relevant policy checks have already been completed.
  void PerformInstall(AppInstallSurface surface,
                      AppInstallData data,
                      base::OnceCallback<void(bool)> install_callback);

  void FetchAppInstallUrl(
      std::string serialized_package_id,
      base::OnceCallback<void(base::expected<GURL, QueryError>)> callback);
  void MaybeLaunchAppInstallUrl(
      base::OnceCallback<void(AppInstallResult)> callback,
      base::expected<GURL, QueryError> install_url);

  raw_ref<Profile> profile_;
  ArcAppInstaller arc_app_installer_;
  WebAppInstaller web_app_installer_;

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

}  // namespace apps

#endif  // CHROME_BROWSER_APPS_APP_SERVICE_APP_INSTALL_APP_INSTALL_SERVICE_ASH_H_