File: app_publisher.cc

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 (227 lines) | stat: -rw-r--r-- 7,319 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
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
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/apps/app_service/publishers/app_publisher.h"

#include "base/logging.h"
#include "base/notimplemented.h"
#include "base/notreached.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "components/services/app_service/public/cpp/capability_access.h"
#include "components/services/app_service/public/cpp/package_id.h"

#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/apps/app_service/promise_apps/promise_app.h"
#include "extensions/grit/extensions_browser_resources.h"
#endif

namespace apps {

AppPublisher::AppPublisher(AppServiceProxy* proxy) : proxy_(proxy) {
  DCHECK(proxy);
}

AppPublisher::~AppPublisher() = default;

// static
AppPtr AppPublisher::MakeApp(AppType app_type,
                             const std::string& app_id,
                             Readiness readiness,
                             const std::string& name,
                             InstallReason install_reason,
                             InstallSource install_source) {
  auto app = std::make_unique<App>(app_type, app_id);
  app->readiness = readiness;
  app->name = name;
  app->short_name = name;

  app->install_reason = install_reason;
  app->install_source = install_source;

  app->is_platform_app = false;
  app->recommendable = true;
  app->searchable = true;
  app->paused = false;

  return app;
}

void AppPublisher::RegisterPublisher(AppType app_type) {
  proxy_->RegisterPublisher(app_type, this);
}

void AppPublisher::LoadIcon(const std::string& app_id,
                            const IconKey& icon_key,
                            apps::IconType icon_type,
                            int32_t size_hint_in_dip,
                            bool allow_placeholder_icon,
                            LoadIconCallback callback) {
  std::move(callback).Run(std::make_unique<IconValue>());
}

#if BUILDFLAG(IS_CHROMEOS)
int AppPublisher::DefaultIconResourceId() const {
  return IDR_APP_DEFAULT_ICON;
}

void AppPublisher::GetCompressedIconData(const std::string& app_id,
                                         int32_t size_in_dip,
                                         ui::ResourceScaleFactor scale_factor,
                                         LoadIconCallback callback) {
  std::move(callback).Run(std::make_unique<IconValue>());
}
#endif

void AppPublisher::LaunchAppWithFiles(const std::string& app_id,
                                      int32_t event_flags,
                                      LaunchSource launch_source,
                                      std::vector<base::FilePath> file_paths) {
  NOTIMPLEMENTED();
}

void AppPublisher::LaunchAppWithIntent(const std::string& app_id,
                                       int32_t event_flags,
                                       IntentPtr intent,
                                       LaunchSource launch_source,
                                       WindowInfoPtr window_info,
                                       LaunchCallback callback) {
  NOTIMPLEMENTED();
  std::move(callback).Run(LaunchResult(State::kFailed));
}

void AppPublisher::SetPermission(const std::string& app_id,
                                 PermissionPtr permission) {
  NOTIMPLEMENTED();
}

void AppPublisher::Uninstall(const std::string& app_id,
                             UninstallSource uninstall_source,
                             bool clear_site_data,
                             bool report_abuse) {
  LOG(ERROR) << "Uninstall failed, could not remove the app with id " << app_id;
}

void AppPublisher::PauseApp(const std::string& app_id) {
  NOTIMPLEMENTED();
}

void AppPublisher::UnpauseApp(const std::string& app_id) {
  NOTIMPLEMENTED();
}

void AppPublisher::BlockApp(const std::string& app_id) {
  NOTIMPLEMENTED();
}

void AppPublisher::UnblockApp(const std::string& app_id) {
  NOTIMPLEMENTED();
}

void AppPublisher::StopApp(const std::string& app_id) {
  NOTIMPLEMENTED();
}

void AppPublisher::GetMenuModel(const std::string& app_id,
                                MenuType menu_type,
                                int64_t display_id,
                                base::OnceCallback<void(MenuItems)> callback) {
  NOTIMPLEMENTED();
}

void AppPublisher::UpdateAppSize(const std::string& app_id) {
  NOTIMPLEMENTED();
}

void AppPublisher::ExecuteContextMenuCommand(const std::string& app_id,
                                             int command_id,
                                             const std::string& shortcut_id,
                                             int64_t display_id) {
  NOTIMPLEMENTED();
}

void AppPublisher::OpenNativeSettings(const std::string& app_id) {
  NOTIMPLEMENTED();
}

void AppPublisher::SetResizeLocked(const std::string& app_id, bool locked) {
  NOTIMPLEMENTED();
}

void AppPublisher::SetWindowMode(const std::string& app_id,
                                 WindowMode window_mode) {
  NOTIMPLEMENTED();
}

#if BUILDFLAG(IS_CHROMEOS)
void AppPublisher::SetAppLocale(const std::string& app_id,
                                const std::string& locale_tag) {
  NOTIMPLEMENTED();
}

// static
PromiseAppPtr AppPublisher::MakePromiseApp(const PackageId& package_id) {
  return std::make_unique<PromiseApp>(package_id);
}

void AppPublisher::PublishPromiseApp(PromiseAppPtr delta) {
  if (!proxy_) {
    NOTREACHED();
  }
  proxy_->OnPromiseApp(std::move(delta));
}
#endif

void AppPublisher::Publish(AppPtr app) {
  if (!proxy_) {
    NOTREACHED();
  }

  std::vector<AppPtr> apps;
  apps.push_back(std::move(app));
  proxy_->OnApps(std::move(apps), apps::AppType::kUnknown,
                 false /* should_notify_initialized */);
}

void AppPublisher::Publish(std::vector<AppPtr> apps,
                           AppType app_type,
                           bool should_notify_initialized) {
  if (!proxy_) {
    NOTREACHED();
  }
  proxy_->OnApps(std::move(apps), app_type, should_notify_initialized);
}

void AppPublisher::ModifyCapabilityAccess(
    const std::string& app_id,
    std::optional<bool> accessing_camera,
    std::optional<bool> accessing_microphone) {
  if (!accessing_camera.has_value() && !accessing_microphone.has_value()) {
    return;
  }

  std::vector<CapabilityAccessPtr> capability_accesses;
  auto capability_access = std::make_unique<CapabilityAccess>(app_id);
  capability_access->camera = accessing_camera;
  capability_access->microphone = accessing_microphone;
  capability_accesses.push_back(std::move(capability_access));
  proxy_->OnCapabilityAccesses(std::move(capability_accesses));
}

void AppPublisher::ResetCapabilityAccess(AppType app_type) {
  std::set<std::string> apps =
      proxy()->AppCapabilityAccessCache().GetAppsAccessingCapabilities();

  std::vector<CapabilityAccessPtr> capability_accesses;
  for (const std::string& app_id : apps) {
    if (proxy()->AppRegistryCache().GetAppType(app_id) == app_type) {
      auto capability_access = std::make_unique<CapabilityAccess>(app_id);
      capability_access->camera = false;
      capability_access->microphone = false;
      capability_accesses.push_back(std::move(capability_access));
    }
  }
  proxy()->OnCapabilityAccesses(std::move(capability_accesses));
}

}  // namespace apps