File: manifest_update_utils.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 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 (160 lines) | stat: -rw-r--r-- 5,252 bytes parent folder | download | duplicates (3)
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
149
150
151
152
153
154
155
156
157
158
159
160
// 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_MANIFEST_UPDATE_UTILS_H_
#define CHROME_BROWSER_WEB_APPLICATIONS_MANIFEST_UPDATE_UTILS_H_

#include <iosfwd>
#include <string>

#include "chrome/browser/web_applications/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_icon_generator.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "chrome/browser/web_applications/web_app_install_utils.h"
#include "components/webapps/common/web_app_id.h"

namespace web_app {

class WebApp;
class WebAppRegistrar;

inline constexpr SquareSizePx kIdentitySizes[] = {kInstallIconSize,
                                                  kLauncherIconSize};

// This enum is recorded by UMA, the numeric values must not change.
enum class ManifestUpdateResult {
  kNoAppInScope = 0,
  kThrottled = 1,
  kWebContentsDestroyed = 2,
  kAppUninstalling = 3,
  kAppIsPlaceholder = 4,
  kAppUpToDate = 5,
  kAppNotEligible = 6,
  kAppUpdateFailed = 7,
  kAppUpdated = 8,
  kAppIsSystemWebApp = 9,
  kIconDownloadFailed = 10,
  kIconReadFromDiskFailed = 11,
  kAppIdMismatch = 12,
  // kAppAssociationsUpdateFailed = 13,
  // kAppAssociationsUpdated = 14,
  kSystemShutdown = 15,
  kAppIdentityUpdateRejectedAndUninstalled = 16,
  kAppIsIsolatedWebApp = 17,
  kCancelledDueToMainFrameNavigation = 18,
  kShortcutIgnoresManifest = 19,
  kMaxValue = kShortcutIgnoresManifest,
};

std::ostream& operator<<(std::ostream& os, ManifestUpdateResult result);

// Not actually used in production logic. This is just for async code
// organisation and debugging output.
enum class ManifestUpdateCheckStage {
  kPendingAppLock,
  kDownloadingNewManifestData,
  kLoadingExistingManifestData,
  kComparingManifestData,
  kResolvingIdentityChanges,
  kComplete,
};

std::ostream& operator<<(std::ostream& os, ManifestUpdateCheckStage stage);

enum class ManifestUpdateCheckResult {
  kAppIdMismatch,
  kAppNotEligible,
  kSystemShutdown,
  kAppUpdateNeeded,
  kAppIdentityUpdateRejectedAndUninstalled,
  kAppUpToDate,
  kIconDownloadFailed,
  kIconReadFromDiskFailed,
  kWebContentsDestroyed,
  kCancelledDueToMainFrameNavigation,
};

std::ostream& operator<<(std::ostream& os, ManifestUpdateCheckResult result);

ManifestUpdateResult FinalResultFromManifestUpdateCheckResult(
    ManifestUpdateCheckResult check_result);

void RecordIconDownloadMetrics(IconsDownloadedResult result,
                               DownloadedIconsHttpResults icons_http_results);

bool CanWebAppSilentlyUpdateIdentity(const WebApp& web_app);
bool CanShowIdentityUpdateConfirmationDialog(const WebAppRegistrar& registrar,
                                             const WebApp& web_app);

struct AppIconIdentityChange {
  SkBitmap before;
  SkBitmap after;
};

enum class IdentityUpdateDecision {
  kRevert,
  kGetUserConfirmation,
  kSilentlyAllow,
};

// Represents what's different between two sets of manifest data split up by
// whether the parts are important to app identity. Also captures whether
// identity changes are allowed/pending/reverted.
struct ManifestDataChanges {
  ManifestDataChanges();
  ManifestDataChanges(ManifestDataChanges&&);
  ManifestDataChanges& operator=(ManifestDataChanges&&);
  ~ManifestDataChanges();

  bool app_name_changed = false;

  std::optional<AppIconIdentityChange> app_icon_identity_change;

  // `any_app_icon_changed` represents whether any app icon has changed
  // including identity and non-identity affecting app icons because reverting
  // changes to identity app icons will revert all app icon changes.
  bool any_app_icon_changed = false;

  bool other_fields_changed = false;

  std::optional<IdentityUpdateDecision> app_name_identity_update_decision;
  std::optional<IdentityUpdateDecision> app_icon_identity_update_decision;

  bool HasIdentityChanges() const {
    return app_name_changed || app_icon_identity_change;
  }

  bool RequiresConfirmation() const {
    return app_name_identity_update_decision ==
               IdentityUpdateDecision::kGetUserConfirmation ||
           app_icon_identity_update_decision ==
               IdentityUpdateDecision::kGetUserConfirmation;
  }

  explicit operator bool() const {
    return app_name_changed || any_app_icon_changed || other_fields_changed;
  }
};

// `existing_app_icon_bitmaps` and `existing_shortcuts_menu_icon_bitmaps` are
// optional and will not be checked if not provided.
// TODO(crbug.com/414851433): Remove this if manifest_update_check_command is
// not in use.
ManifestDataChanges GetManifestDataChanges(
    const WebApp& existing_web_app,
    const IconBitmaps* existing_app_icon_bitmaps,
    const ShortcutsMenuIconBitmaps* existing_shortcuts_menu_icon_bitmaps,
    const WebAppInstallInfo& new_install_info);

std::optional<AppIconIdentityChange> CompareIdentityIconBitmaps(
    const IconBitmaps& existing_app_icon_bitmaps,
    const IconBitmaps& new_app_icon_bitmaps);

void RecordIdentityConfirmationMetrics(
    const ManifestDataChanges& manifest_data_changes,
    const WebApp& web_app);

}  // namespace web_app

#endif  // CHROME_BROWSER_WEB_APPLICATIONS_MANIFEST_UPDATE_UTILS_H_