Commit 97ae1d33 authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

desktop-pwas: Create shortcuts for placeholder apps

InstallFinalizer does not create shortcuts automatically so we have
to create them in BookmarkAppInstallation task when installing a place-
holder app.

Also add a bool to control whether a desktop shortcut will be created
in addition to the applications menu one, since policy doesn't always
create desktop shortcuts.

Bug: 955926
Change-Id: I059257c5aa154caf336400e50cb6cb96f5c2ba1e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1580683Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#653507}
parent 8d54998b
......@@ -42,6 +42,7 @@ class InstallFinalizer {
virtual bool CanCreateOsShortcuts() const = 0;
virtual void CreateOsShortcuts(const AppId& app_id,
bool add_to_desktop,
CreateOsShortcutsCallback callback) = 0;
virtual bool CanPinAppToShelf() const = 0;
......
......@@ -113,9 +113,10 @@ bool BookmarkAppInstallFinalizer::CanCreateOsShortcuts() const {
void BookmarkAppInstallFinalizer::CreateOsShortcuts(
const web_app::AppId& app_id,
bool add_to_desktop,
CreateOsShortcutsCallback callback) {
const Extension* app = GetExtensionById(profile_, app_id);
BookmarkAppCreateOsShortcuts(profile_, app, true /* add_to_desktop */,
BookmarkAppCreateOsShortcuts(profile_, app, add_to_desktop,
std::move(callback));
}
......
......@@ -31,6 +31,7 @@ class BookmarkAppInstallFinalizer : public web_app::InstallFinalizer {
InstallFinalizedCallback callback) override;
bool CanCreateOsShortcuts() const override;
void CreateOsShortcuts(const web_app::AppId& app_id,
bool add_to_desktop,
CreateOsShortcutsCallback callback) override;
bool CanPinAppToShelf() const override;
void PinAppToShelf(const web_app::AppId& app_id) override;
......
......@@ -101,15 +101,44 @@ void BookmarkAppInstallationTask::OnWebAppInstalled(
ResultCallback result_callback,
const web_app::AppId& app_id,
web_app::InstallResultCode code) {
if (code == web_app::InstallResultCode::kSuccess) {
extension_ids_map_.Insert(install_options_.url, app_id,
install_options_.install_source);
extension_ids_map_.SetIsPlaceholder(install_options_.url, is_placeholder);
std::move(result_callback)
.Run(Result(web_app::InstallResultCode::kSuccess, app_id));
} else {
if (code != web_app::InstallResultCode::kSuccess) {
std::move(result_callback).Run(Result(code, base::nullopt));
return;
}
extension_ids_map_.Insert(install_options_.url, app_id,
install_options_.install_source);
extension_ids_map_.SetIsPlaceholder(install_options_.url, is_placeholder);
auto success_closure =
base::BindOnce(std::move(result_callback),
Result(web_app::InstallResultCode::kSuccess, app_id));
if (!is_placeholder) {
std::move(success_closure).Run();
return;
}
// Installation through InstallFinalizer doesn't create shortcuts so create
// them here.
if (install_options_.add_to_quick_launch_bar &&
install_finalizer_->CanPinAppToShelf()) {
install_finalizer_->PinAppToShelf(app_id);
}
// TODO(ortuno): Make adding a shortcut to the applications menu independent
// from adding a shortcut to desktop.
if (install_options_.add_to_applications_menu &&
install_finalizer_->CanCreateOsShortcuts()) {
install_finalizer_->CreateOsShortcuts(
app_id, install_options_.add_to_desktop,
base::BindOnce(
[](base::OnceClosure success_closure, bool shortcuts_created) {
// Even if the shortcuts failed to be created, we consider the
// installation successful since an app was created.
std::move(success_closure).Run();
},
std::move(success_closure)));
}
}
......
......@@ -471,6 +471,7 @@ TEST_F(BookmarkAppInstallationTaskTest, InstallPlaceholder) {
EXPECT_TRUE(IsPlaceholderApp(profile(), app_url()));
EXPECT_EQ(1, install_finalizer()->num_create_os_shortcuts_calls());
EXPECT_TRUE(install_finalizer()->finalized_policy_install());
std::unique_ptr<WebApplicationInfo> web_app_info =
install_finalizer()->web_app_info();
......
......@@ -51,6 +51,7 @@ bool TestInstallFinalizer::CanCreateOsShortcuts() const {
void TestInstallFinalizer::CreateOsShortcuts(
const AppId& app_id,
bool add_to_desktop,
CreateOsShortcutsCallback callback) {
++num_create_os_shortcuts_calls_;
base::ThreadTaskRunnerHandle::Get()->PostTask(
......
......@@ -26,6 +26,7 @@ class TestInstallFinalizer final : public InstallFinalizer {
InstallFinalizedCallback callback) override;
bool CanCreateOsShortcuts() const override;
void CreateOsShortcuts(const AppId& app_id,
bool add_to_desktop,
CreateOsShortcutsCallback callback) override;
bool CanPinAppToShelf() const override;
void PinAppToShelf(const AppId& app_id) override;
......
......@@ -105,6 +105,7 @@ bool WebAppInstallFinalizer::CanCreateOsShortcuts() const {
void WebAppInstallFinalizer::CreateOsShortcuts(
const AppId& app_id,
bool add_to_desktop,
CreateOsShortcutsCallback callback) {
// TODO(loyso): Implement it.
NOTIMPLEMENTED();
......
......@@ -31,6 +31,7 @@ class WebAppInstallFinalizer final : public InstallFinalizer {
InstallFinalizedCallback callback) override;
bool CanCreateOsShortcuts() const override;
void CreateOsShortcuts(const AppId& app_id,
bool add_to_desktop,
CreateOsShortcutsCallback callback) override;
bool CanPinAppToShelf() const override;
void PinAppToShelf(const AppId& app_id) override;
......
......@@ -240,7 +240,7 @@ void WebAppInstallTask::OnInstallFinalized(
&WebAppInstallTask::OnShortcutsCreated, weak_ptr_factory_.GetWeakPtr(),
std::move(web_app_info), app_id);
if (install_finalizer_->CanCreateOsShortcuts()) {
install_finalizer_->CreateOsShortcuts(app_id,
install_finalizer_->CreateOsShortcuts(app_id, /*add_to_dekstop=*/true,
std::move(create_shortcuts_callback));
} else {
std::move(create_shortcuts_callback).Run(false /* created_shortcuts */);
......
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