Commit 0d9d864b authored by Christopher Lam's avatar Christopher Lam Committed by Commit Bot

[System PWAs] Make System PWAs update on Chrome launch.

As a temporary measure, make System PWAs update on every Chrome launch.
This allows developers to see changes when they update manifests. This
will be replaced with a lighter, more robust system before consumer
launch.

Bug: 836128
Change-Id: I82febcd9b0f7ae5f8be401bdedbe4846008562f4
Reviewed-on: https://chromium-review.googlesource.com/c/1325595Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Commit-Queue: calamity <calamity@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607933}
parent d0348b42
...@@ -34,6 +34,7 @@ PendingAppManager::AppInfo CreateAppInfoForSystemApp(const GURL& url) { ...@@ -34,6 +34,7 @@ PendingAppManager::AppInfo CreateAppInfoForSystemApp(const GURL& url) {
InstallSource::kSystemInstalled); InstallSource::kSystemInstalled);
app_info.create_shortcuts = false; app_info.create_shortcuts = false;
app_info.bypass_service_worker_check = true; app_info.bypass_service_worker_check = true;
app_info.always_update = true;
return app_info; return app_info;
} }
......
...@@ -42,6 +42,7 @@ PendingAppManager::AppInfo GetWindowedAppInfo() { ...@@ -42,6 +42,7 @@ PendingAppManager::AppInfo GetWindowedAppInfo() {
InstallSource::kSystemInstalled); InstallSource::kSystemInstalled);
info.create_shortcuts = false; info.create_shortcuts = false;
info.bypass_service_worker_check = true; info.bypass_service_worker_check = true;
info.always_update = true;
return info; return info;
} }
......
...@@ -33,11 +33,12 @@ bool PendingAppManager::AppInfo::operator==( ...@@ -33,11 +33,12 @@ bool PendingAppManager::AppInfo::operator==(
const PendingAppManager::AppInfo& other) const { const PendingAppManager::AppInfo& other) const {
return std::tie(url, launch_container, install_source, create_shortcuts, return std::tie(url, launch_container, install_source, create_shortcuts,
override_previous_user_uninstall, bypass_service_worker_check, override_previous_user_uninstall, bypass_service_worker_check,
require_manifest) == require_manifest, always_update) ==
std::tie(other.url, other.launch_container, other.install_source, std::tie(other.url, other.launch_container, other.install_source,
other.create_shortcuts, other.create_shortcuts,
other.override_previous_user_uninstall, other.override_previous_user_uninstall,
other.bypass_service_worker_check, other.require_manifest); other.bypass_service_worker_check, other.require_manifest,
other.always_update);
} }
PendingAppManager::PendingAppManager() = default; PendingAppManager::PendingAppManager() = default;
......
...@@ -65,6 +65,9 @@ class PendingAppManager { ...@@ -65,6 +65,9 @@ class PendingAppManager {
// This should be used for installing all default apps so that good metadata // This should be used for installing all default apps so that good metadata
// is ensured. // is ensured.
bool require_manifest = false; bool require_manifest = false;
// Whether the app should be reinstalled even if it is already installed.
bool always_update = false;
}; };
PendingAppManager(); PendingAppManager();
......
...@@ -141,9 +141,6 @@ void PendingBookmarkAppManager::SetTimerForTesting( ...@@ -141,9 +141,6 @@ void PendingBookmarkAppManager::SetTimerForTesting(
timer_ = std::move(timer); timer_ = std::move(timer);
} }
// Returns (as the base::Optional part) whether or not there is already a known
// extension for the given ID. The bool inside the base::Optional is, when
// known, whether the extension is installed (true) or uninstalled (false).
base::Optional<bool> PendingBookmarkAppManager::IsExtensionPresentAndInstalled( base::Optional<bool> PendingBookmarkAppManager::IsExtensionPresentAndInstalled(
const std::string& extension_id) { const std::string& extension_id) {
if (ExtensionRegistry::Get(profile_)->GetExtensionById( if (ExtensionRegistry::Get(profile_)->GetExtensionById(
...@@ -169,6 +166,12 @@ void PendingBookmarkAppManager::MaybeStartNextInstallation() { ...@@ -169,6 +166,12 @@ void PendingBookmarkAppManager::MaybeStartNextInstallation() {
const web_app::PendingAppManager::AppInfo& app_info = const web_app::PendingAppManager::AppInfo& app_info =
front->task->app_info(); front->task->app_info();
if (app_info.always_update) {
StartInstallationTask(std::move(front));
return;
}
base::Optional<std::string> extension_id = base::Optional<std::string> extension_id =
extension_ids_map_.LookupExtensionId(app_info.url); extension_ids_map_.LookupExtensionId(app_info.url);
...@@ -189,27 +192,31 @@ void PendingBookmarkAppManager::MaybeStartNextInstallation() { ...@@ -189,27 +192,31 @@ void PendingBookmarkAppManager::MaybeStartNextInstallation() {
} }
} }
} }
StartInstallationTask(std::move(front));
current_task_and_callback_ = std::move(front);
CreateWebContentsIfNecessary();
Observe(web_contents_.get());
content::NavigationController::LoadURLParams load_params(
current_task_and_callback_->task->app_info().url);
load_params.transition_type = ui::PAGE_TRANSITION_GENERATED;
web_contents_->GetController().LoadURLWithParams(load_params);
timer_->Start(
FROM_HERE,
base::TimeDelta::FromSeconds(kSecondsToWaitForWebContentsLoad),
base::BindOnce(&PendingBookmarkAppManager::OnWebContentsLoadTimedOut,
weak_ptr_factory_.GetWeakPtr()));
return; return;
} }
web_contents_.reset(); web_contents_.reset();
} }
void PendingBookmarkAppManager::StartInstallationTask(
std::unique_ptr<TaskAndCallback> task) {
DCHECK(!current_task_and_callback_);
current_task_and_callback_ = std::move(task);
CreateWebContentsIfNecessary();
Observe(web_contents_.get());
content::NavigationController::LoadURLParams load_params(
current_task_and_callback_->task->app_info().url);
load_params.transition_type = ui::PAGE_TRANSITION_GENERATED;
web_contents_->GetController().LoadURLWithParams(load_params);
timer_->Start(
FROM_HERE, base::TimeDelta::FromSeconds(kSecondsToWaitForWebContentsLoad),
base::BindOnce(&PendingBookmarkAppManager::OnWebContentsLoadTimedOut,
weak_ptr_factory_.GetWeakPtr()));
}
void PendingBookmarkAppManager::CreateWebContentsIfNecessary() { void PendingBookmarkAppManager::CreateWebContentsIfNecessary() {
if (web_contents_) if (web_contents_)
return; return;
......
...@@ -62,11 +62,17 @@ class PendingBookmarkAppManager final : public web_app::PendingAppManager, ...@@ -62,11 +62,17 @@ class PendingBookmarkAppManager final : public web_app::PendingAppManager,
private: private:
struct TaskAndCallback; struct TaskAndCallback;
// Returns (as the base::Optional part) whether or not there is already a
// known extension for the given ID. The bool inside the base::Optional is,
// when known, whether the extension is installed (true) or uninstalled
// (false).
base::Optional<bool> IsExtensionPresentAndInstalled( base::Optional<bool> IsExtensionPresentAndInstalled(
const std::string& extension_id); const std::string& extension_id);
void MaybeStartNextInstallation(); void MaybeStartNextInstallation();
void StartInstallationTask(std::unique_ptr<TaskAndCallback> task);
void CreateWebContentsIfNecessary(); void CreateWebContentsIfNecessary();
void OnInstalled(BookmarkAppInstallationTask::Result result); void OnInstalled(BookmarkAppInstallationTask::Result result);
......
...@@ -123,6 +123,37 @@ IN_PROC_BROWSER_TEST_F(PendingBookmarkAppManagerBrowserTest, ...@@ -123,6 +123,37 @@ IN_PROC_BROWSER_TEST_F(PendingBookmarkAppManagerBrowserTest,
EXPECT_FALSE(app); EXPECT_FALSE(app);
} }
IN_PROC_BROWSER_TEST_F(PendingBookmarkAppManagerBrowserTest, AlwaysUpdate) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(features::kDesktopPWAWindowing);
ASSERT_TRUE(embedded_test_server()->Start());
{
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));
const extensions::Extension* app =
extensions::util::GetInstalledPwaForUrl(browser()->profile(), url);
EXPECT_TRUE(app);
EXPECT_EQ("Manifest", app->name());
}
{
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));
const extensions::Extension* app =
extensions::util::GetInstalledPwaForUrl(browser()->profile(), url);
EXPECT_TRUE(app);
EXPECT_EQ("Manifest test app", app->name());
}
}
// Test that adding a manifest that points to a chrome:// URL does not actually // Test that adding a manifest that points to a chrome:// URL does not actually
// install a bookmark app that points to a chrome:// URL. // install a bookmark app that points to a chrome:// URL.
IN_PROC_BROWSER_TEST_F(PendingBookmarkAppManagerBrowserTest, IN_PROC_BROWSER_TEST_F(PendingBookmarkAppManagerBrowserTest,
......
...@@ -575,6 +575,43 @@ TEST_F(PendingBookmarkAppManagerTest, Install_ConcurrentCallsSameApp) { ...@@ -575,6 +575,43 @@ TEST_F(PendingBookmarkAppManagerTest, Install_ConcurrentCallsSameApp) {
EXPECT_EQ(GURL(kFooWebAppUrl), install_callback_url()); EXPECT_EQ(GURL(kFooWebAppUrl), install_callback_url());
} }
TEST_F(PendingBookmarkAppManagerTest, Install_AlwaysUpdate) {
auto pending_app_manager = GetPendingBookmarkAppManagerWithTestFactories();
auto get_always_update_info = []() {
web_app::PendingAppManager::AppInfo info(
GURL(kFooWebAppUrl), web_app::LaunchContainer::kWindow,
web_app::InstallSource::kExternalPolicy);
info.always_update = true;
return info;
};
pending_app_manager->Install(
get_always_update_info(),
base::BindOnce(&PendingBookmarkAppManagerTest::InstallCallback,
base::Unretained(this)));
base::RunLoop().RunUntilIdle();
SuccessfullyLoad(GURL(kFooWebAppUrl));
EXPECT_EQ(1u, installation_task_run_count());
EXPECT_TRUE(app_installed());
EXPECT_EQ(GURL(kFooWebAppUrl), install_callback_url());
ResetResults();
pending_app_manager->Install(
get_always_update_info(),
base::BindOnce(&PendingBookmarkAppManagerTest::InstallCallback,
base::Unretained(this)));
base::RunLoop().RunUntilIdle();
SuccessfullyLoad(GURL(kFooWebAppUrl));
// The app is reinstalled even though it is already installed.
EXPECT_EQ(1u, installation_task_run_count());
EXPECT_TRUE(app_installed());
EXPECT_EQ(GURL(kFooWebAppUrl), install_callback_url());
}
TEST_F(PendingBookmarkAppManagerTest, Install_FailsLoadIncorrectURL) { TEST_F(PendingBookmarkAppManagerTest, Install_FailsLoadIncorrectURL) {
auto pending_app_manager = GetPendingBookmarkAppManagerWithTestFactories(); auto pending_app_manager = GetPendingBookmarkAppManagerWithTestFactories();
pending_app_manager->Install( pending_app_manager->Install(
......
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