Commit 550e3718 authored by phillis's avatar phillis Committed by Commit Bot

dpwa: Create OsIntegrationManager

This is the first step towards consolidating OS integration logic to
OsIntegrationManager. This patch adds just enough
functionality to replace the OS logic in AppLaunchHandler.

Bug: 1087219
Change-Id: I632327b9c7c86683e2b408ea361ee183aed13d86
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2251198Reviewed-by: default avatarcalamity <calamity@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Commit-Queue: Phillis Tang <phillis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780109}
parent 21bae89a
......@@ -54,13 +54,12 @@
#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
#include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
#include "chrome/browser/web_applications/components/app_registry_controller.h"
#include "chrome/browser/web_applications/components/app_shortcut_manager.h"
#include "chrome/browser/web_applications/components/file_handler_manager.h"
#include "chrome/browser/web_applications/components/install_finalizer.h"
#include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/components/web_app_provider_base.h"
#include "chrome/browser/web_applications/extensions/bookmark_app_finalizer_utils.h"
#include "chrome/browser/web_applications/extensions/bookmark_app_util.h"
#include "chrome/browser/web_applications/os_integration_manager.h"
#include "chrome/browser/web_applications/web_app_icon_manager.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/common/buildflags.h"
......@@ -972,15 +971,10 @@ void AppLauncherHandler::HandleInstallAppLocally(const base::ListValue* args) {
true);
web_app_provider_->registry_controller().SetAppInstallTime(app_id,
base::Time::Now());
web_app::AppShortcutManager& shortcut_manager =
web_app_provider_->shortcut_manager();
if (shortcut_manager.CanCreateShortcuts()) {
shortcut_manager.CreateShortcuts(
app_id, /*add_to_desktop=*/true,
base::BindOnce(
&AppLauncherHandler::OnShortcutsCreatedRegisterOsIntegration,
weak_ptr_factory_.GetWeakPtr(), app_id));
}
web_app_provider_->os_integration_manager().InstallOsHooks(
app_id, base::BindOnce(&AppLauncherHandler::OnOsHooksInstalled,
weak_ptr_factory_.GetWeakPtr(), app_id));
// Use the appAdded to update the app icon's color to no longer be
// greyscale.
std::unique_ptr<base::DictionaryValue> app_info = GetWebAppInfo(app_id);
......@@ -1201,13 +1195,10 @@ void AppLauncherHandler::PromptToEnableApp(const std::string& extension_id) {
extension_enable_flow_->StartForWebContents(web_ui()->GetWebContents());
}
void AppLauncherHandler::OnShortcutsCreatedRegisterOsIntegration(
const web_app::AppId& app_id,
bool shortcuts_created) {
void AppLauncherHandler::OnOsHooksInstalled(const web_app::AppId& app_id,
bool shortcuts_created) {
LOCAL_HISTOGRAM_BOOLEAN("Apps.Launcher.InstallLocallyShortcutsCreated",
shortcuts_created);
web_app_provider_->file_handler_manager().EnableAndRegisterOsFileHandlers(
app_id);
}
void AppLauncherHandler::OnExtensionUninstallDialogClosed(
......
......@@ -174,10 +174,8 @@ class AppLauncherHandler
// Prompts the user to re-enable the app for |extension_id|.
void PromptToEnableApp(const std::string& extension_id);
// Registers file handlers for |app_id|, after shortcuts have been
// created.
void OnShortcutsCreatedRegisterOsIntegration(const web_app::AppId& app_id,
bool shortcuts_created);
// Records result to UMA after OS Hooks are installed.
void OnOsHooksInstalled(const web_app::AppId& app_id, bool shortcuts_created);
// ExtensionUninstallDialog::Delegate:
void OnExtensionUninstallDialogClosed(bool did_start_uninstall,
......@@ -264,7 +262,7 @@ class AppLauncherHandler
// Used for favicon loading tasks.
base::CancelableTaskTracker cancelable_task_tracker_;
// Used to register file handlers after shortcuts have been created.
// Used for passing callbacks.
base::WeakPtrFactory<AppLauncherHandler> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(AppLauncherHandler);
......
......@@ -58,6 +58,8 @@ source_set("web_applications") {
"external_web_app_manager.h",
"file_utils_wrapper.cc",
"file_utils_wrapper.h",
"os_integration_manager.cc",
"os_integration_manager.h",
"pending_app_install_task.cc",
"pending_app_install_task.h",
"pending_app_manager_impl.cc",
......
......@@ -27,6 +27,7 @@ class WebAppAudioFocusIdMap;
class WebAppPolicyManager;
class WebAppUiManager;
class SystemWebAppManager;
class OsIntegrationManager;
class WebAppProviderBase : public KeyedService {
public:
......@@ -65,6 +66,9 @@ class WebAppProviderBase : public KeyedService {
virtual SystemWebAppManager& system_web_app_manager() = 0;
// Manage all OS hooks that need to be deployed during Web Apps install
virtual OsIntegrationManager& os_integration_manager() = 0;
DISALLOW_COPY_AND_ASSIGN(WebAppProviderBase);
};
......
// Copyright 2020 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/os_integration_manager.h"
#include "base/bind.h"
#include "chrome/browser/web_applications/components/app_shortcut_manager.h"
#include "chrome/browser/web_applications/components/file_handler_manager.h"
namespace web_app {
OsIntegrationManager::OsIntegrationManager() = default;
OsIntegrationManager::~OsIntegrationManager() = default;
void OsIntegrationManager::SetSubsystems(
AppShortcutManager* shortcut_manager,
FileHandlerManager* file_handler_manager) {
shortcut_manager_ = shortcut_manager;
file_handler_manager_ = file_handler_manager;
}
void OsIntegrationManager::InstallOsHooks(const AppId& app_id,
InstallOsHooksCallback callback) {
DCHECK(shortcut_manager_);
if (shortcut_manager_->CanCreateShortcuts()) {
shortcut_manager_->CreateShortcuts(
app_id, /*add_to_desktop=*/true,
base::BindOnce(&OsIntegrationManager::OnShortcutsCreated,
weak_ptr_factory_.GetWeakPtr(), app_id,
std::move(callback)));
}
}
void OsIntegrationManager::OnShortcutsCreated(const AppId& app_id,
InstallOsHooksCallback callback,
bool shortcuts_created) {
DCHECK(file_handler_manager_);
// TODO(crbug.com/1087219): callback should be run after all hooks are
// deployed, need to refactor filehandler to allow this.
file_handler_manager_->EnableAndRegisterOsFileHandlers(app_id);
std::move(callback).Run(shortcuts_created);
}
} // namespace web_app
// Copyright 2020 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_OS_INTEGRATION_MANAGER_H_
#define CHROME_BROWSER_WEB_APPLICATIONS_OS_INTEGRATION_MANAGER_H_
#include "base/memory/weak_ptr.h"
#include "chrome/browser/web_applications/components/web_app_id.h"
namespace web_app {
class FileHandlerManager;
class AppShortcutManager;
// Callback made when InstallOsHooks has finished trying to deploy all
// needed OS hooks.
using InstallOsHooksCallback = base::OnceCallback<void(bool shortcuts_created)>;
// OsIntegrationManager is responsible of creating/updating/deleting
// all OS hooks during Web App lifecycle.
// It contains individual OS integration managers and takes
// care of inter-dependencies among them.
class OsIntegrationManager {
public:
OsIntegrationManager();
~OsIntegrationManager();
void SetSubsystems(AppShortcutManager* shortcut_manager,
FileHandlerManager* file_handler_manager);
void InstallOsHooks(const AppId& app_id, InstallOsHooksCallback callback);
private:
void OnShortcutsCreated(const AppId& app_id,
InstallOsHooksCallback callback,
bool shortcuts_created);
AppShortcutManager* shortcut_manager_ = nullptr;
FileHandlerManager* file_handler_manager_ = nullptr;
base::WeakPtrFactory<OsIntegrationManager> weak_ptr_factory_{this};
};
} // namespace web_app
#endif // CHROME_BROWSER_WEB_APPLICATIONS_OS_INTEGRATION_MANAGER_H_
......@@ -26,6 +26,7 @@
#include "chrome/browser/web_applications/external_web_app_manager.h"
#include "chrome/browser/web_applications/file_utils_wrapper.h"
#include "chrome/browser/web_applications/manifest_update_manager.h"
#include "chrome/browser/web_applications/os_integration_manager.h"
#include "chrome/browser/web_applications/pending_app_manager_impl.h"
#include "chrome/browser/web_applications/system_web_app_manager.h"
#include "chrome/browser/web_applications/web_app_database_factory.h"
......@@ -148,6 +149,11 @@ SystemWebAppManager& WebAppProvider::system_web_app_manager() {
return *system_web_app_manager_;
}
OsIntegrationManager& WebAppProvider::os_integration_manager() {
CheckIsConnected();
return *os_integration_manager_;
}
void WebAppProvider::Shutdown() {
ui_manager_->Shutdown();
shortcut_manager_->Shutdown();
......@@ -183,6 +189,7 @@ void WebAppProvider::CreateCommonSubsystems(Profile* profile) {
external_web_app_manager_ = std::make_unique<ExternalWebAppManager>(profile);
system_web_app_manager_ = std::make_unique<SystemWebAppManager>(profile);
web_app_policy_manager_ = std::make_unique<WebAppPolicyManager>(profile);
os_integration_manager_ = std::make_unique<OsIntegrationManager>();
}
void WebAppProvider::CreateWebAppsSubsystems(Profile* profile) {
......@@ -266,6 +273,8 @@ void WebAppProvider::ConnectSubsystems() {
web_app_policy_manager_->SetSubsystems(pending_app_manager_.get());
file_handler_manager_->SetSubsystems(registrar_.get());
shortcut_manager_->SetSubsystems(registrar_.get());
os_integration_manager_->SetSubsystems(shortcut_manager_.get(),
file_handler_manager_.get());
connected_ = true;
}
......
......@@ -41,6 +41,7 @@ class WebAppAudioFocusIdMap;
class WebAppInstallManager;
class WebAppPolicyManager;
class WebAppUiManager;
class OsIntegrationManager;
// Forward declarations for new extension-independent subsystems.
class WebAppDatabaseFactory;
......@@ -81,6 +82,7 @@ class WebAppProvider : public WebAppProviderBase {
AppIconManager& icon_manager() override;
AppShortcutManager& shortcut_manager() override;
SystemWebAppManager& system_web_app_manager() override;
OsIntegrationManager& os_integration_manager() override;
// KeyedService:
void Shutdown() override;
......@@ -132,6 +134,7 @@ class WebAppProvider : public WebAppProviderBase {
std::unique_ptr<WebAppInstallManager> install_manager_;
std::unique_ptr<WebAppPolicyManager> web_app_policy_manager_;
std::unique_ptr<WebAppUiManager> ui_manager_;
std::unique_ptr<OsIntegrationManager> os_integration_manager_;
base::OneShotEvent on_registry_ready_;
......
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