Commit d05bb016 authored by Alexey Baskakov's avatar Alexey Baskakov Committed by Commit Bot

WebApp: Extract PendingAppManager::AppInfo as a standalone struct.

Rename AppInfo to InstallOptions to avoid confusion with WebApplicationInfo.

We will reuse InstallOptions as a parameter object in web_app::InstallManager.

Bug: 916381
Change-Id: I7e4ea7ea7986ca537d9327b190443e72c2a16661
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1535306
Commit-Queue: Alexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarJeremy Klein <jlklein@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644699}
parent 6b2bf0a8
......@@ -15,6 +15,7 @@
#include "base/optional.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/components/install_options.h"
#include "chrome/browser/web_applications/components/pending_app_manager.h"
#include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/common/chrome_features.h"
......@@ -196,19 +197,19 @@ void AndroidSmsAppSetupControllerImpl::OnDeleteMigrationCookieResult(
return;
}
web_app::PendingAppManager::AppInfo info(install_url,
web_app::LaunchContainer::kWindow,
web_app::InstallSource::kInternal);
info.override_previous_user_uninstall = true;
web_app::InstallOptions options(install_url,
web_app::LaunchContainer::kWindow,
web_app::InstallSource::kInternal);
options.override_previous_user_uninstall = true;
// The ServiceWorker does not load in time for the installability check, so
// bypass it as a workaround.
info.bypass_service_worker_check = true;
info.require_manifest = true;
options.bypass_service_worker_check = true;
options.require_manifest = true;
PA_LOG(VERBOSE) << "AndroidSmsAppSetupControllerImpl::OnSetCookieResult(): "
<< "Installing PWA for " << install_url << ".";
pending_app_manager_->Install(
std::move(info),
std::move(options),
base::BindOnce(&AndroidSmsAppSetupControllerImpl::OnAppInstallResult,
weak_ptr_factory_.GetWeakPtr(), std::move(callback),
app_url));
......
......@@ -19,6 +19,7 @@
#include "base/run_loop.h"
#include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/web_applications/components/install_options.h"
#include "chrome/browser/web_applications/components/test_pending_app_manager.h"
#include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/test/base/testing_profile.h"
......@@ -40,14 +41,13 @@ const char kTestUrl1[] = "https://test-url-1.com/";
const char kTestInstallUrl1[] = "https://test-url-1.com/install";
const char kTestUrl2[] = "https://test-url-2.com/";
web_app::PendingAppManager::AppInfo GetAppInfoForUrl(const GURL& url) {
web_app::PendingAppManager::AppInfo info(url,
web_app::LaunchContainer::kWindow,
web_app::InstallSource::kInternal);
info.override_previous_user_uninstall = true;
info.bypass_service_worker_check = true;
info.require_manifest = true;
return info;
web_app::InstallOptions GetInstallOptionsForUrl(const GURL& url) {
web_app::InstallOptions options(url, web_app::LaunchContainer::kWindow,
web_app::InstallSource::kInternal);
options.override_previous_user_uninstall = true;
options.bypass_service_worker_check = true;
options.require_manifest = true;
return options;
}
class FakeCookieManager : public network::TestCookieManager {
......@@ -226,7 +226,7 @@ class AndroidSmsAppSetupControllerImplTest : public testing::Test {
// install it.
if (!test_pwa_delegate_->GetPwaForUrl(install_url, &profile_)) {
EXPECT_EQ(num_install_requests_before_call + 1u, install_requests.size());
EXPECT_EQ(GetAppInfoForUrl(install_url), install_requests.back());
EXPECT_EQ(GetInstallOptionsForUrl(install_url), install_requests.back());
EXPECT_EQ(ContentSetting::CONTENT_SETTING_ALLOW,
GetNotificationSetting(app_url));
......
......@@ -40,13 +40,13 @@ void NavigateToURLAndWait(Browser* browser, const GURL& url) {
// TODO(loyso): Merge this with PendingBookmarkAppManagerBrowserTest's
// implementation in some test_support library.
web_app::PendingAppManager::AppInfo CreateAppInfo(const GURL& url) {
web_app::PendingAppManager::AppInfo app_info(
url, web_app::LaunchContainer::kWindow,
web_app::InstallSource::kInternal);
web_app::InstallOptions CreateInstallOptions(const GURL& url) {
web_app::InstallOptions install_options(url,
web_app::LaunchContainer::kWindow,
web_app::InstallSource::kInternal);
// Avoid creating real shortcuts in tests.
app_info.create_shortcuts = false;
return app_info;
install_options.create_shortcuts = false;
return install_options;
}
GURL GetUrlForSuffix(const std::string& prefix, int suffix) {
......@@ -195,13 +195,12 @@ class BookmarkAppTest : public extensions::ExtensionBrowserTest {
// TODO(loyso): Merge this method with
// PendingBookmarkAppManagerBrowserTest::InstallApp in some
// test_support library.
void InstallDefaultAppAndCountApps(
web_app::PendingAppManager::AppInfo app_info) {
void InstallDefaultAppAndCountApps(web_app::InstallOptions install_options) {
base::RunLoop run_loop;
web_app::WebAppProvider::Get(browser()->profile())
->pending_app_manager()
.Install(std::move(app_info),
.Install(std::move(install_options),
base::BindLambdaForTesting(
[this, &run_loop](const GURL& provided_url,
web_app::InstallResultCode code) {
......@@ -399,7 +398,7 @@ IN_PROC_BROWSER_TEST_F(BookmarkAppTest, EngagementHistogramDefaultApp) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL example_url(
embedded_test_server()->GetURL("/banners/manifest_test_page.html"));
InstallDefaultAppAndCountApps(CreateAppInfo(example_url));
InstallDefaultAppAndCountApps(CreateInstallOptions(example_url));
ASSERT_EQ(web_app::InstallResultCode::kSuccess, result_code_.value());
const extensions::Extension* app = extensions::util::GetInstalledPwaForUrl(
......
......@@ -60,7 +60,7 @@ static base::FilePath test_dir(const std::string& sub_dir) {
return dir.AppendASCII(kWebAppDefaultApps).AppendASCII(sub_dir);
}
using AppInfos = std::vector<web_app::PendingAppManager::AppInfo>;
using InstallOptionsList = std::vector<web_app::InstallOptions>;
} // namespace
......@@ -88,27 +88,28 @@ class ScanDirForExternalWebAppsTest : public testing::Test {
protected:
// Helper that makes blocking call to |web_app::ScanForExternalWebApps| and
// returns read app infos.
static AppInfos ScanApps(Profile* profile, const base::FilePath& test_dir) {
static InstallOptionsList ScanApps(Profile* profile,
const base::FilePath& test_dir) {
#if defined(OS_CHROMEOS)
base::ScopedPathOverride path_override(
chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS, test_dir);
#endif
AppInfos result;
InstallOptionsList result;
base::RunLoop run_loop;
web_app::ScanForExternalWebApps(
profile,
base::BindOnce(
[](base::RunLoop* run_loop, AppInfos* result, AppInfos apps) {
*result = apps;
run_loop->Quit();
},
&run_loop, &result));
profile, base::BindOnce(
[](base::RunLoop* run_loop, InstallOptionsList* result,
InstallOptionsList install_options_list) {
*result = install_options_list;
run_loop->Quit();
},
&run_loop, &result));
run_loop.Run();
return result;
}
std::vector<web_app::PendingAppManager::AppInfo>
ScanTestDirForExternalWebApps(const std::string& dir) {
std::vector<web_app::InstallOptions> ScanTestDirForExternalWebApps(
const std::string& dir) {
return web_app::ScanDirForExternalWebAppsForTesting(test_dir(dir),
CreateProfile().get());
}
......@@ -148,10 +149,11 @@ class ScanDirForExternalWebAppsTest : public testing::Test {
}
void VerifySetOfApps(Profile* profile, const std::set<GURL>& expectations) {
const auto app_infos = ScanApps(profile, test_dir(kUserTypesTestDir));
ASSERT_EQ(expectations.size(), app_infos.size());
for (const auto& app_info : app_infos)
ASSERT_EQ(1u, expectations.count(app_info.url));
const auto install_options_list =
ScanApps(profile, test_dir(kUserTypesTestDir));
ASSERT_EQ(expectations.size(), install_options_list.size());
for (const auto& install_options : install_options_list)
ASSERT_EQ(1u, expectations.count(install_options.url));
}
#endif
......@@ -173,35 +175,36 @@ class ScanDirForExternalWebAppsTest : public testing::Test {
};
TEST_F(ScanDirForExternalWebAppsTest, GoodJson) {
const auto app_infos = ScanTestDirForExternalWebApps(kGoodJsonTestDir);
const auto install_options_list =
ScanTestDirForExternalWebApps(kGoodJsonTestDir);
// The good_json directory contains two good JSON files:
// chrome_platform_status.json and google_io_2016.json.
// google_io_2016.json is missing a "create_shortcuts" field, so the default
// value of false should be used.
std::vector<web_app::PendingAppManager::AppInfo> test_app_infos;
std::vector<web_app::InstallOptions> test_install_options_list;
{
web_app::PendingAppManager::AppInfo info(
web_app::InstallOptions install_options(
GURL("https://www.chromestatus.com/features"),
web_app::LaunchContainer::kTab,
web_app::InstallSource::kExternalDefault);
info.create_shortcuts = true;
info.require_manifest = true;
test_app_infos.push_back(std::move(info));
install_options.create_shortcuts = true;
install_options.require_manifest = true;
test_install_options_list.push_back(std::move(install_options));
}
{
web_app::PendingAppManager::AppInfo info(
web_app::InstallOptions install_options(
GURL("https://events.google.com/io2016/?utm_source=web_app_manifest"),
web_app::LaunchContainer::kWindow,
web_app::InstallSource::kExternalDefault);
info.create_shortcuts = false;
info.require_manifest = true;
test_app_infos.push_back(std::move(info));
install_options.create_shortcuts = false;
install_options.require_manifest = true;
test_install_options_list.push_back(std::move(install_options));
}
EXPECT_EQ(test_app_infos.size(), app_infos.size());
for (const auto app_info : test_app_infos) {
EXPECT_TRUE(base::ContainsValue(app_infos, app_info));
EXPECT_EQ(test_install_options_list.size(), install_options_list.size());
for (const auto install_option : test_install_options_list) {
EXPECT_TRUE(base::ContainsValue(install_options_list, install_option));
}
}
......
......@@ -46,11 +46,11 @@ base::Value GetWindowedItem() {
return item;
}
PendingAppManager::AppInfo GetWindowedAppInfo() {
PendingAppManager::AppInfo info(GURL(kWindowedUrl), LaunchContainer::kWindow,
InstallSource::kExternalPolicy);
info.create_shortcuts = false;
return info;
InstallOptions GetWindowedInstallOptions() {
InstallOptions options(GURL(kWindowedUrl), LaunchContainer::kWindow,
InstallSource::kExternalPolicy);
options.create_shortcuts = false;
return options;
}
base::Value GetTabbedItem() {
......@@ -60,11 +60,11 @@ base::Value GetTabbedItem() {
return item;
}
PendingAppManager::AppInfo GetTabbedAppInfo() {
PendingAppManager::AppInfo info(GURL(kTabbedUrl), LaunchContainer::kTab,
InstallSource::kExternalPolicy);
info.create_shortcuts = false;
return info;
InstallOptions GetTabbedInstallOptions() {
InstallOptions options(GURL(kTabbedUrl), LaunchContainer::kTab,
InstallSource::kExternalPolicy);
options.create_shortcuts = false;
return options;
}
base::Value GetDefaultContainerItem() {
......@@ -73,12 +73,11 @@ base::Value GetDefaultContainerItem() {
return item;
}
PendingAppManager::AppInfo GetDefaultContainerAppInfo() {
PendingAppManager::AppInfo info(GURL(kDefaultContainerUrl),
LaunchContainer::kDefault,
InstallSource::kExternalPolicy);
info.create_shortcuts = false;
return info;
InstallOptions GetDefaultContainerInstallOptions() {
InstallOptions options(GURL(kDefaultContainerUrl), LaunchContainer::kDefault,
InstallSource::kExternalPolicy);
options.create_shortcuts = false;
return options;
}
} // namespace
......@@ -144,8 +143,8 @@ TEST_F(WebAppPolicyManagerTest, NoForceInstalledAppsPrefValue) {
base::RunLoop().RunUntilIdle();
const auto& apps_to_install = pending_app_manager()->install_requests();
EXPECT_TRUE(apps_to_install.empty());
const auto& install_requests = pending_app_manager()->install_requests();
EXPECT_TRUE(install_requests.empty());
}
TEST_F(WebAppPolicyManagerTest, NoForceInstalledApps) {
......@@ -155,8 +154,8 @@ TEST_F(WebAppPolicyManagerTest, NoForceInstalledApps) {
policy_manager()->Start();
base::RunLoop().RunUntilIdle();
const auto& apps_to_install = pending_app_manager()->install_requests();
EXPECT_TRUE(apps_to_install.empty());
const auto& install_requests = pending_app_manager()->install_requests();
EXPECT_TRUE(install_requests.empty());
}
TEST_F(WebAppPolicyManagerTest, TwoForceInstalledApps) {
......@@ -169,13 +168,13 @@ TEST_F(WebAppPolicyManagerTest, TwoForceInstalledApps) {
policy_manager()->Start();
base::RunLoop().RunUntilIdle();
const auto& apps_to_install = pending_app_manager()->install_requests();
const auto& install_requests = pending_app_manager()->install_requests();
std::vector<PendingAppManager::AppInfo> expected_apps_to_install;
expected_apps_to_install.push_back(GetWindowedAppInfo());
expected_apps_to_install.push_back(GetTabbedAppInfo());
std::vector<InstallOptions> expected_install_options_list;
expected_install_options_list.push_back(GetWindowedInstallOptions());
expected_install_options_list.push_back(GetTabbedInstallOptions());
EXPECT_EQ(apps_to_install, expected_apps_to_install);
EXPECT_EQ(install_requests, expected_install_options_list);
}
TEST_F(WebAppPolicyManagerTest, ForceInstallAppWithNoForcedLaunchContainer) {
......@@ -186,12 +185,12 @@ TEST_F(WebAppPolicyManagerTest, ForceInstallAppWithNoForcedLaunchContainer) {
policy_manager()->Start();
base::RunLoop().RunUntilIdle();
const auto& apps_to_install = pending_app_manager()->install_requests();
const auto& install_requests = pending_app_manager()->install_requests();
std::vector<PendingAppManager::AppInfo> expected_apps_to_install;
expected_apps_to_install.push_back(GetDefaultContainerAppInfo());
std::vector<InstallOptions> expected_install_options_list;
expected_install_options_list.push_back(GetDefaultContainerInstallOptions());
EXPECT_EQ(apps_to_install, expected_apps_to_install);
EXPECT_EQ(install_requests, expected_install_options_list);
}
TEST_F(WebAppPolicyManagerTest, DynamicRefresh) {
......@@ -203,12 +202,12 @@ TEST_F(WebAppPolicyManagerTest, DynamicRefresh) {
policy_manager()->Start();
base::RunLoop().RunUntilIdle();
const auto& apps_to_install = pending_app_manager()->install_requests();
const auto& install_requests = pending_app_manager()->install_requests();
std::vector<PendingAppManager::AppInfo> expected_apps_to_install;
expected_apps_to_install.push_back(GetWindowedAppInfo());
std::vector<InstallOptions> expected_install_options_list;
expected_install_options_list.push_back(GetWindowedInstallOptions());
EXPECT_EQ(apps_to_install, expected_apps_to_install);
EXPECT_EQ(install_requests, expected_install_options_list);
base::Value second_list(base::Value::Type::LIST);
second_list.GetList().push_back(GetTabbedItem());
......@@ -217,9 +216,9 @@ TEST_F(WebAppPolicyManagerTest, DynamicRefresh) {
base::RunLoop().RunUntilIdle();
expected_apps_to_install.push_back(GetTabbedAppInfo());
expected_install_options_list.push_back(GetTabbedInstallOptions());
EXPECT_EQ(apps_to_install, expected_apps_to_install);
EXPECT_EQ(install_requests, expected_install_options_list);
}
TEST_F(WebAppPolicyManagerTest, UninstallAppInstalledInPreviousSession) {
......@@ -242,10 +241,10 @@ TEST_F(WebAppPolicyManagerTest, UninstallAppInstalledInPreviousSession) {
base::RunLoop().RunUntilIdle();
// We should only try to install the app in the policy.
std::vector<PendingAppManager::AppInfo> expected_apps_to_install;
expected_apps_to_install.push_back(GetWindowedAppInfo());
std::vector<InstallOptions> expected_install_options_list;
expected_install_options_list.push_back(GetWindowedInstallOptions());
EXPECT_EQ(pending_app_manager()->install_requests(),
expected_apps_to_install);
expected_install_options_list);
// We should try to uninstall the app that is no longer in the policy.
EXPECT_EQ(std::vector<GURL>({GURL(kTabbedUrl)}),
......@@ -266,13 +265,13 @@ TEST_F(WebAppPolicyManagerTest, UninstallAppInstalledInCurrentSession) {
std::move(first_list));
base::RunLoop().RunUntilIdle();
const auto& apps_to_install = pending_app_manager()->install_requests();
const auto& install_requests = pending_app_manager()->install_requests();
std::vector<PendingAppManager::AppInfo> expected_apps_to_install;
expected_apps_to_install.push_back(GetWindowedAppInfo());
expected_apps_to_install.push_back(GetTabbedAppInfo());
std::vector<InstallOptions> expected_install_options_list;
expected_install_options_list.push_back(GetWindowedInstallOptions());
expected_install_options_list.push_back(GetTabbedInstallOptions());
EXPECT_EQ(apps_to_install, expected_apps_to_install);
EXPECT_EQ(install_requests, expected_install_options_list);
// Push a new policy without the tabbed site.
base::Value second_list(base::Value::Type::LIST);
......@@ -283,9 +282,9 @@ TEST_F(WebAppPolicyManagerTest, UninstallAppInstalledInCurrentSession) {
// We'll try to install the app again but PendingAppManager will handle
// not re-installing the app.
expected_apps_to_install.push_back(GetWindowedAppInfo());
expected_install_options_list.push_back(GetWindowedInstallOptions());
EXPECT_EQ(apps_to_install, expected_apps_to_install);
EXPECT_EQ(install_requests, expected_install_options_list);
EXPECT_EQ(std::vector<GURL>({GURL(kTabbedUrl)}),
pending_app_manager()->uninstall_requests());
......
......@@ -38,13 +38,13 @@ const char kAppUrl1[] = "chrome://system-app1";
const char kAppUrl2[] = "chrome://system-app2";
const char kAppUrl3[] = "chrome://system-app3";
PendingAppManager::AppInfo GetWindowedAppInfo() {
PendingAppManager::AppInfo info(GURL(kAppUrl1), LaunchContainer::kWindow,
InstallSource::kSystemInstalled);
info.create_shortcuts = false;
info.bypass_service_worker_check = true;
info.always_update = true;
return info;
InstallOptions GetWindowedInstallOptions() {
InstallOptions options(GURL(kAppUrl1), LaunchContainer::kWindow,
InstallSource::kSystemInstalled);
options.create_shortcuts = false;
options.bypass_service_worker_check = true;
options.always_update = true;
return options;
}
} // namespace
......@@ -163,10 +163,10 @@ TEST_F(SystemWebAppManagerTest, UninstallAppInstalledInPreviousSession) {
base::RunLoop().RunUntilIdle();
// We should only try to install the app in the System App list.
std::vector<PendingAppManager::AppInfo> expected_apps_to_install;
expected_apps_to_install.push_back(GetWindowedAppInfo());
std::vector<InstallOptions> expected_install_options_list;
expected_install_options_list.push_back(GetWindowedInstallOptions());
EXPECT_EQ(pending_app_manager()->install_requests(),
expected_apps_to_install);
expected_install_options_list);
// We should try to uninstall the app that is no longer in the System App
// list.
......
......@@ -9,6 +9,8 @@ source_set("components") {
"install_manager.cc",
"install_manager.h",
"install_manager_observer.h",
"install_options.cc",
"install_options.h",
"pending_app_manager.cc",
"pending_app_manager.h",
"web_app_audio_focus_id_map.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/web_applications/components/install_options.h"
#include <ostream>
#include <tuple>
namespace web_app {
InstallOptions::InstallOptions(const GURL& url,
LaunchContainer launch_container,
InstallSource install_source)
: url(url),
launch_container(launch_container),
install_source(install_source) {}
InstallOptions::~InstallOptions() = default;
InstallOptions::InstallOptions(const InstallOptions& other) = default;
InstallOptions::InstallOptions(InstallOptions&& other) = default;
InstallOptions& InstallOptions::operator=(const InstallOptions& other) =
default;
bool InstallOptions::operator==(const InstallOptions& other) const {
return std::tie(url, launch_container, install_source, create_shortcuts,
override_previous_user_uninstall, bypass_service_worker_check,
require_manifest, always_update) ==
std::tie(other.url, other.launch_container, other.install_source,
other.create_shortcuts,
other.override_previous_user_uninstall,
other.bypass_service_worker_check, other.require_manifest,
other.always_update);
}
std::ostream& operator<<(std::ostream& out,
const InstallOptions& install_options) {
return out << "url: " << install_options.url << "\n launch_container: "
<< static_cast<int32_t>(install_options.launch_container)
<< "\n install_source: "
<< static_cast<int32_t>(install_options.install_source)
<< "\n create_shortcuts: " << install_options.create_shortcuts
<< "\n override_previous_user_uninstall: "
<< install_options.override_previous_user_uninstall
<< "\n bypass_service_worker_check: "
<< install_options.bypass_service_worker_check
<< "\n require_manifest: " << install_options.require_manifest;
}
} // namespace web_app
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_INSTALL_OPTIONS_H_
#define CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_INSTALL_OPTIONS_H_
#include <iosfwd>
#include "url/gurl.h"
namespace web_app {
enum class InstallSource;
enum class LaunchContainer;
struct InstallOptions {
InstallOptions(const GURL& url,
LaunchContainer launch_container,
InstallSource install_source);
~InstallOptions();
InstallOptions(const InstallOptions& other);
InstallOptions(InstallOptions&& other);
InstallOptions& operator=(const InstallOptions& other);
bool operator==(const InstallOptions& other) const;
GURL url;
LaunchContainer launch_container;
InstallSource install_source;
bool create_shortcuts = true;
// Whether the app should be reinstalled even if the user has previously
// uninstalled it.
bool override_previous_user_uninstall = false;
// This must only be used by pre-installed default or system apps that are
// valid PWAs if loading the real service worker is too costly to verify
// programmatically.
bool bypass_service_worker_check = false;
// This should be used for installing all default apps so that good metadata
// is ensured.
bool require_manifest = false;
// Whether the app should be reinstalled even if it is already installed.
bool always_update = false;
};
std::ostream& operator<<(std::ostream& out,
const InstallOptions& install_options);
} // namespace web_app
#endif // CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_INSTALL_OPTIONS_H_
......@@ -13,51 +13,24 @@
namespace web_app {
PendingAppManager::AppInfo::AppInfo(const GURL& url,
LaunchContainer launch_container,
InstallSource install_source)
: url(url),
launch_container(launch_container),
install_source(install_source) {}
PendingAppManager::AppInfo::~AppInfo() = default;
PendingAppManager::AppInfo::AppInfo(const AppInfo& other) = default;
PendingAppManager::AppInfo::AppInfo(AppInfo&& other) = default;
PendingAppManager::AppInfo& PendingAppManager::AppInfo::operator=(
const AppInfo& other) = default;
bool PendingAppManager::AppInfo::operator==(
const PendingAppManager::AppInfo& other) const {
return std::tie(url, launch_container, install_source, create_shortcuts,
override_previous_user_uninstall, bypass_service_worker_check,
require_manifest, always_update) ==
std::tie(other.url, other.launch_container, other.install_source,
other.create_shortcuts,
other.override_previous_user_uninstall,
other.bypass_service_worker_check, other.require_manifest,
other.always_update);
}
PendingAppManager::PendingAppManager() = default;
PendingAppManager::~PendingAppManager() = default;
void PendingAppManager::SynchronizeInstalledApps(
std::vector<AppInfo> desired_apps,
std::vector<InstallOptions> desired_apps_install_options,
InstallSource install_source) {
DCHECK(std::all_of(desired_apps.begin(), desired_apps.end(),
[&install_source](const AppInfo& app_info) {
return app_info.install_source == install_source;
DCHECK(std::all_of(desired_apps_install_options.begin(),
desired_apps_install_options.end(),
[&install_source](const InstallOptions& install_options) {
return install_options.install_source == install_source;
}));
std::vector<GURL> current_urls = GetInstalledAppUrls(install_source);
std::sort(current_urls.begin(), current_urls.end());
std::vector<GURL> desired_urls;
for (const auto& info : desired_apps) {
for (const auto& info : desired_apps_install_options) {
desired_urls.emplace_back(info.url);
}
std::sort(desired_urls.begin(), desired_urls.end());
......@@ -65,21 +38,7 @@ void PendingAppManager::SynchronizeInstalledApps(
UninstallApps(
base::STLSetDifference<std::vector<GURL>>(current_urls, desired_urls),
base::DoNothing());
InstallApps(std::move(desired_apps), base::DoNothing());
}
std::ostream& operator<<(std::ostream& out,
const PendingAppManager::AppInfo& app_info) {
return out << "url: " << app_info.url << "\n launch_container: "
<< static_cast<int32_t>(app_info.launch_container)
<< "\n install_source: "
<< static_cast<int32_t>(app_info.install_source)
<< "\n create_shortcuts: " << app_info.create_shortcuts
<< "\n override_previous_user_uninstall: "
<< app_info.override_previous_user_uninstall
<< "\n bypass_service_worker_check: "
<< app_info.bypass_service_worker_check
<< "\n require_manifest: " << app_info.require_manifest;
InstallApps(std::move(desired_apps_install_options), base::DoNothing());
}
} // namespace web_app
......@@ -12,13 +12,12 @@
#include "base/callback_forward.h"
#include "base/macros.h"
#include "chrome/browser/web_applications/components/install_options.h"
#include "url/gurl.h"
namespace web_app {
enum class InstallResultCode;
enum class InstallSource;
enum class LaunchContainer;
// PendingAppManager installs, uninstalls, and updates apps.
//
......@@ -36,83 +35,53 @@ class PendingAppManager {
using UninstallCallback =
base::RepeatingCallback<void(const GURL& app_url, bool succeeded)>;
struct AppInfo {
AppInfo(const GURL& url,
LaunchContainer launch_container,
InstallSource install_source);
~AppInfo();
AppInfo(const AppInfo& other);
AppInfo(AppInfo&& other);
AppInfo& operator=(const AppInfo& other);
bool operator==(const AppInfo& other) const;
GURL url;
LaunchContainer launch_container;
InstallSource install_source;
bool create_shortcuts = true;
// Whether the app should be reinstalled even if the user has previously
// uninstalled it.
bool override_previous_user_uninstall = false;
// This must only be used by pre-installed default or system apps that are
// valid PWAs if loading the real service worker is too costly to verify
// programmatically.
bool bypass_service_worker_check = false;
// This should be used for installing all default apps so that good metadata
// is ensured.
bool require_manifest = false;
// Whether the app should be reinstalled even if it is already installed.
bool always_update = false;
};
PendingAppManager();
virtual ~PendingAppManager();
// Queues an installation operation with the highest priority. Essentially
// installing the app immediately if there are no ongoing operations or
// installing the app right after the current operation finishes. Runs its
// callback with the URL in |app_to_install| and with the id of the installed
// callback with the URL in |install_options| and with the id of the installed
// app or an empty string if the installation fails.
//
// Fails if the same operation has been queued before. Should only be used in
// response to a user action e.g. the user clicked an install button.
virtual void Install(AppInfo app_to_install,
virtual void Install(InstallOptions install_options,
OnceInstallCallback callback) = 0;
// Adds |apps_to_install| to the queue of operations. Runs |callback|
// with the URL of the corresponding AppInfo in |apps_to_install| and with the
// id of the installed app or an empty string if the installation fails. Runs
// |callback| for every completed installation - whether or not the
// installation actually succeeded.
virtual void InstallApps(std::vector<AppInfo> apps_to_install,
// Adds a task to the queue of operations for each InstallOptions in
// |install_options_list|. Runs |callback| with the URL of the corresponding
// InstallOptions in |install_options_list| and with the id of the installed
// app or an empty string if the installation fails. Runs |callback| for every
// completed installation - whether or not the installation actually
// succeeded.
virtual void InstallApps(std::vector<InstallOptions> install_options_list,
const RepeatingInstallCallback& callback) = 0;
// Adds |apps_to_uninstall| to the queue of operations. Runs |callback|
// with the URL of the corresponding app in |apps_to_install| and with a
// bool indicating whether or not the uninstall succeeded. Runs |callback|
// for every completed uninstallation - whether or not the uninstallation
// actually succeeded.
virtual void UninstallApps(std::vector<GURL> apps_to_uninstall,
// Adds a task to the queue of operations for each GURL in
// |uninstall_urls|. Runs |callback| with the URL of the corresponding
// app in |uninstall_urls| and with a bool indicating whether or not the
// uninstall succeeded. Runs |callback| for every completed uninstallation -
// whether or not the uninstallation actually succeeded.
virtual void UninstallApps(std::vector<GURL> uninstall_urls,
const UninstallCallback& callback) = 0;
// Returns the URLs of those apps installed from |install_source|.
virtual std::vector<GURL> GetInstalledAppUrls(
InstallSource install_source) const = 0;
// Installs |desired_apps| and uninstalls any apps in
// GetInstalledAppUrls(install_source) that are not in |desired_apps|'s URLs.
// Installs an app for each InstallOptions in |desired_apps_install_options|
// and uninstalls any apps in GetInstalledAppUrls(install_source) that are not
// in |desired_apps_install_options|'s URLs.
//
// All apps in |desired_apps| should have |install_source| as their source.
// All apps in |desired_apps_install_options| should have |install_source| as
// their source.
//
// Note that this returns after queueing work (installation and
// uninstallation) to be done. It does not wait until that work is complete.
void SynchronizeInstalledApps(std::vector<AppInfo> desired_apps,
InstallSource install_source);
void SynchronizeInstalledApps(
std::vector<InstallOptions> desired_apps_install_options,
InstallSource install_source);
// Returns the app id for |url| if the PendingAppManager is aware of it.
virtual base::Optional<std::string> LookupAppId(const GURL& url) const = 0;
......@@ -121,9 +90,6 @@ class PendingAppManager {
DISALLOW_COPY_AND_ASSIGN(PendingAppManager);
};
std::ostream& operator<<(std::ostream& out,
const PendingAppManager::AppInfo& app_info);
} // namespace web_app
#endif // CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_PENDING_APP_MANAGER_H_
......@@ -19,13 +19,13 @@ class PendingAppManagerTest : public testing::Test {
void Sync(std::vector<GURL> urls) {
pending_app_manager_.ResetCounts();
std::vector<PendingAppManager::AppInfo> app_infos;
std::vector<InstallOptions> install_options_list;
for (const auto& url : urls) {
app_infos.emplace_back(url, LaunchContainer::kWindow,
InstallSource::kInternal);
install_options_list.emplace_back(url, LaunchContainer::kWindow,
InstallSource::kInternal);
}
pending_app_manager_.SynchronizeInstalledApps(std::move(app_infos),
InstallSource::kInternal);
pending_app_manager_.SynchronizeInstalledApps(
std::move(install_options_list), InstallSource::kInternal);
}
void Expect(int deduped_install_count,
......
......@@ -24,31 +24,31 @@ void TestPendingAppManager::SimulatePreviouslyInstalledApp(
installed_apps_[url] = install_source;
}
void TestPendingAppManager::Install(AppInfo app_to_install,
void TestPendingAppManager::Install(InstallOptions install_options,
OnceInstallCallback callback) {
// TODO(nigeltao): Add error simulation when error codes are added to the API.
auto i = installed_apps_.find(app_to_install.url);
auto i = installed_apps_.find(install_options.url);
if (i == installed_apps_.end()) {
installed_apps_[app_to_install.url] = app_to_install.install_source;
installed_apps_[install_options.url] = install_options.install_source;
deduped_install_count_++;
}
install_requests_.push_back(std::move(app_to_install));
install_requests_.push_back(std::move(install_options));
std::move(callback).Run(install_requests().back().url,
InstallResultCode::kSuccess);
}
void TestPendingAppManager::InstallApps(
std::vector<AppInfo> apps_to_install,
std::vector<InstallOptions> install_options_list,
const RepeatingInstallCallback& callback) {
for (auto& app : apps_to_install)
Install(std::move(app), callback);
for (auto& install_options : install_options_list)
Install(std::move(install_options), callback);
}
void TestPendingAppManager::UninstallApps(std::vector<GURL> urls_to_uninstall,
void TestPendingAppManager::UninstallApps(std::vector<GURL> uninstall_urls,
const UninstallCallback& callback) {
for (auto& url : urls_to_uninstall) {
for (auto& url : uninstall_urls) {
auto i = installed_apps_.find(url);
if (i != installed_apps_.end()) {
installed_apps_.erase(i);
......
......@@ -24,7 +24,7 @@ class TestPendingAppManager : public PendingAppManager {
// InstallApps or UninstallApps arguments do. The deduped_foo_count methods
// only count new installs or new uninstalls.
const std::vector<AppInfo>& install_requests() const {
const std::vector<InstallOptions>& install_requests() const {
return install_requests_;
}
const std::vector<GURL>& uninstall_requests() const {
......@@ -43,17 +43,18 @@ class TestPendingAppManager : public PendingAppManager {
InstallSource install_source);
// PendingAppManager:
void Install(AppInfo app_to_install, OnceInstallCallback callback) override;
void InstallApps(std::vector<AppInfo> apps_to_install,
void Install(InstallOptions install_options,
OnceInstallCallback callback) override;
void InstallApps(std::vector<InstallOptions> install_options_list,
const RepeatingInstallCallback& callback) override;
void UninstallApps(std::vector<GURL> urls_to_uninstall,
void UninstallApps(std::vector<GURL> uninstall_urls,
const UninstallCallback& callback) override;
std::vector<GURL> GetInstalledAppUrls(
InstallSource install_source) const override;
base::Optional<std::string> LookupAppId(const GURL& url) const override;
private:
std::vector<AppInfo> install_requests_;
std::vector<InstallOptions> install_requests_;
std::vector<GURL> uninstall_requests_;
int deduped_install_count_;
......
......@@ -56,10 +56,10 @@ void BookmarkAppInstallationTask::CreateTabHelpers(
BookmarkAppInstallationTask::BookmarkAppInstallationTask(
Profile* profile,
web_app::PendingAppManager::AppInfo app_info)
web_app::InstallOptions install_options)
: profile_(profile),
extension_ids_map_(profile_->GetPrefs()),
app_info_(std::move(app_info)),
install_options_(std::move(install_options)),
helper_factory_(base::BindRepeating(&BookmarkAppHelperCreateWrapper)),
data_retriever_(std::make_unique<web_app::WebAppDataRetriever>()) {}
......@@ -97,7 +97,7 @@ void BookmarkAppInstallationTask::OnGetWebApplicationInfo(
}
auto install_source = WebappInstallSource::COUNT;
switch (app_info_.install_source) {
switch (install_options_.install_source) {
case web_app::InstallSource::kInternal:
install_source = WebappInstallSource::INTERNAL_DEFAULT;
break;
......@@ -117,7 +117,7 @@ void BookmarkAppInstallationTask::OnGetWebApplicationInfo(
helper_ = helper_factory_.Run(profile_, *web_app_info, web_contents,
install_source);
switch (app_info_.launch_container) {
switch (install_options_.launch_container) {
case web_app::LaunchContainer::kDefault:
break;
case web_app::LaunchContainer::kTab:
......@@ -128,7 +128,7 @@ void BookmarkAppInstallationTask::OnGetWebApplicationInfo(
break;
}
switch (app_info_.install_source) {
switch (install_options_.install_source) {
// TODO(nigeltao/ortuno): should these two cases lead to different
// Manifest::Location values: INTERNAL vs EXTERNAL_PREF_DOWNLOAD?
case web_app::InstallSource::kInternal:
......@@ -146,13 +146,13 @@ void BookmarkAppInstallationTask::OnGetWebApplicationInfo(
break;
}
if (!app_info_.create_shortcuts)
if (!install_options_.create_shortcuts)
helper_->set_skip_shortcut_creation();
if (app_info_.bypass_service_worker_check)
if (install_options_.bypass_service_worker_check)
helper_->set_bypass_service_worker_check();
if (app_info_.require_manifest)
if (install_options_.require_manifest)
helper_->set_require_manifest();
helper_->Create(base::Bind(&BookmarkAppInstallationTask::OnInstalled,
......@@ -165,8 +165,8 @@ void BookmarkAppInstallationTask::OnInstalled(
const Extension* extension,
const WebApplicationInfo& web_app_info) {
if (extension) {
extension_ids_map_.Insert(app_info_.url, extension->id(),
app_info_.install_source);
extension_ids_map_.Insert(install_options_.url, extension->id(),
install_options_.install_source);
std::move(result_callback)
.Run(Result(web_app::InstallResultCode::kSuccess, extension->id()));
return;
......
......@@ -60,19 +60,18 @@ class BookmarkAppInstallationTask {
static void CreateTabHelpers(content::WebContents* web_contents);
// Constructs a task that will install a BookmarkApp-based Shortcut or Web App
// for |profile|. |app_info| will be used to decide some of the
// for |profile|. |install_options| will be used to decide some of the
// properties of the installed app e.g. open in a tab vs. window, installed by
// policy, etc.
explicit BookmarkAppInstallationTask(
Profile* profile,
web_app::PendingAppManager::AppInfo app_info);
explicit BookmarkAppInstallationTask(Profile* profile,
web_app::InstallOptions install_options);
virtual ~BookmarkAppInstallationTask();
virtual void Install(content::WebContents* web_contents,
ResultCallback callback);
const web_app::PendingAppManager::AppInfo& app_info() { return app_info_; }
const web_app::InstallOptions& install_options() { return install_options_; }
void SetBookmarkAppHelperFactoryForTesting(
BookmarkAppHelperFactory helper_factory);
......@@ -92,7 +91,7 @@ class BookmarkAppInstallationTask {
web_app::ExtensionIdsMap extension_ids_map_;
const web_app::PendingAppManager::AppInfo app_info_;
const web_app::InstallOptions install_options_;
// We temporarily use a BookmarkAppHelper until the WebApp and WebShortcut
// installation tasks reach feature parity with BookmarkAppHelper.
......
......@@ -173,9 +173,9 @@ TEST_F(BookmarkAppInstallationTaskTest,
const GURL app_url(kWebAppUrl);
auto task = std::make_unique<BookmarkAppInstallationTask>(
profile(), web_app::PendingAppManager::AppInfo(
app_url, web_app::LaunchContainer::kDefault,
web_app::InstallSource::kInternal));
profile(),
web_app::InstallOptions(app_url, web_app::LaunchContainer::kDefault,
web_app::InstallSource::kInternal));
SetTestingFactories(task.get(), app_url);
......@@ -209,9 +209,9 @@ TEST_F(BookmarkAppInstallationTaskTest,
const GURL app_url(kWebAppUrl);
auto task = std::make_unique<BookmarkAppInstallationTask>(
profile(), web_app::PendingAppManager::AppInfo(
app_url, web_app::LaunchContainer::kWindow,
web_app::InstallSource::kInternal));
profile(),
web_app::InstallOptions(app_url, web_app::LaunchContainer::kWindow,
web_app::InstallSource::kInternal));
SetTestingFactories(task.get(), app_url);
......@@ -239,12 +239,12 @@ TEST_F(BookmarkAppInstallationTaskTest,
WebAppOrShortcutFromContents_NoShortcuts) {
const GURL app_url(kWebAppUrl);
web_app::PendingAppManager::AppInfo app_info(
app_url, web_app::LaunchContainer::kWindow,
web_app::InstallSource::kInternal);
app_info.create_shortcuts = false;
web_app::InstallOptions install_options(app_url,
web_app::LaunchContainer::kWindow,
web_app::InstallSource::kInternal);
install_options.create_shortcuts = false;
auto task = std::make_unique<BookmarkAppInstallationTask>(
profile(), std::move(app_info));
profile(), std::move(install_options));
SetTestingFactories(task.get(), app_url);
......@@ -265,11 +265,11 @@ TEST_F(BookmarkAppInstallationTaskTest,
WebAppOrShortcutFromContents_ForcedContainerWindow) {
const GURL app_url(kWebAppUrl);
auto app_info = web_app::PendingAppManager::AppInfo(
app_url, web_app::LaunchContainer::kWindow,
web_app::InstallSource::kInternal);
auto install_options =
web_app::InstallOptions(app_url, web_app::LaunchContainer::kWindow,
web_app::InstallSource::kInternal);
auto task = std::make_unique<BookmarkAppInstallationTask>(
profile(), std::move(app_info));
profile(), std::move(install_options));
SetTestingFactories(task.get(), app_url);
task->Install(
......@@ -288,11 +288,11 @@ TEST_F(BookmarkAppInstallationTaskTest,
WebAppOrShortcutFromContents_ForcedContainerTab) {
const GURL app_url(kWebAppUrl);
auto app_info = web_app::PendingAppManager::AppInfo(
app_url, web_app::LaunchContainer::kTab,
web_app::InstallSource::kInternal);
auto install_options =
web_app::InstallOptions(app_url, web_app::LaunchContainer::kTab,
web_app::InstallSource::kInternal);
auto task = std::make_unique<BookmarkAppInstallationTask>(
profile(), std::move(app_info));
profile(), std::move(install_options));
SetTestingFactories(task.get(), app_url);
task->Install(
......@@ -311,11 +311,11 @@ TEST_F(BookmarkAppInstallationTaskTest,
WebAppOrShortcutFromContents_DefaultApp) {
const GURL app_url(kWebAppUrl);
auto app_info = web_app::PendingAppManager::AppInfo(
app_url, web_app::LaunchContainer::kDefault,
web_app::InstallSource::kInternal);
auto install_options =
web_app::InstallOptions(app_url, web_app::LaunchContainer::kDefault,
web_app::InstallSource::kInternal);
auto task = std::make_unique<BookmarkAppInstallationTask>(
profile(), std::move(app_info));
profile(), std::move(install_options));
SetTestingFactories(task.get(), app_url);
task->Install(
......@@ -334,11 +334,11 @@ TEST_F(BookmarkAppInstallationTaskTest,
WebAppOrShortcutFromContents_AppFromPolicy) {
const GURL app_url(kWebAppUrl);
auto app_info = web_app::PendingAppManager::AppInfo(
app_url, web_app::LaunchContainer::kDefault,
web_app::InstallSource::kExternalPolicy);
auto install_options =
web_app::InstallOptions(app_url, web_app::LaunchContainer::kDefault,
web_app::InstallSource::kExternalPolicy);
auto task = std::make_unique<BookmarkAppInstallationTask>(
profile(), std::move(app_info));
profile(), std::move(install_options));
SetTestingFactories(task.get(), app_url);
task->Install(
......
......@@ -22,9 +22,9 @@ namespace {
std::unique_ptr<BookmarkAppInstallationTask> InstallationTaskCreateWrapper(
Profile* profile,
web_app::PendingAppManager::AppInfo app_info) {
return std::make_unique<BookmarkAppInstallationTask>(profile,
std::move(app_info));
web_app::InstallOptions install_options) {
return std::make_unique<BookmarkAppInstallationTask>(
profile, std::move(install_options));
}
} // namespace
......@@ -52,10 +52,10 @@ PendingBookmarkAppManager::PendingBookmarkAppManager(
PendingBookmarkAppManager::~PendingBookmarkAppManager() = default;
void PendingBookmarkAppManager::Install(AppInfo app_to_install,
void PendingBookmarkAppManager::Install(web_app::InstallOptions install_options,
OnceInstallCallback callback) {
pending_tasks_and_callbacks_.push_front(std::make_unique<TaskAndCallback>(
task_factory_.Run(profile_, std::move(app_to_install)),
task_factory_.Run(profile_, std::move(install_options)),
std::move(callback)));
base::ThreadTaskRunnerHandle::Get()->PostTask(
......@@ -65,11 +65,11 @@ void PendingBookmarkAppManager::Install(AppInfo app_to_install,
}
void PendingBookmarkAppManager::InstallApps(
std::vector<AppInfo> apps_to_install,
std::vector<web_app::InstallOptions> install_options_list,
const RepeatingInstallCallback& callback) {
for (auto& app_to_install : apps_to_install) {
for (auto& install_options : install_options_list) {
pending_tasks_and_callbacks_.push_back(std::make_unique<TaskAndCallback>(
task_factory_.Run(profile_, std::move(app_to_install)), callback));
task_factory_.Run(profile_, std::move(install_options)), callback));
}
base::ThreadTaskRunnerHandle::Get()->PostTask(
......@@ -79,11 +79,10 @@ void PendingBookmarkAppManager::InstallApps(
}
void PendingBookmarkAppManager::UninstallApps(
std::vector<GURL> apps_to_uninstall,
std::vector<GURL> uninstall_urls,
const UninstallCallback& callback) {
for (auto& app_to_uninstall : apps_to_uninstall) {
callback.Run(app_to_uninstall,
uninstaller_->UninstallApp(app_to_uninstall));
for (auto& url : uninstall_urls) {
callback.Run(url, uninstaller_->UninstallApp(url));
}
}
......@@ -135,27 +134,27 @@ void PendingBookmarkAppManager::MaybeStartNextInstallation() {
std::move(pending_tasks_and_callbacks_.front());
pending_tasks_and_callbacks_.pop_front();
const web_app::PendingAppManager::AppInfo& app_info =
front->task->app_info();
const web_app::InstallOptions& install_options =
front->task->install_options();
if (app_info.always_update) {
if (install_options.always_update) {
StartInstallationTask(std::move(front));
return;
}
base::Optional<std::string> extension_id =
extension_ids_map_.LookupExtensionId(app_info.url);
extension_ids_map_.LookupExtensionId(install_options.url);
if (extension_id) {
base::Optional<bool> opt =
IsExtensionPresentAndInstalled(extension_id.value());
if (opt.has_value()) {
bool installed = opt.value();
if (installed || !app_info.override_previous_user_uninstall) {
if (installed || !install_options.override_previous_user_uninstall) {
// TODO(crbug.com/878262): Handle the case where the app is already
// installed but from a different source.
std::move(front->callback)
.Run(app_info.url,
.Run(install_options.url,
installed
? web_app::InstallResultCode::kAlreadyInstalled
: web_app::InstallResultCode::kPreviouslyUninstalled);
......@@ -177,7 +176,7 @@ void PendingBookmarkAppManager::StartInstallationTask(
CreateWebContentsIfNecessary();
url_loader_->LoadUrl(current_task_and_callback_->task->app_info().url,
url_loader_->LoadUrl(current_task_and_callback_->task->install_options().url,
web_contents_.get(),
base::BindOnce(&PendingBookmarkAppManager::OnUrlLoaded,
weak_ptr_factory_.GetWeakPtr()));
......@@ -232,7 +231,7 @@ void PendingBookmarkAppManager::CurrentInstallationFinished(
std::unique_ptr<TaskAndCallback> task_and_callback;
task_and_callback.swap(current_task_and_callback_);
std::move(task_and_callback->callback)
.Run(task_and_callback->task->app_info().url, install_result_code);
.Run(task_and_callback->task->install_options().url, install_result_code);
}
} // namespace extensions
......@@ -14,6 +14,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "chrome/browser/web_applications/components/install_options.h"
#include "chrome/browser/web_applications/components/pending_app_manager.h"
#include "chrome/browser/web_applications/components/web_app_url_loader.h"
#include "chrome/browser/web_applications/extensions/bookmark_app_installation_task.h"
......@@ -42,18 +43,19 @@ class PendingBookmarkAppManager final : public web_app::PendingAppManager {
public:
using WebContentsFactory =
base::RepeatingCallback<std::unique_ptr<content::WebContents>(Profile*)>;
using TaskFactory = base::RepeatingCallback<
std::unique_ptr<BookmarkAppInstallationTask>(Profile*, AppInfo)>;
using TaskFactory = base::RepeatingCallback<std::unique_ptr<
BookmarkAppInstallationTask>(Profile*, web_app::InstallOptions)>;
explicit PendingBookmarkAppManager(Profile* profile,
web_app::AppRegistrar* registrar_);
~PendingBookmarkAppManager() override;
// web_app::PendingAppManager
void Install(AppInfo app_to_install, OnceInstallCallback callback) override;
void InstallApps(std::vector<AppInfo> apps_to_install,
void Install(web_app::InstallOptions install_options,
OnceInstallCallback callback) override;
void InstallApps(std::vector<web_app::InstallOptions> install_options_list,
const RepeatingInstallCallback& callback) override;
void UninstallApps(std::vector<GURL> apps_to_uninstall,
void UninstallApps(std::vector<GURL> uninstall_urls,
const UninstallCallback& callback) override;
std::vector<GURL> GetInstalledAppUrls(
web_app::InstallSource install_source) const override;
......
......@@ -27,23 +27,23 @@
namespace extensions {
web_app::PendingAppManager::AppInfo CreateAppInfo(const GURL& url) {
web_app::PendingAppManager::AppInfo app_info(
url, web_app::LaunchContainer::kWindow,
web_app::InstallSource::kInternal);
web_app::InstallOptions CreateInstallOptions(const GURL& url) {
web_app::InstallOptions install_options(url,
web_app::LaunchContainer::kWindow,
web_app::InstallSource::kInternal);
// Avoid creating real shortcuts in tests.
app_info.create_shortcuts = false;
return app_info;
install_options.create_shortcuts = false;
return install_options;
}
class PendingBookmarkAppManagerBrowserTest : public InProcessBrowserTest {
protected:
void InstallApp(web_app::PendingAppManager::AppInfo app_info) {
void InstallApp(web_app::InstallOptions install_options) {
base::RunLoop run_loop;
web_app::WebAppProvider::Get(browser()->profile())
->pending_app_manager()
.Install(std::move(app_info),
.Install(std::move(install_options),
base::BindLambdaForTesting(
[this, &run_loop](const GURL& provided_url,
web_app::InstallResultCode code) {
......@@ -62,7 +62,7 @@ class PendingBookmarkAppManagerBrowserTest : public InProcessBrowserTest {
IN_PROC_BROWSER_TEST_F(PendingBookmarkAppManagerBrowserTest, InstallSucceeds) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/banners/manifest_test_page.html"));
InstallApp(CreateAppInfo(url));
InstallApp(CreateInstallOptions(url));
EXPECT_EQ(web_app::InstallResultCode::kSuccess, result_code_.value());
base::Optional<std::string> id =
web_app::ExtensionIdsMap(browser()->profile()->GetPrefs())
......@@ -81,13 +81,13 @@ IN_PROC_BROWSER_TEST_F(PendingBookmarkAppManagerBrowserTest,
ShutdownWithPendingInstallation) {
ASSERT_TRUE(embedded_test_server()->Start());
web_app::PendingAppManager::AppInfo app_info = CreateAppInfo(
web_app::InstallOptions install_options = CreateInstallOptions(
embedded_test_server()->GetURL("/banners/manifest_test_page.html"));
// Start an installation but don't wait for it to finish.
web_app::WebAppProvider::Get(browser()->profile())
->pending_app_manager()
.Install(std::move(app_info), base::DoNothing());
.Install(std::move(install_options), base::DoNothing());
// The browser should shutdown cleanly even if there is a pending
// installation.
......@@ -101,9 +101,9 @@ IN_PROC_BROWSER_TEST_F(PendingBookmarkAppManagerBrowserTest,
GURL url(embedded_test_server()->GetURL(
"/banners/manifest_no_service_worker.html"));
web_app::PendingAppManager::AppInfo app_info = CreateAppInfo(url);
app_info.bypass_service_worker_check = true;
InstallApp(std::move(app_info));
web_app::InstallOptions install_options = CreateInstallOptions(url);
install_options.bypass_service_worker_check = true;
InstallApp(std::move(install_options));
const extensions::Extension* app =
extensions::util::GetInstalledPwaForUrl(browser()->profile(), url);
EXPECT_TRUE(app);
......@@ -117,8 +117,8 @@ IN_PROC_BROWSER_TEST_F(PendingBookmarkAppManagerBrowserTest,
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL(
"/banners/manifest_no_service_worker.html"));
web_app::PendingAppManager::AppInfo app_info = CreateAppInfo(url);
InstallApp(std::move(app_info));
web_app::InstallOptions install_options = CreateInstallOptions(url);
InstallApp(std::move(install_options));
const extensions::Extension* app =
extensions::util::GetInstalledPwaForUrl(browser()->profile(), url);
EXPECT_FALSE(app);
......@@ -132,9 +132,9 @@ IN_PROC_BROWSER_TEST_F(PendingBookmarkAppManagerBrowserTest, AlwaysUpdate) {
GURL url(embedded_test_server()->GetURL(
"/banners/"
"manifest_test_page.html?manifest=manifest_short_name_only.json"));
web_app::PendingAppManager::AppInfo app_info = CreateAppInfo(url);
app_info.always_update = true;
InstallApp(std::move(app_info));
web_app::InstallOptions install_options = CreateInstallOptions(url);
install_options.always_update = true;
InstallApp(std::move(install_options));
const extensions::Extension* app =
extensions::util::GetInstalledPwaForUrl(browser()->profile(), url);
......@@ -144,9 +144,9 @@ IN_PROC_BROWSER_TEST_F(PendingBookmarkAppManagerBrowserTest, AlwaysUpdate) {
{
GURL url(
embedded_test_server()->GetURL("/banners/manifest_test_page.html"));
web_app::PendingAppManager::AppInfo app_info = CreateAppInfo(url);
app_info.always_update = true;
InstallApp(std::move(app_info));
web_app::InstallOptions install_options = CreateInstallOptions(url);
install_options.always_update = true;
InstallApp(std::move(install_options));
const extensions::Extension* app =
extensions::util::GetInstalledPwaForUrl(browser()->profile(), url);
......@@ -162,7 +162,7 @@ IN_PROC_BROWSER_TEST_F(PendingBookmarkAppManagerBrowserTest,
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL(
"/banners/manifest_test_page.html?manifest=manifest_chrome_url.json"));
InstallApp(CreateAppInfo(url));
InstallApp(CreateInstallOptions(url));
EXPECT_EQ(web_app::InstallResultCode::kSuccess, result_code_.value());
base::Optional<std::string> id =
web_app::ExtensionIdsMap(browser()->profile()->GetPrefs())
......@@ -186,9 +186,9 @@ IN_PROC_BROWSER_TEST_F(PendingBookmarkAppManagerBrowserTest,
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(
embedded_test_server()->GetURL("/banners/no_manifest_test_page.html"));
web_app::PendingAppManager::AppInfo app_info = CreateAppInfo(url);
app_info.require_manifest = true;
InstallApp(std::move(app_info));
web_app::InstallOptions install_options = CreateInstallOptions(url);
install_options.require_manifest = true;
InstallApp(std::move(install_options));
EXPECT_EQ(web_app::InstallResultCode::kFailedUnknownReason,
result_code_.value());
......
......@@ -86,9 +86,8 @@ bool IsFeatureEnabled(const std::string& feature_name) {
return base::FeatureList::IsEnabled(*it->second);
}
std::vector<web_app::PendingAppManager::AppInfo> ScanDir(
const base::FilePath& dir,
const std::string& user_type) {
std::vector<web_app::InstallOptions> ScanDir(const base::FilePath& dir,
const std::string& user_type) {
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
base::BlockingType::MAY_BLOCK);
base::FilePath::StringType extension(FILE_PATH_LITERAL(".json"));
......@@ -96,7 +95,7 @@ std::vector<web_app::PendingAppManager::AppInfo> ScanDir(
false, // Recursive.
base::FileEnumerator::FILES);
std::vector<web_app::PendingAppManager::AppInfo> app_infos;
std::vector<web_app::InstallOptions> install_options_list;
for (base::FilePath file = json_files.Next(); !file.empty();
file = json_files.Next()) {
......@@ -172,16 +171,16 @@ std::vector<web_app::PendingAppManager::AppInfo> ScanDir(
continue;
}
web_app::PendingAppManager::AppInfo info(
web_app::InstallOptions install_options(
std::move(app_url), launch_container,
web_app::InstallSource::kExternalDefault);
info.create_shortcuts = create_shortcuts;
info.require_manifest = true;
install_options.create_shortcuts = create_shortcuts;
install_options.require_manifest = true;
app_infos.push_back(std::move(info));
install_options_list.push_back(std::move(install_options));
}
return app_infos;
return install_options_list;
}
base::FilePath DetermineScanDir(const Profile* profile) {
......@@ -212,9 +211,9 @@ base::FilePath DetermineScanDir(const Profile* profile) {
namespace web_app {
std::vector<web_app::PendingAppManager::AppInfo>
ScanDirForExternalWebAppsForTesting(const base::FilePath& dir,
Profile* profile) {
std::vector<web_app::InstallOptions> ScanDirForExternalWebAppsForTesting(
const base::FilePath& dir,
Profile* profile) {
return ScanDir(dir, apps::DetermineUserType(profile));
}
......@@ -223,7 +222,7 @@ void ScanForExternalWebApps(Profile* profile,
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
const base::FilePath dir = DetermineScanDir(profile);
if (dir.empty()) {
std::move(callback).Run(std::vector<web_app::PendingAppManager::AppInfo>());
std::move(callback).Run(std::vector<web_app::InstallOptions>());
return;
}
// Do a two-part callback dance, across different TaskRunners.
......@@ -233,7 +232,7 @@ void ScanForExternalWebApps(Profile* profile,
// base::PostTaskWithTraitsAndReplyWithResult will bounce us back to the
// originating thread (the UI thread).
//
// 2. In |callback|, forward the vector of AppInfo's on to the
// 2. In |callback|, forward the vector of InstallOptions on to the
// pending_app_manager_, which can only be called on the UI thread.
base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE,
......
......@@ -19,7 +19,7 @@ class Profile;
namespace web_app {
using ScanForExternalWebAppsCallback =
base::OnceCallback<void(std::vector<web_app::PendingAppManager::AppInfo>)>;
base::OnceCallback<void(std::vector<web_app::InstallOptions>)>;
void ScanForExternalWebApps(Profile* profile,
ScanForExternalWebAppsCallback callback);
......@@ -29,9 +29,9 @@ void ScanForExternalWebApps(Profile* profile,
// at https://developer.chrome.com/apps/external_extensions
//
// This function performs file I/O, and must not be scheduled on UI threads.
std::vector<web_app::PendingAppManager::AppInfo>
ScanDirForExternalWebAppsForTesting(const base::FilePath& dir,
Profile* profile);
std::vector<web_app::InstallOptions> ScanDirForExternalWebAppsForTesting(
const base::FilePath& dir,
Profile* profile);
} // namespace web_app
......
......@@ -58,7 +58,7 @@ void WebAppPolicyManager::InitChangeRegistrarAndRefreshPolicyInstalledApps() {
void WebAppPolicyManager::RefreshPolicyInstalledApps() {
const base::Value* web_apps =
pref_service_->GetList(prefs::kWebAppInstallForceList);
std::vector<PendingAppManager::AppInfo> apps_to_install;
std::vector<InstallOptions> install_options_list;
for (const base::Value& info : web_apps->GetList()) {
const base::Value& url = *info.FindKey(kUrlKey);
const base::Value* launch_container = info.FindKey(kLaunchContainerKey);
......@@ -75,17 +75,17 @@ void WebAppPolicyManager::RefreshPolicyInstalledApps() {
else
container = LaunchContainer::kTab;
web_app::PendingAppManager::AppInfo app_info(
web_app::InstallOptions install_options(
GURL(std::move(url.GetString())), container,
web_app::InstallSource::kExternalPolicy);
app_info.create_shortcuts = false;
install_options.create_shortcuts = false;
// There is a separate policy to create shortcuts/pin apps to shelf.
apps_to_install.push_back(std::move(app_info));
install_options_list.push_back(std::move(install_options));
}
pending_app_manager_->SynchronizeInstalledApps(
std::move(apps_to_install), InstallSource::kExternalPolicy);
std::move(install_options_list), InstallSource::kExternalPolicy);
}
} // namespace web_app
......@@ -35,15 +35,15 @@ base::flat_map<SystemAppType, GURL> CreateSystemWebApps() {
return urls;
}
PendingAppManager::AppInfo CreateAppInfoForSystemApp(const GURL& url) {
InstallOptions CreateInstallOptionsForSystemApp(const GURL& url) {
DCHECK_EQ(content::kChromeUIScheme, url.scheme());
web_app::PendingAppManager::AppInfo app_info(url, LaunchContainer::kWindow,
InstallSource::kSystemInstalled);
app_info.create_shortcuts = false;
app_info.bypass_service_worker_check = true;
app_info.always_update = true;
return app_info;
web_app::InstallOptions install_options(url, LaunchContainer::kWindow,
InstallSource::kSystemInstalled);
install_options.create_shortcuts = false;
install_options.bypass_service_worker_check = true;
install_options.always_update = true;
return install_options;
}
} // namespace
......@@ -83,15 +83,17 @@ bool SystemWebAppManager::IsEnabled() {
}
void SystemWebAppManager::StartAppInstallation() {
std::vector<PendingAppManager::AppInfo> apps_to_install;
std::vector<InstallOptions> install_options_list;
if (IsEnabled()) {
// Skipping this will uninstall all System Apps currently installed.
for (const auto& app : system_app_urls_)
apps_to_install.push_back(CreateAppInfoForSystemApp(app.second));
for (const auto& app : system_app_urls_) {
install_options_list.push_back(
CreateInstallOptionsForSystemApp(app.second));
}
}
pending_app_manager_->SynchronizeInstalledApps(
std::move(apps_to_install), InstallSource::kSystemInstalled);
std::move(install_options_list), InstallSource::kSystemInstalled);
}
} // namespace web_app
......@@ -229,9 +229,9 @@ void WebAppProvider::Reset() {
}
void WebAppProvider::OnScanForExternalWebApps(
std::vector<web_app::PendingAppManager::AppInfo> app_infos) {
std::vector<InstallOptions> desired_apps_install_options) {
pending_app_manager_->SynchronizeInstalledApps(
std::move(app_infos), InstallSource::kExternalDefault);
std::move(desired_apps_install_options), InstallSource::kExternalDefault);
}
} // namespace web_app
......@@ -100,8 +100,7 @@ class WebAppProvider : public WebAppProviderBase,
void Reset();
void OnScanForExternalWebApps(
std::vector<web_app::PendingAppManager::AppInfo>);
void OnScanForExternalWebApps(std::vector<InstallOptions>);
// New extension-independent subsystems:
std::unique_ptr<WebAppAudioFocusIdMap> audio_focus_id_map_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment