File: web_app_shortcut.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 (550 lines) | stat: -rw-r--r-- 20,936 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
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
// 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.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "chrome/browser/web_applications/os_integration/web_app_shortcut.h"

#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/bind_post_task.h"
#include "base/task/lazy_thread_pool_task_runner.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/thread_annotations.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "chrome/browser/web_applications/os_integration/file_handling_sub_manager.h"
#include "chrome/browser/web_applications/proto/web_app_os_integration_state.pb.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/browser/web_applications/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_helpers.h"
#include "chrome/browser/web_applications/web_app_icon_manager.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "chrome/common/chrome_constants.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/grit/extensions_browser_resources.h"
#include "skia/ext/image_operations.h"
#include "third_party/protobuf/src/google/protobuf/repeated_field.h"
#include "third_party/re2/src/re2/re2.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_rep_default.h"

#if BUILDFLAG(IS_WIN)
#include "ui/gfx/icon_util.h"
#endif

#if BUILDFLAG(IS_MAC)
#include "chrome/browser/web_applications/os_integration/mac/app_shim_registry.h"
#endif

using content::BrowserThread;

namespace web_app {

namespace {

#if BUILDFLAG(IS_MAC)
const int kDesiredIconSizesForShortcut[] = {16, 32, 128, 256, 512};
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
// Linux supports icons of any size. FreeDesktop Icon Theme Specification states
// that "Minimally you should install a 48x48 icon in the hicolor theme."
const int kDesiredIconSizesForShortcut[] = {16, 32, 48, 128, 256, 512};
#elif BUILDFLAG(IS_WIN)
const int* kDesiredIconSizesForShortcut = IconUtil::kIconDimensions;
#else
const int kDesiredIconSizesForShortcut[] = {32};
#endif

#if BUILDFLAG(IS_WIN)
base::LazyThreadPoolCOMSTATaskRunner g_shortcuts_task_runner =
    LAZY_COM_STA_TASK_RUNNER_INITIALIZER(
        base::TaskTraits({base::MayBlock(), base::TaskPriority::USER_VISIBLE,
                          base::TaskShutdownBehavior::BLOCK_SHUTDOWN}),
        base::SingleThreadTaskRunnerThreadMode::SHARED);
#else
base::LazyThreadPoolSequencedTaskRunner g_shortcuts_task_runner =
    LAZY_THREAD_POOL_SEQUENCED_TASK_RUNNER_INITIALIZER(
        base::TaskTraits({base::MayBlock(), base::TaskPriority::USER_VISIBLE,
                          base::TaskShutdownBehavior::BLOCK_SHUTDOWN}));
#endif

size_t GetNumDesiredIconSizesForShortcut() {
#if BUILDFLAG(IS_WIN)
  return IconUtil::kNumIconDimensions;
#else
  return std::size(kDesiredIconSizesForShortcut);
#endif
}

void CreatePlatformShortcutsAndPostCallback(
    const base::FilePath& shortcut_data_path,
    const ShortcutLocations& creation_locations,
    ShortcutCreationReason creation_reason,
    CreateShortcutsCallback callback,
    std::unique_ptr<ShortcutInfo> shortcut_info) {
  // Ownership of shortcut_info is moved into the callback.
  const ShortcutInfo& shortcut_info_ref = *shortcut_info.get();
  internals::CreatePlatformShortcuts(
      shortcut_data_path, creation_locations, creation_reason,
      shortcut_info_ref,
      base::BindPostTask(
          content::GetUIThreadTaskRunner({}),
          std::move(callback)
              // Ensure that `shortcut_info` is deleted on the UI thread.
              .Then(base::OnceClosure(
                  base::DoNothingWithBoundArgs(std::move(shortcut_info))))));
}

void DeletePlatformShortcutsAndPostCallback(
    const base::FilePath& shortcut_data_path,
    DeleteShortcutsCallback callback,
    const ShortcutInfo& shortcut_info) {
  internals::DeletePlatformShortcuts(shortcut_data_path, shortcut_info,
                                     content::GetUIThreadTaskRunner({}),
                                     std::move(callback));
}

void DeleteMultiProfileShortcutsForAppAndPostCallback(const std::string& app_id,
                                                      ResultCallback callback) {
  internals::DeleteMultiProfileShortcutsForApp(app_id);
  content::GetUIThreadTaskRunner({})->PostTask(
      FROM_HERE, base::BindOnce(std::move(callback), Result::kOk));
}

void UpdatePlatformShortcutsAndPostCallback(
    const base::FilePath& shortcut_data_dir,
    const std::u16string& old_app_title,
    std::optional<ShortcutLocations> locations,
    ResultCallback callback,
    std::unique_ptr<ShortcutInfo> shortcut_info) {
  // Ownership of shortcut_info is moved into the callback.
  const ShortcutInfo& shortcut_info_ref = *shortcut_info.get();
  internals::UpdatePlatformShortcuts(
      std::move(shortcut_data_dir), std::move(old_app_title), locations,
      base::BindPostTask(
          content::GetUIThreadTaskRunner({}),
          std::move(callback)
              // Ensure that `shortcut_info` is deleted on the UI thread.
              .Then(base::OnceClosure(
                  base::DoNothingWithBoundArgs(std::move(shortcut_info))))),
      shortcut_info_ref);
}

std::vector<WebAppShortcutsMenuItemInfo::Icon>
ConvertIconProtoDataToShortcutsMenuIcon(
    const ::google::protobuf::RepeatedPtrField<
        proto::os_state::ShortcutIconData>& shortcut_icon_data) {
  std::vector<WebAppShortcutsMenuItemInfo::Icon> shortcut_menu_item_icons;
  for (const auto& icon_data : shortcut_icon_data) {
    WebAppShortcutsMenuItemInfo::Icon icon;
    icon.square_size_px = icon_data.icon_size();
    // The icon url is set to an empty GURL() because we need this data
    // structure to pass in for OS integration but the url is not used for
    // setting OS integration.
    icon.url = GURL();
    shortcut_menu_item_icons.push_back(std::move(icon));
  }
  return shortcut_menu_item_icons;
}

gfx::ImageFamily PackageIconsIntoImageFamily(
    bool allow_empty,
    std::map<SquareSizePx, SkBitmap> icon_bitmaps) {
  gfx::ImageFamily image_family;
  for (auto& size_and_bitmap : icon_bitmaps) {
    image_family.Add(gfx::ImageSkia(
        gfx::ImageSkiaRep(size_and_bitmap.second, /*scale=*/0.0f)));
  }

  // If the image failed to load, use the standard application icon.
  if (!allow_empty && image_family.empty()) {
    SquareSizePx icon_size_in_px = GetDesiredIconSizesForShortcut().back();
    gfx::ImageSkia image_skia = CreateDefaultApplicationIcon(icon_size_in_px);
    image_family.Add(gfx::Image(image_skia));
  }

  return image_family;
}

std::unique_ptr<ShortcutInfo> SetFavicon(
    std::unique_ptr<ShortcutInfo> shortcut_info,
    IconPurpose purpose,
    bool is_diy_app,
    gfx::ImageFamily image_family) {
  if (purpose == IconPurpose::ANY) {
    shortcut_info->favicon = std::move(image_family);
  } else if (purpose == IconPurpose::MASKABLE) {
    shortcut_info->favicon_maskable = std::move(image_family);
  }
  shortcut_info->is_diy_app = is_diy_app;
  return shortcut_info;
}

}  // namespace

ShortcutInfo::ShortcutInfo() = default;

ShortcutInfo::~ShortcutInfo() {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}

std::unique_ptr<ShortcutInfo> BuildShortcutInfoWithoutFavicon(
    const webapps::AppId& app_id,
    const GURL& start_url,
    const base::FilePath& profile_path,
    const std::string& profile_name,
    const proto::os_state::WebAppOsIntegration& state) {
  auto shortcut_info = std::make_unique<ShortcutInfo>();

  shortcut_info->app_id = app_id;
  shortcut_info->url = start_url;
  DCHECK(state.has_shortcut());
  const proto::os_state::ShortcutDescription& shortcut_state = state.shortcut();
  DCHECK(shortcut_state.has_title());
  shortcut_info->title = base::UTF8ToUTF16(shortcut_state.title());
  DCHECK(shortcut_state.has_description());
  shortcut_info->description = base::UTF8ToUTF16(shortcut_state.description());
  shortcut_info->profile_path = profile_path;
  shortcut_info->profile_name = profile_name;
  shortcut_info->is_multi_profile = true;

  if (state.has_file_handling()) {
    shortcut_info->file_handler_extensions =
        GetFileExtensionsFromFileHandlingProto(state.file_handling());
    shortcut_info->file_handler_mime_types =
        GetMimeTypesFromFileHandlingProto(state.file_handling());
  }

  if (state.has_protocols_handled()) {
    for (const auto& protocol_handler : state.protocols_handled().protocols()) {
      DCHECK(protocol_handler.has_protocol());
      if (protocol_handler.has_protocol() &&
          !protocol_handler.protocol().empty()) {
        shortcut_info->protocol_handlers.emplace(protocol_handler.protocol());
      }
    }
  }

// TODO(crbug.com/40257107): Implement tests on Linux for using shortcuts_menu
// actions.
#if BUILDFLAG(IS_LINUX)
  const std::vector<WebAppShortcutsMenuItemInfo>& shortcuts_menu_item_infos =
      CreateShortcutsMenuItemInfos(state.shortcut_menus());
  DCHECK_LE(shortcuts_menu_item_infos.size(), kMaxApplicationDockMenuItems);
  for (const auto& shortcuts_menu_item_info : shortcuts_menu_item_infos) {
    if (!shortcuts_menu_item_info.name.empty() &&
        !shortcuts_menu_item_info.url.is_empty()) {
      // Generates ID from the name by replacing all characters that are not
      // numbers, letters, or '-' with '-'.
      std::string id = base::UTF16ToUTF8(shortcuts_menu_item_info.name);
      RE2::GlobalReplace(&id, "[^a-zA-Z0-9\\-]", "-");
      shortcut_info->actions.emplace(
          id, base::UTF16ToUTF8(shortcuts_menu_item_info.name),
          shortcuts_menu_item_info.url);
    }
  }
#endif  // BUILDFLAG(IS_LINUX)

#if BUILDFLAG(IS_MAC)
  shortcut_info->handlers_per_profile =
      AppShimRegistry::Get()->GetHandlersForApp(app_id);
#endif

  return shortcut_info;
}

void PopulateFaviconPurposeForShortcutInfo(
    const WebApp* app,
    WebAppIconManager& icon_manager,
    IconPurpose purpose,
    base::OnceCallback<void(std::unique_ptr<ShortcutInfo>)> callback,
    std::unique_ptr<ShortcutInfo> shortcut_info_to_populate) {
  DCHECK(app);

  // Build a common intersection between desired and downloaded icons.
  auto icon_sizes_in_px = base::STLSetIntersection<std::vector<SquareSizePx>>(
      app->downloaded_icon_sizes(purpose), GetDesiredIconSizesForShortcut());

  auto populate_and_return_shortcut_info =
      base::BindOnce(&SetFavicon, std::move(shortcut_info_to_populate), purpose,
                     app->is_diy_app())
          .Then(std::move(callback));

  if (!icon_sizes_in_px.empty()) {
    icon_manager.ReadIcons(
        app->app_id(), purpose, icon_sizes_in_px,
        base::BindOnce(&PackageIconsIntoImageFamily,
                       /*allow_empty=*/purpose != IconPurpose::ANY)
            .Then(std::move(populate_and_return_shortcut_info)));
    return;
  }

  // If there is no single icon at the desired sizes, we will resize what we can
  // get.
  SquareSizePx desired_icon_size = GetDesiredIconSizesForShortcut().back();
  icon_manager.ReadIconAndResize(
      app->app_id(), purpose, desired_icon_size,
      base::BindOnce(&PackageIconsIntoImageFamily,
                     /*allow_empty=*/purpose != IconPurpose::ANY)
          .Then(std::move(populate_and_return_shortcut_info)));
}

void PopulateFaviconForShortcutInfo(
    const WebApp* app,
    WebAppIconManager& icon_manager,
    std::unique_ptr<ShortcutInfo> shortcut_info_to_populate,
    base::OnceCallback<void(std::unique_ptr<ShortcutInfo>)> callback) {
  DCHECK(app);

  auto populate_favicon_maskable = base::BindOnce(
      &PopulateFaviconPurposeForShortcutInfo, app, std::ref(icon_manager),
      IconPurpose::MASKABLE, std::move(callback));

  PopulateFaviconPurposeForShortcutInfo(app, icon_manager, IconPurpose::ANY,
                                        std::move(populate_favicon_maskable),
                                        std::move(shortcut_info_to_populate));
}

std::vector<WebAppShortcutsMenuItemInfo> CreateShortcutsMenuItemInfos(
    const proto::os_state::ShortcutMenus& shortcut_menus) {
  std::vector<WebAppShortcutsMenuItemInfo> shortcut_menu_item_infos;
  for (const auto& shortcut_menu_info : shortcut_menus.shortcut_menu_info()) {
    WebAppShortcutsMenuItemInfo item_info;
    item_info.name = base::UTF8ToUTF16(shortcut_menu_info.shortcut_name());
    item_info.url = GURL(shortcut_menu_info.shortcut_launch_url());
    item_info.any = ConvertIconProtoDataToShortcutsMenuIcon(
        shortcut_menu_info.icon_data_any());
    item_info.maskable = ConvertIconProtoDataToShortcutsMenuIcon(
        shortcut_menu_info.icon_data_maskable());
    item_info.monochrome = ConvertIconProtoDataToShortcutsMenuIcon(
        shortcut_menu_info.icon_data_monochrome());
    shortcut_menu_item_infos.push_back(std::move(item_info));
  }
  return shortcut_menu_item_infos;
}

ShortcutLocations::ShortcutLocations() = default;
ShortcutLocations::~ShortcutLocations() = default;

base::Value ShortcutLocations::ToDebugValue() const {
  base::Value::Dict debug_log;
  debug_log.Set("on_desktop", on_desktop);
  debug_log.Set("in_quick_launch_bar", in_quick_launch_bar);
  debug_log.Set("in_startup", in_startup);
  std::string menu_loc;
  switch (applications_menu_location) {
    case APP_MENU_LOCATION_NONE:
      menu_loc = "LOC_NONE";
      break;
    case APP_MENU_LOCATION_SUBDIR_CHROMEAPPS:
      menu_loc = "SUBDIR_CHROMEAPPS";
      break;
    case APP_MENU_LOCATION_HIDDEN:
      menu_loc = "HIDDEN";
      break;
  }
  debug_log.Set("menu_location", menu_loc);
  return base::Value(std::move(debug_log));
}

ShortcutLocations MergeLocations(
    const ShortcutLocations& user_specified_locations,
    const ShortcutLocations& creation_locations) {
  ShortcutLocations merged_locations;
  merged_locations.on_desktop =
      creation_locations.on_desktop || user_specified_locations.on_desktop;
  merged_locations.in_quick_launch_bar =
      creation_locations.in_quick_launch_bar ||
      user_specified_locations.in_quick_launch_bar;
  merged_locations.in_startup =
      creation_locations.in_startup || user_specified_locations.in_startup;
  return merged_locations;
}

std::string GenerateApplicationNameFromInfo(const ShortcutInfo& shortcut_info) {
  if (shortcut_info.app_id.empty()) {
    return GenerateApplicationNameFromURL(shortcut_info.url);
  }

  return GenerateApplicationNameFromAppId(shortcut_info.app_id);
}

base::FilePath GetOsIntegrationResourcesDirectoryForApp(
    const base::FilePath& profile_path,
    const std::string& app_id,
    const GURL& url) {
  DCHECK(!profile_path.empty());
  base::FilePath app_data_dir(profile_path.Append(chrome::kWebAppDirname));

  if (!app_id.empty()) {
    return app_data_dir.AppendASCII(GenerateApplicationNameFromAppId(app_id));
  }

  std::string host(url.host());
  std::string scheme(url.has_scheme() ? url.scheme() : "http");
  std::string port(url.has_port() ? url.port() : "80");
  std::string scheme_port(scheme + "_" + port);

#if BUILDFLAG(IS_WIN)
  base::FilePath::StringType host_path(base::UTF8ToWide(host));
  base::FilePath::StringType scheme_port_path(base::UTF8ToWide(scheme_port));
#elif BUILDFLAG(IS_POSIX)
  base::FilePath::StringType host_path(host);
  base::FilePath::StringType scheme_port_path(scheme_port);
#else
#error "Unknown platform"
#endif

  return app_data_dir.Append(host_path).Append(scheme_port_path);
}

base::span<const int> GetDesiredIconSizesForShortcut() {
  return base::span<const int>(kDesiredIconSizesForShortcut,
                               GetNumDesiredIconSizesForShortcut());
}

gfx::ImageSkia CreateDefaultApplicationIcon(int size) {
  DCHECK_CURRENTLY_ON(BrowserThread::UI);

  // TODO(crbug.com/40583793): Create web_app_browser_resources.grd with the
  // default app icon. Remove dependency on extensions_browser_resources.h and
  // use IDR_WEB_APP_DEFAULT_ICON here.
  gfx::Image default_icon =
      ui::ResourceBundle::GetSharedInstance().GetImageNamed(
          IDR_APP_DEFAULT_ICON);
  SkBitmap bmp = skia::ImageOperations::Resize(
      *default_icon.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, size,
      size);
  gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bmp);
  // We are on the UI thread, and this image can be used from the FILE thread,
  // for creating shortcut icon files.
  image_skia.MakeThreadSafe();

  return image_skia;
}

namespace internals {

void PostShortcutIOTask(base::OnceCallback<void(const ShortcutInfo&)> task,
                        std::unique_ptr<ShortcutInfo> shortcut_info) {
  DCHECK_CURRENTLY_ON(BrowserThread::UI);

  // Ownership of |shortcut_info| moves to the Reply, which is guaranteed to
  // outlive the const reference.
  const ShortcutInfo& shortcut_info_ref = *shortcut_info;
  GetShortcutIOTaskRunner()->PostTaskAndReply(
      FROM_HERE, base::BindOnce(std::move(task), std::cref(shortcut_info_ref)),
      base::BindOnce(
          [](std::unique_ptr<ShortcutInfo> shortcut_info) {
            // This lambda is to own and delete the shortcut info.
            shortcut_info.reset();
          },
          std::move(shortcut_info)));
}

void PostAsyncShortcutIOTask(
    base::OnceCallback<void(std::unique_ptr<ShortcutInfo>)> task,
    std::unique_ptr<ShortcutInfo> shortcut_info) {
  DCHECK_CURRENTLY_ON(BrowserThread::UI);

  // Ownership of |shortcut_info| is transferred to the task. The task must
  // ensure that it is destroyed on the UI thread.
  GetShortcutIOTaskRunner()->PostTask(
      FROM_HERE, base::BindOnce(std::move(task), std::move(shortcut_info)));
}

void ScheduleCreatePlatformShortcuts(
    const base::FilePath& shortcut_data_path,
    const ShortcutLocations& creation_locations,
    ShortcutCreationReason reason,
    std::unique_ptr<ShortcutInfo> shortcut_info,
    CreateShortcutsCallback callback) {
  DCHECK_CURRENTLY_ON(BrowserThread::UI);

  PostAsyncShortcutIOTask(
      base::BindOnce(&CreatePlatformShortcutsAndPostCallback,
                     shortcut_data_path, creation_locations, reason,
                     std::move(callback)),
      std::move(shortcut_info));
}

void ScheduleDeletePlatformShortcuts(
    const base::FilePath& shortcut_data_path,
    std::unique_ptr<ShortcutInfo> shortcut_info,
    DeleteShortcutsCallback callback) {
  DCHECK_CURRENTLY_ON(BrowserThread::UI);

  PostShortcutIOTask(base::BindOnce(&DeletePlatformShortcutsAndPostCallback,
                                    shortcut_data_path, std::move(callback)),
                     std::move(shortcut_info));
}

void ScheduleDeleteMultiProfileShortcutsForApp(const std::string& app_id,
                                               ResultCallback callback) {
  DCHECK_CURRENTLY_ON(BrowserThread::UI);

  GetShortcutIOTaskRunner()->PostTask(
      FROM_HERE,
      base::BindOnce(&DeleteMultiProfileShortcutsForAppAndPostCallback, app_id,
                     std::move(callback)));
}

void ScheduleUpdatePlatformShortcuts(
    const base::FilePath& shortcut_data_dir,
    const std::u16string& old_app_title,
    std::optional<ShortcutLocations> locations,
    base::OnceCallback<void(Result)> on_complete,
    std::unique_ptr<ShortcutInfo> shortcut_info) {
  DCHECK_CURRENTLY_ON(BrowserThread::UI);

  internals::PostAsyncShortcutIOTask(
      base::BindOnce(&UpdatePlatformShortcutsAndPostCallback,
                     std::move(shortcut_data_dir), std::move(old_app_title),
                     locations, std::move(on_complete)),
      std::move(shortcut_info));
}

scoped_refptr<base::SequencedTaskRunner> GetShortcutIOTaskRunner() {
  return g_shortcuts_task_runner.Get();
}

base::FilePath GetShortcutDataDir(const ShortcutInfo& shortcut_info) {
  return GetOsIntegrationResourcesDirectoryForApp(
      shortcut_info.profile_path, shortcut_info.app_id, shortcut_info.url);
}

#if !BUILDFLAG(IS_MAC)
void DeleteMultiProfileShortcutsForApp(const std::string& app_id) {
  // Multi-profile shortcuts exist only on macOS.
  NOTREACHED();
}
#endif

}  // namespace internals
}  // namespace web_app