blob: 8ce405cc563adda96dc8ea29a9dfd64f7fe12dd9 [file] [log] [blame]
Daniel Murphyec5131b2023-10-11 00:55:151// Copyright 2023 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/web_applications/jobs/link_capturing.h"
6
7#include "base/values.h"
8#include "chrome/browser/web_applications/locks/all_apps_lock.h"
Daniel Murphyf34291b42025-03-10 20:02:219#include "chrome/browser/web_applications/proto/web_app.pb.h"
Daniel Murphyc95b0ef2024-08-03 00:02:3610#include "chrome/browser/web_applications/proto/web_app_install_state.pb.h"
Daniel Murphyec5131b2023-10-11 00:55:1511#include "chrome/browser/web_applications/web_app.h"
12#include "chrome/browser/web_applications/web_app_registrar.h"
13#include "chrome/browser/web_applications/web_app_registry_update.h"
14#include "chrome/browser/web_applications/web_app_sync_bridge.h"
15
16namespace web_app {
17
Daniel Murphy77abe9752024-01-11 20:57:0318void SetAppCapturesSupportedLinksDisableOverlapping(
Daniel Murphyec5131b2023-10-11 00:55:1519 const webapps::AppId& app_id,
20 bool set_to_preferred,
Daniel Murphy77abe9752024-01-11 20:57:0321 AllAppsLock& lock,
22 base::Value::Dict& debug_value) {
Daniel Murphyec5131b2023-10-11 00:55:1523 debug_value.Set("app_id", app_id);
24 debug_value.Set("set_to_preferred", set_to_preferred);
25
Daniel Murphyc95b0ef2024-08-03 00:02:3626 if (!lock.registrar().IsInstallState(
27 app_id, {proto::INSTALLED_WITHOUT_OS_INTEGRATION,
28 proto::INSTALLED_WITH_OS_INTEGRATION})) {
Daniel Murphy7779f7222023-11-06 21:57:3129 debug_value.Set("result", "App not installed.");
Daniel Murphy77abe9752024-01-11 20:57:0330 return;
Daniel Murphy7779f7222023-11-06 21:57:3131 }
Daniel Murphyec5131b2023-10-11 00:55:1532
Daniel Murphy7779f7222023-11-06 21:57:3133 // When disabling, simply disable & exit because this doesn't need to affect
34 // the state of other apps.
35 if (!set_to_preferred) {
36 {
37 ScopedRegistryUpdate update = lock.sync_bridge().BeginUpdate();
38 WebApp* app_to_update = update->UpdateApp(app_id);
39 app_to_update->SetLinkCapturingUserPreference(
Daniel Murphyf34291b42025-03-10 20:02:2140 proto::NAVIGATION_CAPTURING_PREFERENCE_DO_NOT_CAPTURE);
Daniel Murphy7779f7222023-11-06 21:57:3141 }
42 debug_value.Set("app_updated", true);
43 // TODO(b/273830801): Automatically call observers when changes are
44 // committed to the web_app DB (here and below).
45 lock.registrar().NotifyWebAppUserLinkCapturingPreferencesChanged(
46 app_id, set_to_preferred);
Daniel Murphy77abe9752024-01-11 20:57:0347 return;
Daniel Murphy7779f7222023-11-06 21:57:3148 }
49
50 // Whe enabling, any app with the same scope (overlapping) that is explicitly