#include "chrome/browser/web_applications/externally_managed_app_manager.h"
#include <map>
#include <memory>
#include <ostream>
#include <utility>
#include <vector>
#include "base/check_is_test.h"
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/functional/callback_helpers.h"
#include "base/not_fatal_until.h"
#include "base/ranges/algorithm.h"
#include "base/stl_util.h"
#include "base/strings/to_string.h"
#include "base/task/sequenced_task_runner.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/external_install_options.h"
#include "chrome/browser/web_applications/externally_managed_app_install_task.h"
#include "chrome/browser/web_applications/externally_managed_app_registration_task.h"
#include "chrome/browser/web_applications/locks/all_apps_lock.h"
#include "chrome/browser/web_applications/web_app_command_scheduler.h"
#include "chrome/browser/web_applications/web_app_install_utils.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/browser/web_applications/web_app_registry_update.h"
#include "chrome/browser/web_applications/web_app_sync_bridge.h"
#include "chrome/browser/web_applications/web_contents/web_app_data_retriever.h"
#include "chrome/browser/web_applications/web_contents/web_contents_manager.h"
#include "chrome/common/chrome_features.h"
#include "components/webapps/browser/install_result_code.h"
#include "components/webapps/browser/uninstall_result_code.h"
#include "components/webapps/browser/web_contents/web_app_url_loader.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
namespace web_app {
ExternallyManagedAppManager::InstallResult::InstallResult() = default;
ExternallyManagedAppManager::InstallResult::InstallResult(
webapps::InstallResultCode code,
std::optional<webapps::AppId> app_id,
bool did_uninstall_and_replace)
: … { … }
ExternallyManagedAppManager::InstallResult::InstallResult(
const InstallResult&) = default;
ExternallyManagedAppManager::InstallResult::~InstallResult() = default;
bool ExternallyManagedAppManager::InstallResult::operator==(
const InstallResult& other) const { … }
ExternallyManagedAppManager::SynchronizeRequest::SynchronizeRequest(
SynchronizeCallback callback,
std::vector<ExternalInstallOptions> pending_installs,
int remaining_uninstall_requests)
: … { … }
ExternallyManagedAppManager::SynchronizeRequest::~SynchronizeRequest() =
default;
ExternallyManagedAppManager::SynchronizeRequest&
ExternallyManagedAppManager::SynchronizeRequest::operator=(
ExternallyManagedAppManager::SynchronizeRequest&&) = default;
ExternallyManagedAppManager::SynchronizeRequest::SynchronizeRequest(
SynchronizeRequest&& other) = default;
struct ExternallyManagedAppManager::TaskAndCallback { … };
ExternallyManagedAppManager::ExternallyManagedAppManager(Profile* profile)
: … { … }
ExternallyManagedAppManager::~ExternallyManagedAppManager() { … }
void ExternallyManagedAppManager::SetProvider(base::PassKey<WebAppProvider>,
WebAppProvider& provider) { … }
void ExternallyManagedAppManager::InstallNow(
ExternalInstallOptions install_options,
OnceInstallCallback callback) { … }
void ExternallyManagedAppManager::Install(
ExternalInstallOptions install_options,
OnceInstallCallback callback) { … }
void ExternallyManagedAppManager::InstallApps(
std::vector<ExternalInstallOptions> install_options_list,
const RepeatingInstallCallback& callback) { … }
void ExternallyManagedAppManager::UninstallApps(
std::vector<GURL> uninstall_urls,
ExternalInstallSource install_source,
const UninstallCallback& callback) { … }
void ExternallyManagedAppManager::SynchronizeInstalledApps(
std::vector<ExternalInstallOptions> desired_apps_install_options,
ExternalInstallSource install_source,
SynchronizeCallback callback) { … }
void ExternallyManagedAppManager::Shutdown() { … }
void ExternallyManagedAppManager::SetUrlLoaderForTesting(
std::unique_ptr<webapps::WebAppUrlLoader> url_loader) { … }
void ExternallyManagedAppManager::SetDataRetrieverFactoryForTesting(
base::RepeatingCallback<std::unique_ptr<WebAppDataRetriever>()> factory) { … }
void ExternallyManagedAppManager::ReleaseWebContents() { … }
std::unique_ptr<ExternallyManagedAppInstallTask>
ExternallyManagedAppManager::CreateInstallationTask(
ExternalInstallOptions install_options) { … }
std::unique_ptr<ExternallyManagedAppRegistrationTaskBase>
ExternallyManagedAppManager::CreateRegistration(
GURL install_url,
const base::TimeDelta registration_timeout) { … }
void ExternallyManagedAppManager::OnRegistrationFinished(
const GURL& install_url,
RegistrationResultCode result) { … }
void ExternallyManagedAppManager::PostMaybeStartNext() { … }
void ExternallyManagedAppManager::MaybeStartNext() { … }
void ExternallyManagedAppManager::MaybeStartNextOnLockAcquired(
AllAppsLock& lock,
base::Value::Dict& debug_value) { … }
void ExternallyManagedAppManager::StartInstallationTask(
std::unique_ptr<TaskAndCallback> task,
std::optional<webapps::AppId> installed_placeholder_app_id) { … }
bool ExternallyManagedAppManager::RunNextRegistration() { … }
void ExternallyManagedAppManager::CreateWebContentsIfNecessary() { … }
void ExternallyManagedAppManager::OnInstalled(
ExternallyManagedAppManager::InstallResult result) { … }
void ExternallyManagedAppManager::MaybeEnqueueServiceWorkerRegistration(
const ExternalInstallOptions& install_options) { … }
bool ExternallyManagedAppManager::IsShuttingDown() { … }
void ExternallyManagedAppManager::SynchronizeInstalledAppsOnLockAcquired(
std::vector<ExternalInstallOptions> desired_apps_install_options,
ExternalInstallSource install_source,
SynchronizeCallback callback,
AllAppsLock& lock,
base::Value::Dict& debug_info) { … }
void ExternallyManagedAppManager::SetRegistrationCallbackForTesting(
RegistrationCallback callback) { … }
void ExternallyManagedAppManager::ClearRegistrationCallbackForTesting() { … }
void ExternallyManagedAppManager::SetRegistrationsCompleteCallbackForTesting(
base::OnceClosure callback) { … }
void ExternallyManagedAppManager::InstallForSynchronizeCallback(
ExternalInstallSource source,
const GURL& install_url,
ExternallyManagedAppManager::InstallResult result) { … }
void ExternallyManagedAppManager::UninstallForSynchronizeCallback(
ExternalInstallSource source,
const GURL& install_url,
webapps::UninstallResultCode code) { … }
void ExternallyManagedAppManager::ContinueSynchronization(
ExternalInstallSource source) { … }
void ExternallyManagedAppManager::CompleteSynchronization(
ExternalInstallSource source) { … }
void ExternallyManagedAppManager::ClearSynchronizeRequestsForTesting() { … }
std::ostream& operator<<(
std::ostream& out,
const ExternallyManagedAppManager::InstallResult& install_result) { … }
}