Commit ea08dc28 authored by Carlos Frias's avatar Carlos Frias Committed by Commit Bot

DPWA: Add option to control registering file handlers in InstallOsHooks

This CL enables obtaining a finer control for OS hooks supported by
OSIntegrationManager::InstallOsHooks().

Currently, there is no option for file handlers and
file_handler_manager_->EnableAndRegisterOsFileHandlers()
is being called every time InstallOsHooks() is executed.

This CL adds the bitset OsHookType to InstallOsHooksOptions struct to
allow controlling which OS Hooks to install, including file handlers.

bool add_to_application_menu now becomes
os_hooks[OsHookType::kShortcuts].

bool run_on_os_login now becomes os_hooks[OsHookType::kRunOnOsLogin].

Bug: 1087219
Change-Id: Ib370c394235efe66fca23267928184b9841c76ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2373229
Commit-Queue: Carlos Frias <carlos.frias@microsoft.com>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807509}
parent 22c9ee2e
...@@ -970,10 +970,13 @@ void AppLauncherHandler::HandleInstallAppLocally(const base::ListValue* args) { ...@@ -970,10 +970,13 @@ void AppLauncherHandler::HandleInstallAppLocally(const base::ListValue* args) {
web_app_provider_->registry_controller().SetAppInstallTime(app_id, web_app_provider_->registry_controller().SetAppInstallTime(app_id,
base::Time::Now()); base::Time::Now());
web_app::InstallOsHooksOptions options; web_app::InstallOsHooksOptions options;
options.add_to_applications_menu = true;
options.add_to_desktop = true; options.add_to_desktop = true;
options.add_to_quick_launch_bar = false; options.add_to_quick_launch_bar = false;
options.run_on_os_login = false; options.os_hooks[web_app::OsHookType::kShortcuts] = true;
options.os_hooks[web_app::OsHookType::kShortcutsMenu] = true;
options.os_hooks[web_app::OsHookType::kFileHandlers] = true;
options.os_hooks[web_app::OsHookType::kRunOnOsLogin] = false;
web_app_provider_->os_integration_manager().InstallOsHooks( web_app_provider_->os_integration_manager().InstallOsHooks(
app_id, app_id,
base::BindOnce(&AppLauncherHandler::OnOsHooksInstalled, base::BindOnce(&AppLauncherHandler::OnOsHooksInstalled,
......
...@@ -22,6 +22,10 @@ ...@@ -22,6 +22,10 @@
namespace web_app { namespace web_app {
InstallOsHooksOptions::InstallOsHooksOptions() = default;
InstallOsHooksOptions::InstallOsHooksOptions(
const InstallOsHooksOptions& other) = default;
// This is adapted from base/barrier_closure.cc. os_hooks_results is maintained // This is adapted from base/barrier_closure.cc. os_hooks_results is maintained
// to track install results from different OS hooks callers // to track install results from different OS hooks callers
class OsHooksBarrierInfo { class OsHooksBarrierInfo {
...@@ -114,7 +118,7 @@ void OsIntegrationManager::InstallOsHooks( ...@@ -114,7 +118,7 @@ void OsIntegrationManager::InstallOsHooks(
// TODO(ortuno): Make adding a shortcut to the applications menu independent // TODO(ortuno): Make adding a shortcut to the applications menu independent
// from adding a shortcut to desktop. // from adding a shortcut to desktop.
if (options.add_to_applications_menu && if (options.os_hooks[OsHookType::kShortcuts] &&
shortcut_manager_->CanCreateShortcuts()) { shortcut_manager_->CanCreateShortcuts()) {
const bool add_to_desktop = options.add_to_desktop; const bool add_to_desktop = options.add_to_desktop;
shortcut_manager_->CreateShortcuts( shortcut_manager_->CreateShortcuts(
...@@ -272,15 +276,18 @@ void OsIntegrationManager::OnShortcutsCreated( ...@@ -272,15 +276,18 @@ void OsIntegrationManager::OnShortcutsCreated(
// TODO(crbug.com/1087219): callback should be run after all hooks are // TODO(crbug.com/1087219): callback should be run after all hooks are
// deployed, need to refactor filehandler to allow this. // deployed, need to refactor filehandler to allow this.
file_handler_manager_->EnableAndRegisterOsFileHandlers(app_id); if (options.os_hooks[OsHookType::kFileHandlers])
file_handler_manager_->EnableAndRegisterOsFileHandlers(app_id);
barrier_callback.Run(OsHookType::kFileHandlers, /*completed=*/true); barrier_callback.Run(OsHookType::kFileHandlers, /*completed=*/true);
if (options.add_to_quick_launch_bar && if (options.os_hooks[OsHookType::kShortcuts] &&
options.add_to_quick_launch_bar &&
ui_manager_->CanAddAppToQuickLaunchBar()) { ui_manager_->CanAddAppToQuickLaunchBar()) {
ui_manager_->AddAppToQuickLaunchBar(app_id); ui_manager_->AddAppToQuickLaunchBar(app_id);
} }
if (shortcuts_created && base::FeatureList::IsEnabled( if (shortcuts_created && options.os_hooks[OsHookType::kShortcutsMenu] &&
features::kDesktopPWAsAppIconShortcutsMenu)) { base::FeatureList::IsEnabled(
features::kDesktopPWAsAppIconShortcutsMenu)) {
if (web_app_info) { if (web_app_info) {
if (web_app_info->shortcuts_menu_item_infos.empty()) { if (web_app_info->shortcuts_menu_item_infos.empty()) {
barrier_callback.Run(OsHookType::kShortcutsMenu, /*completed=*/false); barrier_callback.Run(OsHookType::kShortcutsMenu, /*completed=*/false);
...@@ -300,16 +307,16 @@ void OsIntegrationManager::OnShortcutsCreated( ...@@ -300,16 +307,16 @@ void OsIntegrationManager::OnShortcutsCreated(
barrier_callback.Run(OsHookType::kShortcutsMenu, /*completed=*/false); barrier_callback.Run(OsHookType::kShortcutsMenu, /*completed=*/false);
} }
if (base::FeatureList::IsEnabled(features::kDesktopPWAsRunOnOsLogin) && if (options.os_hooks[OsHookType::kRunOnOsLogin] &&
options.run_on_os_login) { base::FeatureList::IsEnabled(features::kDesktopPWAsRunOnOsLogin)) {
// TODO(crbug.com/897302): Implement Run on OS Login mode selection. // TODO(crbug.com/897302): Implement Run on OS Login mode selection.
// Currently it is set to be the default: RunOnOsLoginMode::kWindowed // Currently it is set to be the default: RunOnOsLoginMode::kWindowed
RegisterRunOnOsLogin( RegisterRunOnOsLogin(
app_id, base::BindOnce(barrier_callback, OsHookType::kRunOnOsLogin)); app_id, base::BindOnce(barrier_callback, OsHookType::kRunOnOsLogin));
} else { } else {
base::SequencedTaskRunnerHandle::Get()->PostTask( base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE, base::BindOnce(barrier_callback, OsHookType::kRunOnOsLogin,
base::BindOnce(barrier_callback, OsHookType::kRunOnOsLogin, false)); /*completed=*/false));
} }
} }
......
...@@ -33,12 +33,15 @@ class WebAppUiManager; ...@@ -33,12 +33,15 @@ class WebAppUiManager;
// OsHooksResults contains the result of all Os hook deployments // OsHooksResults contains the result of all Os hook deployments
using OsHooksResults = std::bitset<OsHookType::kMaxValue + 1>; using OsHooksResults = std::bitset<OsHookType::kMaxValue + 1>;
// Used to pass install options configured from upstream caller // Used to pass install options configured from upstream caller.
// All options are disabled by default.
struct InstallOsHooksOptions { struct InstallOsHooksOptions {
bool add_to_applications_menu = false; InstallOsHooksOptions();
InstallOsHooksOptions(const InstallOsHooksOptions& other);
OsHooksResults os_hooks;
bool add_to_desktop = false; bool add_to_desktop = false;
bool add_to_quick_launch_bar = false; bool add_to_quick_launch_bar = false;
bool run_on_os_login = false;
}; };
// Callback made after InstallOsHooks is finished. // Callback made after InstallOsHooks is finished.
......
...@@ -256,10 +256,17 @@ void PendingAppInstallTask::OnWebAppInstalled(bool is_placeholder, ...@@ -256,10 +256,17 @@ void PendingAppInstallTask::OnWebAppInstalled(bool is_placeholder,
return; return;
} }
InstallOsHooksOptions options; InstallOsHooksOptions options;
options.add_to_applications_menu = install_options_.add_to_applications_menu; options.os_hooks[OsHookType::kShortcuts] =
install_options_.add_to_applications_menu;
options.add_to_desktop = install_options_.add_to_desktop; options.add_to_desktop = install_options_.add_to_desktop;
options.add_to_quick_launch_bar = install_options_.add_to_quick_launch_bar; options.add_to_quick_launch_bar = install_options_.add_to_quick_launch_bar;
options.run_on_os_login = install_options_.run_on_os_login; options.os_hooks[OsHookType::kRunOnOsLogin] =
install_options_.run_on_os_login;
// TODO(crbug.com/1087219): Determine if |register_file_handlers| should be
// configured from somewhere else rather than always true.
options.os_hooks[OsHookType::kFileHandlers] = true;
options.os_hooks[OsHookType::kShortcutsMenu] = true;
os_integration_manager_->InstallOsHooks( os_integration_manager_->InstallOsHooks(
app_id, app_id,
......
...@@ -46,7 +46,7 @@ void TestOsIntegrationManager::InstallOsHooks( ...@@ -46,7 +46,7 @@ void TestOsIntegrationManager::InstallOsHooks(
did_add_to_desktop_ = options.add_to_desktop; did_add_to_desktop_ = options.add_to_desktop;
if (options.add_to_applications_menu && can_create_shortcuts_) { if (options.os_hooks[OsHookType::kShortcuts] && can_create_shortcuts_) {
bool success = true; bool success = true;
auto it = next_create_shortcut_results_.find(app_id); auto it = next_create_shortcut_results_.find(app_id);
if (it != next_create_shortcut_results_.end()) { if (it != next_create_shortcut_results_.end()) {
...@@ -59,7 +59,7 @@ void TestOsIntegrationManager::InstallOsHooks( ...@@ -59,7 +59,7 @@ void TestOsIntegrationManager::InstallOsHooks(
} }
} }
if (options.run_on_os_login) { if (options.os_hooks[OsHookType::kRunOnOsLogin]) {
++num_register_run_on_os_login_calls_; ++num_register_run_on_os_login_calls_;
os_hooks_results[OsHookType::kRunOnOsLogin] = true; os_hooks_results[OsHookType::kRunOnOsLogin] = true;
} }
......
...@@ -776,22 +776,28 @@ void WebAppInstallTask::OnInstallFinalizedCreateShortcuts( ...@@ -776,22 +776,28 @@ void WebAppInstallTask::OnInstallFinalizedCreateShortcuts(
InstallOsHooksOptions options; InstallOsHooksOptions options;
options.add_to_applications_menu = true; options.os_hooks[OsHookType::kShortcuts] = true;
options.add_to_desktop = true; options.add_to_desktop = true;
options.add_to_quick_launch_bar = kAddAppsToQuickLaunchBarByDefault; options.add_to_quick_launch_bar = kAddAppsToQuickLaunchBarByDefault;
options.run_on_os_login = web_app_info->run_on_os_login; options.os_hooks[OsHookType::kRunOnOsLogin] = web_app_info->run_on_os_login;
if (install_source_ == WebappInstallSource::SYNC) if (install_source_ == WebappInstallSource::SYNC)
options.add_to_quick_launch_bar = false; options.add_to_quick_launch_bar = false;
if (install_params_) { if (install_params_) {
options.add_to_applications_menu = options.os_hooks[OsHookType::kShortcuts] =
install_params_->add_to_applications_menu; install_params_->add_to_applications_menu;
options.add_to_desktop = install_params_->add_to_desktop; options.add_to_desktop = install_params_->add_to_desktop;
options.add_to_quick_launch_bar = install_params_->add_to_quick_launch_bar; options.add_to_quick_launch_bar = install_params_->add_to_quick_launch_bar;
options.run_on_os_login = install_params_->run_on_os_login; options.os_hooks[OsHookType::kRunOnOsLogin] =
install_params_->run_on_os_login;
} }
// TODO(crbug.com/1087219): Determine if file handlers should be
// configured from somewhere else rather than always true.
options.os_hooks[OsHookType::kFileHandlers] = true;
options.os_hooks[OsHookType::kShortcutsMenu] = true;
auto hooks_created_callback = base::BindOnce( auto hooks_created_callback = base::BindOnce(
&WebAppInstallTask::OnOsHooksCreated, weak_ptr_factory_.GetWeakPtr(), &WebAppInstallTask::OnOsHooksCreated, weak_ptr_factory_.GetWeakPtr(),
web_app_info->open_as_window, app_id); web_app_info->open_as_window, app_id);
......
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