Daniel Murphy | ec5131b | 2023-10-11 00:55:15 | [diff] [blame] | 1 | // 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 Murphy | f34291b4 | 2025-03-10 20:02:21 | [diff] [blame] | 9 | #include "chrome/browser/web_applications/proto/web_app.pb.h" |
Daniel Murphy | c95b0ef | 2024-08-03 00:02:36 | [diff] [blame] | 10 | #include "chrome/browser/web_applications/proto/web_app_install_state.pb.h" |
Daniel Murphy | ec5131b | 2023-10-11 00:55:15 | [diff] [blame] | 11 | #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 | |
| 16 | namespace web_app { |
| 17 | |
Daniel Murphy | 77abe975 | 2024-01-11 20:57:03 | [diff] [blame] | 18 | void SetAppCapturesSupportedLinksDisableOverlapping( |
Daniel Murphy | ec5131b | 2023-10-11 00:55:15 | [diff] [blame] | 19 | const webapps::AppId& app_id, |
| 20 | bool set_to_preferred, |
Daniel Murphy | 77abe975 | 2024-01-11 20:57:03 | [diff] [blame] | 21 | AllAppsLock& lock, |
| 22 | base::Value::Dict& debug_value) { |
Daniel Murphy | ec5131b | 2023-10-11 00:55:15 | [diff] [blame] | 23 | debug_value.Set("app_id", app_id); |
| 24 | debug_value.Set("set_to_preferred", set_to_preferred); |
| 25 | |
Daniel Murphy | c95b0ef | 2024-08-03 00:02:36 | [diff] [blame] | 26 | if (!lock.registrar().IsInstallState( |
| 27 | app_id, {proto::INSTALLED_WITHOUT_OS_INTEGRATION, |
| 28 | proto::INSTALLED_WITH_OS_INTEGRATION})) { |
Daniel Murphy | 7779f722 | 2023-11-06 21:57:31 | [diff] [blame] | 29 | debug_value.Set("result", "App not installed."); |
Daniel Murphy | 77abe975 | 2024-01-11 20:57:03 | [diff] [blame] | 30 | return; |
Daniel Murphy | 7779f722 | 2023-11-06 21:57:31 | [diff] [blame] | 31 | } |
Daniel Murphy | ec5131b | 2023-10-11 00:55:15 | [diff] [blame] | 32 | |
Daniel Murphy | 7779f722 | 2023-11-06 21:57:31 | [diff] [blame] | 33 | // 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 Murphy | f34291b4 | 2025-03-10 20:02:21 | [diff] [blame] | 40 | proto::NAVIGATION_CAPTURING_PREFERENCE_DO_NOT_CAPTURE); |
Daniel Murphy | 7779f722 | 2023-11-06 21:57:31 | [diff] [blame] | 41 | } |
| 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 Murphy | 77abe975 | 2024-01-11 20:57:03 | [diff] [blame] | 47 | return; |
Daniel Murphy | 7779f722 | 2023-11-06 21:57:31 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | // Whe enabling, any app with the same scope (overlapping) that is explicitly |
|
|