File: app.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 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 (187 lines) | stat: -rw-r--r-- 7,342 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SERVICES_APP_SERVICE_PUBLIC_CPP_APP_H_
#define COMPONENTS_SERVICES_APP_SERVICE_PUBLIC_CPP_APP_H_

#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "base/component_export.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/services/app_service/public/cpp/app_types.h"
#include "components/services/app_service/public/cpp/icon_types.h"
#include "components/services/app_service/public/cpp/intent_filter.h"
#include "components/services/app_service/public/cpp/package_id.h"
#include "components/services/app_service/public/cpp/permission.h"
#include "components/services/app_service/public/cpp/run_on_os_login_types.h"

namespace apps {

// Information about an app. See components/services/app_service/README.md.
struct COMPONENT_EXPORT(APP_TYPES) App {
  App(AppType app_type, const std::string& app_id);

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

  ~App();

  bool operator==(const App& other) const;

  std::unique_ptr<App> Clone() const;

  // Adds a new field for `extra`. The type `T` can be any type, e.g. int,
  // double, string, base::Value::Dict, base::Value::List, base::Value, etc. The
  // value is saved in base::Value::Dict `extra`. If the type `T` can't be
  // converted to base::Value, an explicit convert function can be added to
  // convert `value` to base::Value.
  template <typename T>
  void SetExtraField(const std::string& field_name, T&& value) {
    if (!extra.has_value()) {
      extra = base::Value::Dict();
    }
    extra->Set(field_name, value);
  }

  AppType app_type;
  std::string app_id;

  Readiness readiness = Readiness::kUnknown;

  // The full name of the app. Will be used in most UIs.
  std::optional<std::string> name;
  // A shortened version of the app name. May omit branding (e.g.
  // "Google" prefixes) or rely on abbreviations (e.g. "YT Music"). If no
  // `short_name` is supplied, the `name` will be used instead.
  // The `short_name` may be used in UIs where space is limited and/or we want
  // to optimize for scannability.
  std::optional<std::string> short_name;

  // An optional, publisher-specific ID for this app, e.g. for Android apps,
  // this field contains the Android package name, and for web apps, it
  // contains the start URL.
  std::optional<std::string> publisher_id;

  // An optional ID for the package that installed this app. In general, this
  // will match the `app_type` and `publisher_id` of the app. However, this is
  // permitted to diverge for alternate installation methods, e.g. web apps that
  // are installed through the Play Store.
  std::optional<PackageId> installer_package_id;

  std::optional<std::string> description;
  std::optional<std::string> version;
  std::vector<std::string> additional_search_terms;

  std::optional<IconKey> icon_key;

  std::optional<base::Time> last_launch_time;
  std::optional<base::Time> install_time;

  // This vector must be treated atomically, if there is a permission
  // change, the publisher must send through the entire list of permissions.
  // Should contain no duplicate IDs.
  // If empty during updates, Subscriber can assume no changes.
  // There is no guarantee that this is sorted by any criteria.
  Permissions permissions;

  // The main reason why this app is currently installed on the device (e.g.
  // because it is required by Policy). This may change over time and is not
  // necessarily the reason why the app was originally installed.
  InstallReason install_reason = InstallReason::kUnknown;

  // How installation of the app was triggered on this device. Either a UI
  // surface (e.g. Play Store), or a system component (e.g. Sync).
  InstallSource install_source = InstallSource::kUnknown;

  // IDs used for policy to identify the app.
  // For web apps, it contains the install URL(s).
  std::vector<std::string> policy_ids;

  // Whether the app is an extensions::Extensions where is_platform_app()
  // returns true.
  std::optional<bool> is_platform_app;

  std::optional<bool> recommendable;
  std::optional<bool> searchable;
  std::optional<bool> show_in_launcher;
  std::optional<bool> show_in_shelf;
  std::optional<bool> show_in_search;
  std::optional<bool> show_in_management;

  // True if the app is able to handle intents and should be shown in intent
  // surfaces.
  std::optional<bool> handles_intents;

  // Whether the app publisher allows the app to be uninstalled.
  std::optional<bool> allow_uninstall;

  // Whether the app icon should add the notification badging.
  std::optional<bool> has_badge;

  // Paused apps cannot be launched, and any running apps that become paused
  // will be stopped. This is independent of whether or not the app is ready to
  // be launched (defined by the Readiness field).
  std::optional<bool> paused;

  // This vector stores all the intent filters defined in this app. Each
  // intent filter defines a matching criteria for whether an intent can
  // be handled by this app. One app can have multiple intent filters.
  IntentFilters intent_filters;

  // Whether the app can be free resized. If this is true, various resizing
  // operations will be restricted.
  std::optional<bool> resize_locked;

  // Whether the app's display mode is in the browser or otherwise.
  WindowMode window_mode = WindowMode::kUnknown;

  // Whether the app runs on os login in a new window or not.
  std::optional<RunOnOsLogin> run_on_os_login;

  // Whether the app can be closed by the user.
  std::optional<bool> allow_close;

  // If the value is false, User will not be able to select open mode (i.e.
  // open in new window or in new tab) for the app. The app will default to be
  // opened in a new window.
  std::optional<bool> allow_window_mode_selection;

  // Storage space size for app and associated data.
  std::optional<uint64_t> app_size_in_bytes;
  std::optional<uint64_t> data_size_in_bytes;

  // App-specified supported locales.
  std::vector<std::string> supported_locales;
  // Currently selected locale, empty string means system language is used.
  // ARC-specific note: Based on Android implementation, `selected_locale`
  //  is not necessarily part of `supported_locales`.
  std::optional<std::string> selected_locale;

  // The extra information used by the app platform(e.g. ARC, GuestOS) for an
  // app. `extra` needs to be modified as a whole, and we can't only modify part
  // of `extra`. AppService doesn't use the fields saved in `extra`. App
  // publishers modify the content saved in `extra`.
  std::optional<base::Value::Dict> extra;

  // When adding new fields to the App type, the `Clone` function, the
  // `operator==` function, and the `AppUpdate` class should also be updated. If
  // the new fields should be saved, below functions should be updated:
  // `AppStorage::IsAppChanged`
  // `AppStorageFileHandler::ConvertAppsToValue`
  // `AppStorageFileHandler::ConvertValueToApps`
};

using AppPtr = std::unique_ptr<App>;

COMPONENT_EXPORT(APP_TYPES)
bool IsEqual(const std::vector<AppPtr>& source,
             const std::vector<AppPtr>& target);

}  // namespace apps

#endif  // COMPONENTS_SERVICES_APP_SERVICE_PUBLIC_CPP_APP_H_