File: arc_apps.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 (292 lines) | stat: -rw-r--r-- 12,722 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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
// Copyright 2018 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_PUBLISHERS_ARC_APPS_H_
#define CHROME_BROWSER_APPS_APP_SERVICE_PUBLISHERS_ARC_APPS_H_

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

#include "ash/public/cpp/message_center/arc_notification_manager_base.h"
#include "ash/public/cpp/message_center/arc_notifications_host_initializer.h"
#include "base/containers/flat_set.h"
#include "base/functional/callback.h"
#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "chrome/browser/apps/app_service/app_icon/app_icon_factory.h"
#include "chrome/browser/apps/app_service/app_icon/arc_activity_adaptive_icon_impl.h"
#include "chrome/browser/apps/app_service/app_notifications.h"
#include "chrome/browser/apps/app_service/app_service_proxy_forward.h"
#include "chrome/browser/apps/app_service/app_shortcut_item.h"
#include "chrome/browser/apps/app_service/launch_result_type.h"
#include "chrome/browser/apps/app_service/paused_apps.h"
#include "chrome/browser/apps/app_service/publishers/app_publisher.h"
#include "chrome/browser/ash/app_list/arc/arc_app_list_prefs.h"
#include "chrome/browser/ash/arc/app_shortcuts/arc_app_shortcuts_request.h"
#include "chrome/browser/ash/arc/privacy_items/arc_privacy_items_bridge.h"
#include "chromeos/ash/experiences/arc/intent_helper/arc_intent_helper_bridge.h"
#include "chromeos/ash/experiences/arc/intent_helper/arc_intent_helper_observer.h"
#include "chromeos/ash/experiences/arc/mojom/app_permissions.mojom.h"
#include "chromeos/ash/experiences/arc/mojom/intent_helper.mojom-forward.h"
#include "chromeos/ash/experiences/arc/mojom/privacy_items.mojom.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/services/app_service/public/cpp/app_launch_util.h"
#include "components/services/app_service/public/cpp/app_types.h"
#include "components/services/app_service/public/cpp/instance_registry.h"
#include "components/services/app_service/public/cpp/intent.h"
#include "components/services/app_service/public/cpp/menu.h"
#include "components/services/app_service/public/cpp/permission.h"

class Profile;

namespace apps {

class PublisherTest;
class WebApkManager;
struct AppLaunchParams;

// An app publisher (in the App Service sense) of ARC++ apps,
//
// See components/services/app_service/README.md.
class ArcApps : public KeyedService,
                public AppPublisher,
                public ArcAppListPrefs::Observer,
                public arc::ArcIntentHelperObserver,
                public ash::ArcNotificationManagerBase::Observer,
                public ash::ArcNotificationsHostInitializer::Observer,
                public apps::InstanceRegistry::Observer,
                public arc::ArcPrivacyItemsBridge::Observer {
 public:
  static ArcApps* Get(Profile* profile);

  explicit ArcApps(AppServiceProxy* proxy);
  ArcApps(const ArcApps&) = delete;
  ArcApps& operator=(const ArcApps&) = delete;

  ~ArcApps() override;

  WebApkManager* GetWebApkManagerForTesting() { return web_apk_manager_.get(); }

  static void SetArcVersionForTesting(int version);

 private:
  friend class ArcAppsFactory;
  friend class PublisherTest;
  FRIEND_TEST_ALL_PREFIXES(PublisherTest, ArcAppsOnApps);
  FRIEND_TEST_ALL_PREFIXES(PublisherTest, ArcApps_CapabilityAccess);

  using AppIdToTaskIds = std::map<std::string, std::set<int>>;
  using TaskIdToAppId = std::map<int, std::string>;

  void Initialize();

  // KeyedService overrides.
  void Shutdown() override;

  // apps::AppPublisher overrides.
  void GetCompressedIconData(const std::string& app_id,
                             int32_t size_in_dip,
                             ui::ResourceScaleFactor scale_factor,
                             LoadIconCallback callback) override;
  void Launch(const std::string& app_id,
              int32_t event_flags,
              LaunchSource launch_source,
              WindowInfoPtr window_info) override;
  void LaunchAppWithIntent(const std::string& app_id,
                           int32_t event_flags,
                           IntentPtr intent,
                           LaunchSource launch_source,
                           WindowInfoPtr window_info,
                           LaunchCallback callback) override;
  void LaunchAppWithParams(AppLaunchParams&& params,
                           LaunchCallback callback) override;
  void SetPermission(const std::string& app_id,
                     PermissionPtr permission) override;
  void Uninstall(const std::string& app_id,
                 UninstallSource uninstall_source,
                 bool clear_site_data,
                 bool report_abuse) override;
  void GetMenuModel(const std::string& app_id,
                    MenuType menu_type,
                    int64_t display_id,
                    base::OnceCallback<void(MenuItems)> callback) override;
  void SetResizeLocked(const std::string& app_id, bool locked) override;
  void SetAppLocale(const std::string& app_id,
                    const std::string& locale_tag) override;

  void PauseApp(const std::string& app_id) override;
  void UnpauseApp(const std::string& app_id) override;
  void BlockApp(const std::string& app_id) override;
  void UnblockApp(const std::string& app_id) override;
  void StopApp(const std::string& app_id) override;
  void UpdateAppSize(const std::string& app_id) override;
  void ExecuteContextMenuCommand(const std::string& app_id,
                                 int command_id,
                                 const std::string& shortcut_id,
                                 int64_t display_id) override;
  void OpenNativeSettings(const std::string& app_id) override;
  void OnSupportedLinksPreferenceChanged(const std::string& app_id,
                                         bool open_in_app) override;

  // ArcAppListPrefs::Observer overrides.
  void OnAppRegistered(const std::string& app_id,
                       const ArcAppListPrefs::AppInfo& app_info) override;
  void OnAppStatesChanged(const std::string& app_id,
                          const ArcAppListPrefs::AppInfo& app_info) override;
  void OnAppRemoved(const std::string& app_id) override;
  void OnAppNameUpdated(const std::string& app_id,
                        const std::string& name) override;
  void OnAppLastLaunchTimeUpdated(const std::string& app_id) override;
  void OnPackageInstalled(
      const arc::mojom::ArcPackageInfo& package_info) override;
  void OnPackageModified(
      const arc::mojom::ArcPackageInfo& package_info) override;
  void OnPackageListInitialRefreshed() override;
  void OnTaskCreated(int32_t task_id,
                     const std::string& package_name,
                     const std::string& activity,
                     const std::string& intent,
                     int32_t session_id) override;
  void OnTaskDestroyed(int32_t task_id) override;
  void OnInstallationStarted(const std::string& package_name) override;
  void OnInstallationProgressChanged(const std::string& package_name,
                                     float progress) override;
  void OnInstallationActiveChanged(const std::string& package_name,
                                   bool active) override;
  void OnInstallationFinished(const std::string& package_name,
                              bool success,
                              bool is_launchable_app) override;
  void OnAppConnectionClosed() override;

  // arc::ArcIntentHelperObserver overrides.
  void OnIntentFiltersUpdated(
      const std::optional<std::string>& package_name) override;
  void OnArcSupportedLinksChanged(
      const std::vector<arc::mojom::SupportedLinksPackagePtr>& added,
      const std::vector<arc::mojom::SupportedLinksPackagePtr>& removed,
      arc::mojom::SupportedLinkChangeSource source) override;

  // ash::ArcNotificationsHostInitializer::Observer overrides.
  void OnSetArcNotificationsInstance(
      ash::ArcNotificationManagerBase* arc_notification_manager) override;
  void OnArcNotificationInitializerDestroyed(
      ash::ArcNotificationsHostInitializer* initializer) override;

  // ArcNotificationManagerBase::Observer overrides.
  void OnNotificationUpdated(const std::string& notification_id,
                             const std::string& app_id) override;
  void OnNotificationRemoved(const std::string& notification_id) override;
  void OnArcNotificationManagerDestroyed(
      ash::ArcNotificationManagerBase* notification_manager) override;

  // ArcPrivacyItemsBridgeObserver overrides.
  void OnPrivacyItemsChanged(
      const std::vector<arc::mojom::PrivacyItemPtr>& privacy_items) override;

  // apps::InstanceRegistry::Observer overrides.
  void OnInstanceUpdate(const apps::InstanceUpdate& update) override;
  void OnInstanceRegistryWillBeDestroyed(
      apps::InstanceRegistry* instance_registry) override;

  // Creates the App struct for `app_id` based on `app_info`. If `update_icon`
  // is true, creates a new icon key. If `raw_icon_updated` is true, sets
  // `raw_icon_updated` in the icon key as true, to remove the icon files in the
  // icon directory to get the new icon files when loading icons.
  AppPtr CreateApp(ArcAppListPrefs* prefs,
                   const std::string& app_id,
                   const ArcAppListPrefs::AppInfo& app_info,
                   bool update_icon = true,
                   bool raw_icon_updated = false);
  void ConvertAndPublishPackageApps(
      const arc::mojom::ArcPackageInfo& package_info,
      bool update_icon = true);
  IconEffects GetIconEffects(const std::string& app_id,
                             const ArcAppListPrefs::AppInfo& app_info);
  void SetIconEffect(const std::string& app_id);
  void CloseTasks(const std::string& app_id);

  void BuildMenuForShortcut(const std::string& package_name,
                            MenuItems menu_items,
                            base::OnceCallback<void(MenuItems)> callback);

  // Bound by |arc_app_shortcuts_request_|'s OnGetAppShortcutItems method.
  void OnGetAppShortcutItems(
      MenuItems menu_items,
      base::OnceCallback<void(MenuItems)> callback,
      std::unique_ptr<apps::AppShortcutItems> app_shortcut_items);

  // Observes DisabledSystemFeaturesList policy.
  void ObserveDisabledSystemFeaturesPolicy();

  // Triggered when DisabledSystemFeaturesList policy changes.
  void OnDisableListPolicyChanged();

  // Returns true if the app is suspended.
  bool IsAppSuspended(const std::string& app_id,
                      const ArcAppListPrefs::AppInfo& app_info);

  // Calculates the readiness state. Use this function for installed apps to be
  // consistent.
  Readiness GetReadiness(const std::string& app_id,
                         const ArcAppListPrefs::AppInfo& app_info);

  const raw_ptr<Profile> profile_;
  ArcActivityAdaptiveIconImpl arc_activity_adaptive_icon_impl_;

  PausedApps paused_apps_;

  AppIdToTaskIds app_id_to_task_ids_;
  TaskIdToAppId task_id_to_app_id_;

  // App id set which might be accessing camera or microphone.
  base::flat_set<std::string> accessing_apps_;

  // Handles requesting app shortcuts from Android.
  std::unique_ptr<arc::ArcAppShortcutsRequest> arc_app_shortcuts_request_;

  std::unique_ptr<apps::WebApkManager> web_apk_manager_;

  base::ScopedObservation<arc::ArcIntentHelperBridge,
                          arc::ArcIntentHelperObserver>
      arc_intent_helper_observation_{this};

  base::ScopedObservation<ash::ArcNotificationsHostInitializer,
                          ash::ArcNotificationsHostInitializer::Observer>
      notification_initializer_observation_{this};

  base::ScopedObservation<ash::ArcNotificationManagerBase,
                          ash::ArcNotificationManagerBase::Observer>
      notification_observation_{this};

  AppNotifications app_notifications_;

  base::ScopedObservation<arc::ArcPrivacyItemsBridge,
                          arc::ArcPrivacyItemsBridge::Observer>
      arc_privacy_items_bridge_observation_{this};

  base::ScopedObservation<apps::InstanceRegistry,
                          apps::InstanceRegistry::Observer>
      instance_registry_observation_{this};

  bool settings_app_is_active_ = false;

  bool settings_app_is_disabled_ = false;

  PrefChangeRegistrar local_state_pref_change_registrar_;

  std::set<std::string> blocked_app_ids_;

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

}  // namespace apps

#endif  // CHROME_BROWSER_APPS_APP_SERVICE_PUBLISHERS_ARC_APPS_H_