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