Nigel Tao | c5d6bcb | 2018-07-25 04:57:42 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Song Fangzhen | 08553c78 | 2021-08-05 05:00:11 | [diff] [blame] | 5 | #include "chrome/browser/web_applications/externally_managed_app_manager.h" |
Nigel Tao | c5d6bcb | 2018-07-25 04:57:42 | [diff] [blame] | 6 | |
Christopher Lam | a45ea6d | 2019-07-08 07:22:05 | [diff] [blame] | 7 | #include <map> |
Giovanni Ortuño Urquidi | b4839fb | 2018-08-24 10:36:57 | [diff] [blame] | 8 | #include <memory> |
| 9 | #include <utility> |
Dibyajyoti Pal | d251e0e | 2022-06-13 15:44:32 | [diff] [blame] | 10 | #include <vector> |
Giovanni Ortuño Urquidi | b4839fb | 2018-08-24 10:36:57 | [diff] [blame] | 11 | |
danakj | db9ae794 | 2020-11-11 16:01:35 | [diff] [blame] | 12 | #include "base/callback_helpers.h" |
Jan Wilken Dörrie | bf97d44 | 2020-12-09 19:01:58 | [diff] [blame] | 13 | #include "base/containers/contains.h" |
Peter Kasting | 4703b5b | 2022-08-31 08:15:58 | [diff] [blame] | 14 | #include "base/ranges/algorithm.h" |
Lei Zhang | e11edbe0 | 2021-06-25 18:30:22 | [diff] [blame] | 15 | #include "base/stl_util.h" |
Christopher Lam | 8b4142d | 2019-04-08 06:54:42 | [diff] [blame] | 16 | #include "base/threading/thread_task_runner_handle.h" |
Dibyajyoti Pal | d251e0e | 2022-06-13 15:44:32 | [diff] [blame] | 17 | #include "build/chromeos_buildflags.h" |
Daniel Murphy | 19a34bf | 2022-04-07 15:29:36 | [diff] [blame] | 18 | #include "chrome/browser/web_applications/web_app_install_utils.h" |
Song Fangzhen | ed83c14 | 2021-07-13 03:21:44 | [diff] [blame] | 19 | #include "chrome/browser/web_applications/web_app_registrar.h" |
Alexander Bolodurin | 48a8d4e | 2022-02-16 03:06:18 | [diff] [blame] | 20 | #include "components/webapps/browser/install_result_code.h" |
Nigel Tao | 02f334fe | 2018-09-20 01:28:29 | [diff] [blame] | 21 | |
Dibyajyoti Pal | d251e0e | 2022-06-13 15:44:32 | [diff] [blame] | 22 | #if BUILDFLAG(IS_CHROMEOS) |
| 23 | #include "base/containers/cxx20_erase.h" |
| 24 | #endif |
| 25 | |
Nigel Tao | c5d6bcb | 2018-07-25 04:57:42 | [diff] [blame] | 26 | namespace web_app { |
| 27 | |
Alan Cutter | f29ca273 | 2021-12-06 06:07:25 | [diff] [blame] | 28 | ExternallyManagedAppManager::InstallResult::InstallResult() = default; |
| 29 | |
| 30 | ExternallyManagedAppManager::InstallResult::InstallResult( |
Alexander Bolodurin | 48a8d4e | 2022-02-16 03:06:18 | [diff] [blame] | 31 | webapps::InstallResultCode code, |
Alan Cutter | f29ca273 | 2021-12-06 06:07:25 | [diff] [blame] | 32 | absl::optional<AppId> app_id, |
| 33 | bool did_uninstall_and_replace) |
| 34 | : code(code), |
| 35 | app_id(std::move(app_id)), |
| 36 | did_uninstall_and_replace(did_uninstall_and_replace) {} |
| 37 | |
| 38 | ExternallyManagedAppManager::InstallResult::InstallResult( |
| 39 | const InstallResult&) = default; |
| 40 | |
| 41 | ExternallyManagedAppManager::InstallResult::~InstallResult() = default; |
| 42 | |
Daniel Murphy | 6294817d | 2021-04-13 22:28:13 | [diff] [blame] | 43 | bool ExternallyManagedAppManager::InstallResult::operator==( |
Alan Cutter | 2ce91fc | 2020-12-02 03:56:41 | [diff] [blame] | 44 | const InstallResult& other) const { |
Alan Cutter | f29ca273 | 2021-12-06 06:07:25 | [diff] [blame] | 45 | return std::tie(code, app_id, did_uninstall_and_replace) == |
| 46 | std::tie(other.code, other.app_id, other.did_uninstall_and_replace); |
Alan Cutter | 2ce91fc | 2020-12-02 03:56:41 | [diff] [blame] | 47 | } |
| 48 | |
Daniel Murphy | 6294817d | 2021-04-13 22:28:13 | [diff] [blame] | 49 | ExternallyManagedAppManager::SynchronizeRequest::SynchronizeRequest( |
Christopher Lam | 8b4142d | 2019-04-08 06:54:42 | [diff] [blame] | 50 | SynchronizeCallback callback, |
Daniel Murphy | 527765a5 | 2021-09-13 19:09:21 | [diff] [blame] | 51 | std::vector<ExternalInstallOptions> pending_installs, |
| 52 | int remaining_uninstall_requests) |
| 53 | : callback(std::move(callback)), |
| 54 | remaining_install_requests(pending_installs.size()), |
| 55 | pending_installs(std::move(pending_installs)), |
| 56 | remaining_uninstall_requests(remaining_uninstall_requests) {} |
Christopher Lam | 8b4142d | 2019-04-08 06:54:42 | [diff] [blame] | 57 | |
Daniel Murphy | 6294817d | 2021-04-13 22:28:13 | [diff] [blame] | 58 | ExternallyManagedAppManager::SynchronizeRequest::~SynchronizeRequest() = |
| 59 | default; |
Christopher Lam | 8b4142d | 2019-04-08 06:54:42 | [diff] [blame] | 60 | |
Daniel Murphy | 6294817d | 2021-04-13 22:28:13 | [diff] [blame] | 61 | ExternallyManagedAppManager::SynchronizeRequest& |
| 62 | ExternallyManagedAppManager::SynchronizeRequest::operator=( |
| 63 | ExternallyManagedAppManager::SynchronizeRequest&&) = default; |
Christopher Lam | 8b4142d | 2019-04-08 06:54:42 | [diff] [blame] | 64 | |
Daniel Murphy | 6294817d | 2021-04-13 22:28:13 | [diff] [blame] | 65 | ExternallyManagedAppManager::SynchronizeRequest::SynchronizeRequest( |
Christopher Lam | 8b4142d | 2019-04-08 06:54:42 | [diff] [blame] | 66 | SynchronizeRequest&& other) = default; |
| 67 | |
Daniel Murphy | 6294817d | 2021-04-13 22:28:13 | [diff] [blame] | 68 | ExternallyManagedAppManager::ExternallyManagedAppManager() = default; |
Nigel Tao | c5d6bcb | 2018-07-25 04:57:42 | [diff] [blame] | 69 | |
Daniel Murphy | 6294817d | 2021-04-13 22:28:13 | [diff] [blame] | 70 | ExternallyManagedAppManager::~ExternallyManagedAppManager() { |
Eric Willigers | 31c682b2 | 2019-08-27 03:57:40 | [diff] [blame] | 71 | DCHECK(!registration_callback_); |
| 72 | } |
Nigel Tao | c5d6bcb | 2018-07-25 04:57:42 | [diff] [blame] | 73 | |
Daniel Murphy | 6294817d | 2021-04-13 22:28:13 | [diff] [blame] | 74 | void ExternallyManagedAppManager::SetSubsystems( |
Song Fangzhen | ed83c14 | 2021-07-13 03:21:44 | [diff] [blame] | 75 | WebAppRegistrar* registrar, |
phillis | 526a61d | 2020-07-20 21:10:57 | [diff] [blame] | 76 | WebAppUiManager* ui_manager, |
Song Fangzhen | b60b44f4 | 2021-08-11 08:49:23 | [diff] [blame] | 77 | WebAppInstallFinalizer* finalizer, |
Phillis Tang | b1cb31f | 2022-05-11 08:06:10 | [diff] [blame] | 78 | WebAppCommandManager* command_manager, |
Mustapha Jaber | 651c204 | 2022-02-25 15:27:49 | [diff] [blame] | 79 | WebAppSyncBridge* sync_bridge) { |
Christopher Lam | a45ea6d | 2019-07-08 07:22:05 | [diff] [blame] | 80 | registrar_ = registrar; |
Alan Cutter | 31b206b | 2019-07-17 16:57:35 | [diff] [blame] | 81 | ui_manager_ = ui_manager; |
Christopher Lam | a45ea6d | 2019-07-08 07:22:05 | [diff] [blame] | 82 | finalizer_ = finalizer; |
Phillis Tang | b1cb31f | 2022-05-11 08:06:10 | [diff] [blame] | 83 | command_manager_ = command_manager; |
Mustapha Jaber | 651c204 | 2022-02-25 15:27:49 | [diff] [blame] | 84 | sync_bridge_ = sync_bridge; |
Christopher Lam | a45ea6d | 2019-07-08 07:22:05 | [diff] [blame] | 85 | } |
| 86 | |
Daniel Murphy | 6294817d | 2021-04-13 22:28:13 | [diff] [blame] | 87 | void ExternallyManagedAppManager::SynchronizeInstalledApps( |
Alexey Baskakov | 0b9a2ee | 2019-07-22 01:21:24 | [diff] [blame] | 88 | std::vector<ExternalInstallOptions> desired_apps_install_options, |
Alexey Baskakov | 03189527 | 2019-07-18 08:19:33 | [diff] [blame] | 89 | ExternalInstallSource install_source, |
Christopher Lam | 8b4142d | 2019-04-08 06:54:42 | [diff] [blame] | 90 | SynchronizeCallback callback) { |
Christopher Lam | 44ee1a8 | 2019-06-21 06:50:56 | [diff] [blame] | 91 | DCHECK(registrar_); |
Peter Kasting | 4703b5b | 2022-08-31 08:15:58 | [diff] [blame] | 92 | DCHECK(base::ranges::all_of( |
| 93 | desired_apps_install_options, |
Alexey Baskakov | 0b9a2ee | 2019-07-22 01:21:24 | [diff] [blame] | 94 | [&install_source](const ExternalInstallOptions& install_options) { |
| 95 | return install_options.install_source == install_source; |
| 96 | })); |
Alexey Baskakov | 03189527 | 2019-07-18 08:19:33 | [diff] [blame] | 97 | // Only one concurrent SynchronizeInstalledApps() expected per |
| 98 | // ExternalInstallSource. |
Jan Wilken Dörrie | a8cb5630 | 2019-06-06 18:59:36 | [diff] [blame] | 99 | DCHECK(!base::Contains(synchronize_requests_, install_source)); |
Nigel Tao | 02f334fe | 2018-09-20 01:28:29 | [diff] [blame] | 100 | |
Christopher Lam | 44ee1a8 | 2019-06-21 06:50:56 | [diff] [blame] | 101 | std::vector<GURL> installed_urls; |
Eric Willigers | fd78748 | 2022-03-02 03:26:54 | [diff] [blame] | 102 | for (const auto& apps_it : |
| 103 | registrar_->GetExternallyInstalledApps(install_source)) { |
Dibyajyoti Pal | f7430b3e | 2022-06-28 14:32:10 | [diff] [blame] | 104 | // TODO(crbug.com/1339965): Remove this check once we cleanup |
Dibyajyoti Pal | d251e0e | 2022-06-13 15:44:32 | [diff] [blame] | 105 | // ExternallyInstalledWebAppPrefs on external app uninstall. |
Mustapha Jaber | 651c204 | 2022-02-25 15:27:49 | [diff] [blame] | 106 | bool has_same_external_source = |
| 107 | registrar_->GetAppById(apps_it.first) |
| 108 | ->GetSources() |
Daniel Murphy | 19a34bf | 2022-04-07 15:29:36 | [diff] [blame] | 109 | .test(ConvertExternalInstallSourceToSource(install_source)); |
Dibyajyoti Pal | 2cb22f9 | 2022-06-08 20:22:39 | [diff] [blame] | 110 | if (has_same_external_source) { |
| 111 | for (const GURL& url : apps_it.second) { |
| 112 | installed_urls.push_back(url); |
| 113 | } |
| 114 | } |
Mustapha Jaber | 651c204 | 2022-02-25 15:27:49 | [diff] [blame] | 115 | } |
Christopher Lam | 44ee1a8 | 2019-06-21 06:50:56 | [diff] [blame] | 116 | |
| 117 | std::sort(installed_urls.begin(), installed_urls.end()); |
Nigel Tao | 02f334fe | 2018-09-20 01:28:29 | [diff] [blame] | 118 | |
| 119 | std::vector<GURL> desired_urls; |
Eric Willigers | fd78748 | 2022-03-02 03:26:54 | [diff] [blame] | 120 | desired_urls.reserve(desired_apps_install_options.size()); |
Christopher Lam | 44ee1a8 | 2019-06-21 06:50:56 | [diff] [blame] | 121 | for (const auto& info : desired_apps_install_options) |
Alan Cutter | 0cc8373 | 2020-09-02 02:26:36 | [diff] [blame] | 122 | desired_urls.push_back(info.install_url); |
Christopher Lam | 44ee1a8 | 2019-06-21 06:50:56 | [diff] [blame] | 123 | |
Nigel Tao | 02f334fe | 2018-09-20 01:28:29 | [diff] [blame] | 124 | std::sort(desired_urls.begin(), desired_urls.end()); |
| 125 | |
Dibyajyoti Pal | d251e0e | 2022-06-13 15:44:32 | [diff] [blame] | 126 | std::vector<GURL> urls_to_remove = |
Christopher Lam | 44ee1a8 | 2019-06-21 06:50:56 | [diff] [blame] | 127 | base::STLSetDifference<std::vector<GURL>>(installed_urls, desired_urls); |
Christopher Lam | 8b4142d | 2019-04-08 06:54:42 | [diff] [blame] | 128 | |
Dibyajyoti Pal | d251e0e | 2022-06-13 15:44:32 | [diff] [blame] | 129 | #if BUILDFLAG(IS_CHROMEOS) |
| 130 | // This check ensures that on Chrome OS, the messages app is not uninstalled |
| 131 | // automatically when SynchronizeInstalledApps() is called for preinstalled |
| 132 | // apps. |
| 133 | // TODO(crbug.com/1239801): Once Messages has been migrated to be a |
| 134 | // preinstalled app, this logic can be removed because the |
| 135 | // PreInstalledWebAppManager will take care of this. |
| 136 | if (!urls_to_remove.empty() && |
| 137 | ConvertExternalInstallSourceToSource(install_source) == |
| 138 | WebAppManagement::kDefault) { |
| 139 | base::EraseIf(urls_to_remove, [&](const GURL& url) { |
| 140 | return url.spec() == |
| 141 | "https://messages-web.sandbox.google.com/web/authentication" || |
| 142 | url.spec() == "https://messages.google.com/web/authentication"; |
| 143 | }); |
| 144 | } |
| 145 | #endif |
| 146 | |
Christopher Lam | 8b4142d | 2019-04-08 06:54:42 | [diff] [blame] | 147 | // Run callback immediately if there's no work to be done. |
| 148 | if (urls_to_remove.empty() && desired_apps_install_options.empty()) { |
| 149 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 150 | FROM_HERE, |
Alan Cutter | 2ce91fc | 2020-12-02 03:56:41 | [diff] [blame] | 151 | base::BindOnce(std::move(callback), std::map<GURL, InstallResult>(), |
Christopher Lam | 9513eb2f | 2019-06-27 07:57:57 | [diff] [blame] | 152 | std::map<GURL, bool>())); |
Christopher Lam | 8b4142d | 2019-04-08 06:54:42 | [diff] [blame] | 153 | return; |
| 154 | } |
| 155 | |
Christopher Lam | 8b4142d | 2019-04-08 06:54:42 | [diff] [blame] | 156 | // Add the callback to a map and call once all installs/uninstalls finish. |
| 157 | synchronize_requests_.insert_or_assign( |
| 158 | install_source, |
| 159 | SynchronizeRequest(std::move(callback), |
Daniel Murphy | 527765a5 | 2021-09-13 19:09:21 | [diff] [blame] | 160 | std::move(desired_apps_install_options), |
| 161 | urls_to_remove.size())); |
Christopher Lam | 8b4142d | 2019-04-08 06:54:42 | [diff] [blame] | 162 | |
Daniel Murphy | 527765a5 | 2021-09-13 19:09:21 | [diff] [blame] | 163 | if (urls_to_remove.empty()) { |
| 164 | // If there are no uninstalls, this will trigger the installs. |
| 165 | ContinueOrCompleteSynchronization(install_source); |
| 166 | } else { |
| 167 | UninstallApps( |
| 168 | urls_to_remove, install_source, |
| 169 | base::BindRepeating( |
| 170 | &ExternallyManagedAppManager::UninstallForSynchronizeCallback, |
| 171 | weak_ptr_factory_.GetWeakPtr(), install_source)); |
| 172 | } |
Christopher Lam | 8b4142d | 2019-04-08 06:54:42 | [diff] [blame] | 173 | } |
| 174 | |
Daniel Murphy | 6294817d | 2021-04-13 22:28:13 | [diff] [blame] | 175 | void ExternallyManagedAppManager::SetRegistrationCallbackForTesting( |
Eric Willigers | 31c682b2 | 2019-08-27 03:57:40 | [diff] [blame] | 176 | RegistrationCallback callback) { |
Eric Willigers | fd78748 | 2022-03-02 03:26:54 | [diff] [blame] | 177 | registration_callback_ = std::move(callback); |
Eric Willigers | 17390d1 | 2019-08-26 08:16:27 | [diff] [blame] | 178 | } |
| 179 | |
Daniel Murphy | 6294817d | 2021-04-13 22:28:13 | [diff] [blame] | 180 | void ExternallyManagedAppManager::ClearRegistrationCallbackForTesting() { |
Eric Willigers | 31c682b2 | 2019-08-27 03:57:40 | [diff] [blame] | 181 | registration_callback_ = RegistrationCallback(); |
Eric Willigers | 17390d1 | 2019-08-26 08:16:27 | [diff] [blame] | 182 | } |
| 183 | |
Daniel Murphy | 6294817d | 2021-04-13 22:28:13 | [diff] [blame] | 184 | void ExternallyManagedAppManager::SetRegistrationsCompleteCallbackForTesting( |
Alan Cutter | 464b32c6 | 2020-09-16 06:41:37 | [diff] [blame] | 185 | base::OnceClosure callback) { |
| 186 | registrations_complete_callback_ = std::move(callback); |
| 187 | } |
| 188 | |
Daniel Murphy | 6294817d | 2021-04-13 22:28:13 | [diff] [blame] | 189 | void ExternallyManagedAppManager::OnRegistrationFinished( |
| 190 | const GURL& install_url, |
| 191 | RegistrationResultCode result) { |
Eric Willigers | 31c682b2 | 2019-08-27 03:57:40 | [diff] [blame] | 192 | if (registration_callback_) |
Alan Cutter | 096084e | 2020-09-02 08:54:02 | [diff] [blame] | 193 | registration_callback_.Run(install_url, result); |
Eric Willigers | 17390d1 | 2019-08-26 08:16:27 | [diff] [blame] | 194 | } |
| 195 | |
Daniel Murphy | 6294817d | 2021-04-13 22:28:13 | [diff] [blame] | 196 | void ExternallyManagedAppManager::InstallForSynchronizeCallback( |
Alexey Baskakov | 03189527 | 2019-07-18 08:19:33 | [diff] [blame] | 197 | ExternalInstallSource source, |
Alan Cutter | aca3563b | 2022-07-19 08:48:27 | [diff] [blame] | 198 | const GURL& install_url, |
Daniel Murphy | 6294817d | 2021-04-13 22:28:13 | [diff] [blame] | 199 | ExternallyManagedAppManager::InstallResult result) { |
Alan Cutter | 2ce91fc | 2020-12-02 03:56:41 | [diff] [blame] | 200 | if (!IsSuccess(result.code)) { |
Alan Cutter | aca3563b | 2022-07-19 08:48:27 | [diff] [blame] | 201 | LOG(ERROR) << install_url << " from install source " |
| 202 | << static_cast<int>(source) << " failed to install with reason " |
Alan Cutter | 2ce91fc | 2020-12-02 03:56:41 | [diff] [blame] | 203 | << static_cast<int>(result.code); |
Christopher Lam | 9513eb2f | 2019-06-27 07:57:57 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | auto source_and_request = synchronize_requests_.find(source); |
| 207 | DCHECK(source_and_request != synchronize_requests_.end()); |
| 208 | SynchronizeRequest& request = source_and_request->second; |
Alan Cutter | aca3563b | 2022-07-19 08:48:27 | [diff] [blame] | 209 | request.install_results[install_url] = std::move(result); |
Daniel Murphy | 527765a5 | 2021-09-13 19:09:21 | [diff] [blame] | 210 | --request.remaining_install_requests; |
| 211 | DCHECK_GE(request.remaining_install_requests, 0); |
Christopher Lam | 9513eb2f | 2019-06-27 07:57:57 | [diff] [blame] | 212 | |
Daniel Murphy | 527765a5 | 2021-09-13 19:09:21 | [diff] [blame] | 213 | ContinueOrCompleteSynchronization(source); |
Christopher Lam | 8b4142d | 2019-04-08 06:54:42 | [diff] [blame] | 214 | } |
| 215 | |
Daniel Murphy | 6294817d | 2021-04-13 22:28:13 | [diff] [blame] | 216 | void ExternallyManagedAppManager::UninstallForSynchronizeCallback( |
Alexey Baskakov | 03189527 | 2019-07-18 08:19:33 | [diff] [blame] | 217 | ExternalInstallSource source, |
Alan Cutter | aca3563b | 2022-07-19 08:48:27 | [diff] [blame] | 218 | const GURL& install_url, |
Alexey Baskakov | 03189527 | 2019-07-18 08:19:33 | [diff] [blame] | 219 | bool succeeded) { |
Christopher Lam | 9513eb2f | 2019-06-27 07:57:57 | [diff] [blame] | 220 | auto source_and_request = synchronize_requests_.find(source); |
| 221 | DCHECK(source_and_request != synchronize_requests_.end()); |
| 222 | SynchronizeRequest& request = source_and_request->second; |
Alan Cutter | aca3563b | 2022-07-19 08:48:27 | [diff] [blame] | 223 | request.uninstall_results[install_url] = succeeded; |
Daniel Murphy | 527765a5 | 2021-09-13 19:09:21 | [diff] [blame] | 224 | --request.remaining_uninstall_requests; |
| 225 | DCHECK_GE(request.remaining_uninstall_requests, 0); |
Christopher Lam | 9513eb2f | 2019-06-27 07:57:57 | [diff] [blame] | 226 | |
Daniel Murphy | 527765a5 | 2021-09-13 19:09:21 | [diff] [blame] | 227 | ContinueOrCompleteSynchronization(source); |
Christopher Lam | 8b4142d | 2019-04-08 06:54:42 | [diff] [blame] | 228 | } |
| 229 | |
Daniel Murphy | 527765a5 | 2021-09-13 19:09:21 | [diff] [blame] | 230 | void ExternallyManagedAppManager::ContinueOrCompleteSynchronization( |
| 231 | ExternalInstallSource source) { |
Christopher Lam | 9513eb2f | 2019-06-27 07:57:57 | [diff] [blame] | 232 | auto source_and_request = synchronize_requests_.find(source); |
| 233 | DCHECK(source_and_request != synchronize_requests_.end()); |
Christopher Lam | 8b4142d | 2019-04-08 06:54:42 | [diff] [blame] | 234 | |
Christopher Lam | 9513eb2f | 2019-06-27 07:57:57 | [diff] [blame] | 235 | SynchronizeRequest& request = source_and_request->second; |
Christopher Lam | 9513eb2f | 2019-06-27 07:57:57 | [diff] [blame] | 236 | |
Daniel Murphy | 527765a5 | 2021-09-13 19:09:21 | [diff] [blame] | 237 | if (request.remaining_uninstall_requests > 0) |
| 238 | return; |
| 239 | |
| 240 | // Installs only take place after all uninstalls. |
| 241 | if (!request.pending_installs.empty()) { |
| 242 | DCHECK_GT(request.remaining_install_requests, 0); |
| 243 | // Note: It is intentional that std::move(request.pending_installs) clears |
| 244 | // the vector in `request`, preventing this branch from triggering again. |
| 245 | InstallApps(std::move(request.pending_installs), |
| 246 | base::BindRepeating( |
| 247 | &ExternallyManagedAppManager::InstallForSynchronizeCallback, |
| 248 | weak_ptr_factory_.GetWeakPtr(), source)); |
| 249 | return; |
Christopher Lam | 8b4142d | 2019-04-08 06:54:42 | [diff] [blame] | 250 | } |
Daniel Murphy | 527765a5 | 2021-09-13 19:09:21 | [diff] [blame] | 251 | |
| 252 | if (request.remaining_install_requests > 0) |
| 253 | return; |
| 254 | |
| 255 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 256 | FROM_HERE, base::BindOnce(std::move(request.callback), |
| 257 | std::move(request.install_results), |
| 258 | std::move(request.uninstall_results))); |
| 259 | synchronize_requests_.erase(source); |
Giovanni Ortuño Urquidi | b4839fb | 2018-08-24 10:36:57 | [diff] [blame] | 260 | } |
Daniel Murphy | 6294817d | 2021-04-13 22:28:13 | [diff] [blame] | 261 | void ExternallyManagedAppManager::ClearSynchronizeRequestsForTesting() { |
Dominic Schulz | dd4d866 | 2020-07-27 17:49:09 | [diff] [blame] | 262 | synchronize_requests_.erase(synchronize_requests_.begin(), |
| 263 | synchronize_requests_.end()); |
| 264 | } |
Giovanni Ortuño Urquidi | b4839fb | 2018-08-24 10:36:57 | [diff] [blame] | 265 | |
Nigel Tao | c5d6bcb | 2018-07-25 04:57:42 | [diff] [blame] | 266 | } // namespace web_app |