File: app_service_proxy_base.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 (699 lines) | stat: -rw-r--r-- 25,048 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
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
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
// 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/app_service_proxy_base.h"

#include <stddef.h>

#include <map>
#include <type_traits>
#include <utility>

#include "base/check.h"
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "chrome/browser/apps/app_service/app_icon_source.h"
#include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/apps/app_service/browser_app_launcher.h"
#include "chrome/browser/apps/app_service/metrics/app_service_metrics.h"
#include "chrome/browser/apps/app_service/publishers/app_publisher.h"
#include "chrome/browser/profiles/profile.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/app_update.h"
#include "components/services/app_service/public/cpp/features.h"
#include "components/services/app_service/public/cpp/icon_effects.h"
#include "components/services/app_service/public/cpp/intent.h"
#include "components/services/app_service/public/cpp/intent_filter.h"
#include "components/services/app_service/public/cpp/intent_filter_util.h"
#include "components/services/app_service/public/cpp/intent_util.h"
#include "components/services/app_service/public/cpp/preferred_app.h"
#include "components/services/app_service/public/cpp/types_util.h"
#include "content/public/browser/url_data_source.h"
#include "url/gurl.h"

namespace apps {

class PreferredAppsListHandle;

namespace {

// Utility struct used in GetAppsForIntent.
struct IndexAndGeneric {
  size_t index;
  bool is_generic;
};

std::string GetActivityLabel(const IntentFilterPtr& filter,
                             const AppUpdate& update) {
  if (filter->activity_label.has_value() && !filter->activity_label->empty()) {
    return filter->activity_label.value();
  } else {
    return update.Name();
  }
}

}  // anonymous namespace

AppServiceProxyBase::AppInnerIconLoader::AppInnerIconLoader(
    AppServiceProxyBase* host)
    : host_(host), overriding_icon_loader_for_testing_(nullptr) {}

std::optional<IconKey> AppServiceProxyBase::AppInnerIconLoader::GetIconKey(
    const std::string& id) {
  if (overriding_icon_loader_for_testing_) {
    return overriding_icon_loader_for_testing_->GetIconKey(id);
  }

  std::optional<IconKey> icon_key;
  host_->app_registry_cache_.ForOneApp(
      id,
      [&icon_key](const AppUpdate& update) { icon_key = update.IconKey(); });
  return icon_key;
}

std::unique_ptr<IconLoader::Releaser>
AppServiceProxyBase::AppInnerIconLoader::LoadIconFromIconKey(
    const std::string& id,
    const IconKey& icon_key,
    IconType icon_type,
    int32_t size_hint_in_dip,
    bool allow_placeholder_icon,
    apps::LoadIconCallback callback) {
  if (overriding_icon_loader_for_testing_) {
    return overriding_icon_loader_for_testing_->LoadIconFromIconKey(
        id, icon_key, icon_type, size_hint_in_dip, allow_placeholder_icon,
        std::move(callback));
  }

  AppType app_type = host_->AppRegistryCache().GetAppType(id);
  if (host_->ShouldReadIcons(app_type)) {
    host_->ReadIcons(app_type, id, size_hint_in_dip, icon_key.Clone(),
                     icon_type, std::move(callback));
    return nullptr;
  }

  auto* publisher = host_->GetPublisher(app_type);
  if (!publisher) {
    LOG(WARNING) << "No publisher for requested icon";
    std::move(callback).Run(std::make_unique<IconValue>());
    return nullptr;
  }

  RecordIconLoadMethodMetrics(IconLoadingMethod::kViaNonMojomCall);
  publisher->LoadIcon(id, icon_key, icon_type, size_hint_in_dip,
                      allow_placeholder_icon, std::move(callback));
  return nullptr;
}

AppServiceProxyBase::AppServiceProxyBase(Profile* profile)
    : app_inner_icon_loader_(this),
      app_icon_coalescer_(&app_inner_icon_loader_),
      app_outer_icon_loader_(&app_icon_coalescer_,
                             IconCache::GarbageCollectionPolicy::kEager),
      profile_(profile) {
  preferred_apps_impl_ = std::make_unique<apps::PreferredAppsImpl>(
      this, profile ? profile->GetPath() : base::FilePath());
}

AppServiceProxyBase::~AppServiceProxyBase() = default;

void AppServiceProxyBase::ReinitializeForTesting(
    Profile* profile,
    base::OnceClosure read_completed_for_testing,
    base::OnceClosure write_completed_for_testing) {
  // Some test code creates a profile and profile-linked services, like the App
  // Service, before the profile is fully initialized. Such tests can call this
  // after full profile initialization to ensure the App Service implementation
  // has all of profile state it needs.
  profile_ = profile;
  is_using_testing_profile_ = true;
  app_registry_cache_.ReinitializeForTesting();  // IN-TEST

  preferred_apps_impl_ = std::make_unique<apps::PreferredAppsImpl>(
      this, profile ? profile->GetPath() : base::FilePath(),
      std::move(read_completed_for_testing),
      std::move(write_completed_for_testing));

  publishers_.clear();
  Initialize();
}

bool AppServiceProxyBase::IsValidProfile() {
  if (!profile_) {
    return false;
  }

  // We only initialize the App Service for regular or guest profiles. Non-guest
  // off-the-record profiles do not get an instance.
  if (profile_->IsOffTheRecord() && !profile_->IsGuestSession()) {
    return false;
  }

  return true;
}

void AppServiceProxyBase::Initialize() {
  if (!IsValidProfile()) {
    return;
  }

  browser_app_launcher_ = std::make_unique<apps::BrowserAppLauncher>(profile_);

  // Make the chrome://app-icon/ resource available.
  content::URLDataSource::Add(profile_,
                              std::make_unique<apps::AppIconSource>(profile_));
}

AppPublisher* AppServiceProxyBase::GetPublisher(AppType app_type) {
  auto it = publishers_.find(app_type);
  return it == publishers_.end() ? nullptr : it->second;
}

apps::AppRegistryCache& AppServiceProxyBase::AppRegistryCache() {
  return app_registry_cache_;
}

apps::AppCapabilityAccessCache&
AppServiceProxyBase::AppCapabilityAccessCache() {
  return app_capability_access_cache_;
}

BrowserAppLauncher* AppServiceProxyBase::BrowserAppLauncher() {
  return browser_app_launcher_.get();
}

apps::PreferredAppsListHandle& AppServiceProxyBase::PreferredAppsList() {
  return preferred_apps_impl_->preferred_apps_list();
}

void AppServiceProxyBase::RegisterPublisher(AppType app_type,
                                            AppPublisher* publisher) {
  publishers_[app_type] = publisher;
}

void AppServiceProxyBase::UnregisterPublisher(AppType app_type) {
  publishers_.erase(app_type);
}

void AppServiceProxyBase::OnSupportedLinksPreferenceChanged(
    const std::string& app_id,
    bool open_in_app) {
  AppType app_type = AppRegistryCache().GetAppType(app_id);
  if (!base::Contains(publishers_, app_type)) {
    return;
  }

  publishers_[app_type]->OnSupportedLinksPreferenceChanged(app_id, open_in_app);
}

std::unique_ptr<IconLoader::Releaser> AppServiceProxyBase::LoadIcon(
    const std::string& app_id,
    const IconType& icon_type,
    int32_t size_hint_in_dip,
    bool allow_placeholder_icon,
    apps::LoadIconCallback callback) {
  return app_icon_loader()->LoadIcon(app_id, icon_type, size_hint_in_dip,
                                     allow_placeholder_icon,
                                     std::move(callback));
}

uint32_t AppServiceProxyBase::GetIconEffects(const std::string& app_id) {
  std::optional<apps::IconKey> icon_key = app_icon_loader()->GetIconKey(app_id);
  if (!icon_key.has_value()) {
    return IconEffects::kNone;
  }
  return icon_key->icon_effects;
}

std::unique_ptr<apps::IconLoader::Releaser>
AppServiceProxyBase::LoadIconWithIconEffects(const std::string& app_id,
                                             uint32_t icon_effects,
                                             IconType icon_type,
                                             int32_t size_hint_in_dip,
                                             bool allow_placeholder_icon,
                                             LoadIconCallback callback) {
  std::optional<apps::IconKey> icon_key = app_icon_loader()->GetIconKey(app_id);
  if (!icon_key.has_value()) {
    std::move(callback).Run(std::make_unique<IconValue>());
    return nullptr;
  }

  icon_key->icon_effects = icon_effects;

  return app_icon_loader()->LoadIconFromIconKey(
      app_id, icon_key.value(), icon_type, size_hint_in_dip,
      allow_placeholder_icon, std::move(callback));
}

void AppServiceProxyBase::Launch(const std::string& app_id,
                                 int32_t event_flags,
                                 apps::LaunchSource launch_source,
                                 apps::WindowInfoPtr window_info) {
  app_registry_cache_.ForOneApp(
      app_id, [this, event_flags, launch_source,
               &window_info](const apps::AppUpdate& update) {
        auto* publisher = GetPublisher(update.AppType());
        if (!publisher) {
          return;
        }

        if (MaybeShowLaunchPreventionDialog(update)) {
          return;
        }

        RecordAppLaunch(update.AppId(), launch_source);
        RecordAppPlatformMetrics(profile_, update, launch_source,
                                 apps::LaunchContainer::kLaunchContainerNone);

        publisher->Launch(update.AppId(), event_flags, launch_source,
                          std::move(window_info));

        PerformPostLaunchTasks(launch_source);
      });
}

void AppServiceProxyBase::LaunchAppWithFiles(
    const std::string& app_id,
    int32_t event_flags,
    LaunchSource launch_source,
    std::vector<base::FilePath> file_paths) {
  app_registry_cache_.ForOneApp(
      app_id, [this, event_flags, launch_source,
               &file_paths](const apps::AppUpdate& update) {
        auto* publisher = GetPublisher(update.AppType());
        if (!publisher) {
          return;
        }

        if (MaybeShowLaunchPreventionDialog(update)) {
          return;
        }

        RecordAppPlatformMetrics(profile_, update, launch_source,
                                 LaunchContainer::kLaunchContainerNone);

        // TODO(crbug/1117655): File manager records metrics for apps it
        // launched. So we only record launches from other places. We should
        // eventually move those metrics here, after AppService supports all
        // app types launched by file manager.
        if (launch_source != LaunchSource::kFromFileManager) {
          RecordAppLaunch(update.AppId(), launch_source);
        }

        publisher->LaunchAppWithFiles(update.AppId(), event_flags,
                                      launch_source, std::move(file_paths));

        PerformPostLaunchTasks(launch_source);
      });
}

void AppServiceProxyBase::LaunchAppWithIntent(const std::string& app_id,
                                              int32_t event_flags,
                                              IntentPtr intent,
                                              LaunchSource launch_source,
                                              WindowInfoPtr window_info,
                                              LaunchCallback callback) {
  CHECK(intent);
  app_registry_cache_.ForOneApp(app_id, [this, event_flags, &intent,
                                         launch_source, &window_info,
                                         callback = std::move(callback)](
                                            const AppUpdate& update) mutable {
    auto* publisher = GetPublisher(update.AppType());
    if (!publisher) {
      std::move(callback).Run(LaunchResult(State::kFailed));
      return;
    }

    if (MaybeShowLaunchPreventionDialog(update)) {
      std::move(callback).Run(LaunchResult(State::kFailed));
      return;
    }

    // TODO(crbug/1117655): File manager records metrics for apps it
    // launched. So we only record launches from other places. We should
    // eventually move those metrics here, after AppService supports all
    // app types launched by file manager.
    if (launch_source != LaunchSource::kFromFileManager) {
      RecordAppLaunch(update.AppId(), launch_source);
    }
    RecordAppPlatformMetrics(profile_, update, launch_source,
                             LaunchContainer::kLaunchContainerNone);

    publisher->LaunchAppWithIntent(update.AppId(), event_flags,
                                   std::move(intent), launch_source,
                                   std::move(window_info), std::move(callback));

    PerformPostLaunchTasks(launch_source);
  });
}

void AppServiceProxyBase::LaunchAppWithUrl(const std::string& app_id,
                                           int32_t event_flags,
                                           GURL url,
                                           LaunchSource launch_source,
                                           WindowInfoPtr window_info,
                                           LaunchCallback callback) {
  LaunchAppWithIntent(
      app_id, event_flags,
      std::make_unique<apps::Intent>(apps_util::kIntentActionView, url),
      launch_source, std::move(window_info), std::move(callback));
}

void AppServiceProxyBase::LaunchAppWithParams(AppLaunchParams&& params,
                                              LaunchCallback callback) {
  auto app_type = app_registry_cache_.GetAppType(params.app_id);
  auto* publisher = GetPublisher(app_type);
  if (!publisher) {
    std::move(callback).Run(LaunchResult());
    return;
  }

  app_registry_cache_.ForOneApp(
      params.app_id,
      [this, &params, &callback, &publisher](const apps::AppUpdate& update) {
        if (MaybeShowLaunchPreventionDialog(update)) {
          std::move(callback).Run(LaunchResult());
          return;
        }
        auto launch_source = params.launch_source;
        // TODO(crbug/1117655): File manager records metrics for apps it
        // launched. So we only record launches from other places. We should
        // eventually move those metrics here, after AppService supports all
        // app types launched by file manager.
        if (launch_source != apps::LaunchSource::kFromFileManager) {
          RecordAppLaunch(update.AppId(), launch_source);
        }

        RecordAppPlatformMetrics(profile_, update, launch_source,
                                 params.container);

        publisher->LaunchAppWithParams(
            std::move(params),
            base::BindOnce(&AppServiceProxyBase::OnLaunched,
                           weak_factory_.GetWeakPtr(), std::move(callback)));

        PerformPostLaunchTasks(launch_source);
      });
}

void AppServiceProxyBase::SetPermission(const std::string& app_id,
                                        PermissionPtr permission) {
  app_registry_cache_.ForOneApp(
      app_id, [this, &permission](const apps::AppUpdate& update) {
        auto* publisher = GetPublisher(update.AppType());
        if (!publisher) {
          return;
        }

        publisher->SetPermission(update.AppId(), std::move(permission));
      });
}

void AppServiceProxyBase::UninstallSilently(const std::string& app_id,
                                            UninstallSource uninstall_source) {
  auto app_type = app_registry_cache_.GetAppType(app_id);
  auto* publisher = GetPublisher(app_type);
  if (!publisher) {
    return;
  }
  publisher->Uninstall(app_id, uninstall_source,
                       /*clear_site_data=*/false, /*report_abuse=*/false);
  PerformPostUninstallTasks(app_type, app_id, uninstall_source);
}

void AppServiceProxyBase::StopApp(const std::string& app_id) {
  auto* publisher = GetPublisher(app_registry_cache_.GetAppType(app_id));
  if (publisher) {
    publisher->StopApp(app_id);
  }
}

void AppServiceProxyBase::GetMenuModel(
    const std::string& app_id,
    MenuType menu_type,
    int64_t display_id,
    base::OnceCallback<void(MenuItems)> callback) {
  auto* publisher = GetPublisher(app_registry_cache_.GetAppType(app_id));
  if (publisher) {
    publisher->GetMenuModel(app_id, menu_type, display_id, std::move(callback));
  } else {
    std::move(callback).Run(MenuItems());
  }
}

void AppServiceProxyBase::UpdateAppSize(const std::string& app_id) {
  auto app_type = app_registry_cache_.GetAppType(app_id);
  auto* publisher = GetPublisher(app_type);
  if (publisher) {
    publisher->UpdateAppSize(app_id);
  }
  return;
}

void AppServiceProxyBase::ExecuteContextMenuCommand(
    const std::string& app_id,
    int command_id,
    const std::string& shortcut_id,
    int64_t display_id) {
  auto* publisher = GetPublisher(app_registry_cache_.GetAppType(app_id));
  if (publisher) {
    publisher->ExecuteContextMenuCommand(app_id, command_id, shortcut_id,
                                         display_id);
  }
  return;
}

void AppServiceProxyBase::OpenNativeSettings(const std::string& app_id) {
  auto* publisher = GetPublisher(app_registry_cache_.GetAppType(app_id));
  if (publisher) {
    publisher->OpenNativeSettings(app_id);
  }
}

apps::IconLoader* AppServiceProxyBase::OverrideInnerIconLoaderForTesting(
    apps::IconLoader* icon_loader) {
  apps::IconLoader* old =
      app_inner_icon_loader_.overriding_icon_loader_for_testing_;
  app_inner_icon_loader_.overriding_icon_loader_for_testing_ = icon_loader;
  return old;
}

std::vector<std::string> AppServiceProxyBase::GetAppIdsForUrl(
    const GURL& url,
    bool exclude_browsers,
    bool exclude_browser_tab_apps) {
  auto intent_launch_info = GetAppsForIntent(
      std::make_unique<apps::Intent>(apps_util::kIntentActionView, url),
      exclude_browsers, exclude_browser_tab_apps);
  std::vector<std::string> app_ids;
  for (auto& entry : intent_launch_info) {
    app_ids.push_back(std::move(entry.app_id));
  }
  return app_ids;
}

std::vector<IntentLaunchInfo> AppServiceProxyBase::GetAppsForIntent(
    const apps::IntentPtr& intent,
    bool exclude_browsers,
    bool exclude_browser_tab_apps) {
  std::vector<IntentLaunchInfo> intent_launch_info;
  if (!intent || intent->OnlyShareToDrive() || !intent->IsIntentValid()) {
    return intent_launch_info;
  }

  app_registry_cache_.ForEachApp([this, &intent_launch_info, &intent,
                                  &exclude_browsers, &exclude_browser_tab_apps](
                                     const apps::AppUpdate& update) {
    if (update.Readiness() != apps::Readiness::kReady &&
        update.Readiness() != apps::Readiness::kDisabledByPolicy) {
      // We consider apps disabled by policy to be ready as they cause URL
      // loads to be blocked.
      return;
    }
    if (!update.HandlesIntents().value_or(false)) {
      return;
    }
    if (ShouldExcludeBrowserTabApps(exclude_browser_tab_apps,
                                    update.WindowMode())) {
      return;
    }
    // |activity_label| -> {index, is_generic}
    std::map<std::string, IndexAndGeneric> best_handler_map;
    bool is_file_handling_intent = !intent->files.empty();
    const apps::IntentFilters& filters = update.IntentFilters();
    for (size_t i = 0; i < filters.size(); i++) {
      const IntentFilterPtr& filter = filters[i];
      DCHECK(filter);
      if (exclude_browsers && filter->IsBrowserFilter()) {
        continue;
      }
      if (intent->MatchFilter(filter)) {
        // Return the first non-generic match if it exists, otherwise the
        // first generic match.
        bool generic = false;
        if (is_file_handling_intent) {
          generic = apps_util::IsGenericFileHandler(intent, filter);
        }
        std::string activity_label = GetActivityLabel(filter, update);
        // Replace the best handler if it is generic and we have a non-generic
        // one.
        auto it = best_handler_map.find(activity_label);
        if (it == best_handler_map.end() ||
            (it->second.is_generic && !generic)) {
          best_handler_map[activity_label] = IndexAndGeneric{i, generic};
        }
      }
    }
    for (const auto& handler_entry : best_handler_map) {
      const IntentFilterPtr& filter = filters[handler_entry.second.index];
      IntentLaunchInfo entry = CreateIntentLaunchInfo(intent, filter, update);
      intent_launch_info.push_back(entry);
    }
  });
  return intent_launch_info;
}

bool AppServiceProxyBase::ShouldExcludeBrowserTabApps(
    bool exclude_browser_tab_apps,
    WindowMode window_mode) {
  return (exclude_browser_tab_apps && window_mode == WindowMode::kBrowser);
}

std::vector<IntentLaunchInfo> AppServiceProxyBase::GetAppsForFiles(
    std::vector<apps::IntentFilePtr> files) {
  return GetAppsForIntent(std::make_unique<apps::Intent>(
                              apps_util::kIntentActionView, std::move(files)),
                          false, false);
}

void AppServiceProxyBase::SetSupportedLinksPreference(
    const std::string& app_id) {
  IntentFilters filters;
  AppRegistryCache().ForOneApp(
      app_id, [&app_id, &filters](const AppUpdate& app) {
        for (auto& filter : app.IntentFilters()) {
          if (apps_util::IsSupportedLinkForApp(app_id, filter)) {
            filters.push_back(std::move(filter));
          }
        }
      });

  SetSupportedLinksPreference(app_id, std::move(filters));
}

void AppServiceProxyBase::SetSupportedLinksPreference(
    const std::string& app_id,
    IntentFilters all_link_filters) {
  DCHECK(!app_id.empty());

  preferred_apps_impl_->SetSupportedLinksPreference(
      app_id, std::move(all_link_filters));
}

void AppServiceProxyBase::RemoveSupportedLinksPreference(
    const std::string& app_id) {
  DCHECK(!app_id.empty());

  preferred_apps_impl_->RemoveSupportedLinksPreference(app_id);
}

void AppServiceProxyBase::SetWindowMode(const std::string& app_id,
                                        WindowMode window_mode) {
  auto* publisher = GetPublisher(app_registry_cache_.GetAppType(app_id));
  if (publisher) {
    publisher->SetWindowMode(app_id, window_mode);
  }
}

void AppServiceProxyBase::OnApps(std::vector<AppPtr> deltas,
                                 AppType app_type,
                                 bool should_notify_initialized) {
  for (const auto& delta : deltas) {
    if (delta->readiness != Readiness::kUnknown &&
        !apps_util::IsInstalled(delta->readiness)) {
      preferred_apps_impl_->RemovePreferredApp(delta->app_id);
    }
  }

  app_registry_cache_.OnApps(std::move(deltas), app_type,
                             should_notify_initialized);
}

void AppServiceProxyBase::OnCapabilityAccesses(
    std::vector<CapabilityAccessPtr> deltas) {
  app_capability_access_cache_.OnCapabilityAccesses(std::move(deltas));
}

IntentFilterPtr AppServiceProxyBase::FindBestMatchingFilter(
    const IntentPtr& intent) {
  IntentFilterPtr best_matching_intent_filter;
  if (!intent) {
    return best_matching_intent_filter;
  }

  int best_match_level = static_cast<int>(IntentFilterMatchLevel::kNone);
  app_registry_cache_.ForEachApp(
      [&intent, &best_match_level,
       &best_matching_intent_filter](const apps::AppUpdate& update) {
        for (auto& filter : update.IntentFilters()) {
          if (!intent->MatchFilter(filter)) {
            continue;
          }
          auto match_level = filter->GetFilterMatchLevel();
          if (match_level <= best_match_level) {
            continue;
          }
          best_matching_intent_filter = std::move(filter);
          best_match_level = match_level;
        }
      });
  return best_matching_intent_filter;
}

void AppServiceProxyBase::PerformPostLaunchTasks(
    apps::LaunchSource launch_source) {}

void AppServiceProxyBase::RecordAppPlatformMetrics(
    Profile* profile,
    const apps::AppUpdate& update,
    apps::LaunchSource launch_source,
    apps::LaunchContainer container) {}

void AppServiceProxyBase::PerformPostUninstallTasks(
    apps::AppType app_type,
    const std::string& app_id,
    UninstallSource uninstall_source) {}

void AppServiceProxyBase::OnLaunched(LaunchCallback callback,
                                     LaunchResult&& launch_result) {
  std::move(callback).Run(std::move(launch_result));
}

bool AppServiceProxyBase::ShouldReadIcons(AppType app_type) {
  return false;
}

IntentLaunchInfo AppServiceProxyBase::CreateIntentLaunchInfo(
    const apps::IntentPtr& intent,
    const apps::IntentFilterPtr& filter,
    const apps::AppUpdate& update) {
  IntentLaunchInfo entry;
  entry.app_id = update.AppId();
  entry.activity_label = GetActivityLabel(filter, update);
  entry.activity_name = filter->activity_name.value_or("");
  entry.is_generic_file_handler =
      apps_util::IsGenericFileHandler(intent, filter);
  entry.is_file_extension_match = filter->IsFileExtensionsFilter();
  return entry;
}

IntentLaunchInfo::IntentLaunchInfo() = default;
IntentLaunchInfo::~IntentLaunchInfo() = default;
IntentLaunchInfo::IntentLaunchInfo(const IntentLaunchInfo& other) = default;

}  // namespace apps