Commit 160206ba authored by Alexey Baskakov's avatar Alexey Baskakov Committed by Commit Bot

WebApp: Implement deletion of OS shortcuts for the new web apps system.

Delete OS shortcuts in OnWebAppWillBeUninstalled observation.

The bookmark app uninstallation case is currently handled in
::AppShortcutManager::OnExtensionUninstalled()
located in
chrome/browser/apps/platform_apps/shortcut_manager.h|cc.

Bug: 860581
Change-Id: Id501151011998b49d971cf09a5ebab7f985de8e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2000448Reviewed-by: default avatarJay Harris <harrisjay@chromium.org>
Commit-Queue: Alexey Baskakov <loyso@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732277}
parent 63f19936
...@@ -22,6 +22,15 @@ void AppShortcutManager::SetSubsystems(AppRegistrar* registrar) { ...@@ -22,6 +22,15 @@ void AppShortcutManager::SetSubsystems(AppRegistrar* registrar) {
registrar_ = registrar; registrar_ = registrar;
} }
void AppShortcutManager::Start() {
DCHECK(registrar_);
app_registrar_observer_.Add(registrar_);
}
void AppShortcutManager::Shutdown() {
app_registrar_observer_.RemoveAll();
}
void AppShortcutManager::AddObserver(AppShortcutObserver* observer) { void AppShortcutManager::AddObserver(AppShortcutObserver* observer) {
observers_.AddObserver(observer); observers_.AddObserver(observer);
} }
......
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/scoped_observer.h"
#include "chrome/browser/web_applications/components/app_registrar.h"
#include "chrome/browser/web_applications/components/app_registrar_observer.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h" #include "chrome/browser/web_applications/components/web_app_helpers.h"
#include "chrome/browser/web_applications/components/web_app_shortcut.h" #include "chrome/browser/web_applications/components/web_app_shortcut.h"
...@@ -18,22 +21,26 @@ class Profile; ...@@ -18,22 +21,26 @@ class Profile;
namespace web_app { namespace web_app {
class AppRegistrar;
class AppShortcutObserver; class AppShortcutObserver;
struct ShortcutInfo; struct ShortcutInfo;
// This class manages creation/update/deletion of OS shortcuts for web
// applications.
//
// TODO(crbug.com/860581): Migrate functions from // TODO(crbug.com/860581): Migrate functions from
// web_app_extension_shortcut.(h|cc) and // web_app_extension_shortcut.(h|cc) and
// platform_apps/shortcut_manager.(h|cc) to the AppShortcutManager, so web app // platform_apps/shortcut_manager.(h|cc) to web_app::AppShortcutManager and
// shortcuts can be managed in an extensions agnostic way. // its subclasses.
// Manages OS shortcuts for web applications. class AppShortcutManager : public AppRegistrarObserver {
class AppShortcutManager {
public: public:
explicit AppShortcutManager(Profile* profile); explicit AppShortcutManager(Profile* profile);
virtual ~AppShortcutManager(); ~AppShortcutManager() override;
void SetSubsystems(AppRegistrar* registrar); void SetSubsystems(AppRegistrar* registrar);
void Start();
void Shutdown();
void AddObserver(AppShortcutObserver* observer); void AddObserver(AppShortcutObserver* observer);
void RemoveObserver(AppShortcutObserver* observer); void RemoveObserver(AppShortcutObserver* observer);
...@@ -70,13 +77,16 @@ class AppShortcutManager { ...@@ -70,13 +77,16 @@ class AppShortcutManager {
CreateShortcutsCallback callback, CreateShortcutsCallback callback,
std::unique_ptr<ShortcutInfo> info); std::unique_ptr<ShortcutInfo> info);
ScopedObserver<AppRegistrar, AppRegistrarObserver> app_registrar_observer_{
this};
base::ObserverList<AppShortcutObserver, /*check_empty=*/true> observers_;
bool suppress_shortcuts_for_testing_ = false; bool suppress_shortcuts_for_testing_ = false;
AppRegistrar* registrar_ = nullptr; AppRegistrar* registrar_ = nullptr;
Profile* const profile_; Profile* const profile_;
base::ObserverList<AppShortcutObserver, /*check_empty=*/true> observers_;
base::WeakPtrFactory<AppShortcutManager> weak_ptr_factory_{this}; base::WeakPtrFactory<AppShortcutManager> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(AppShortcutManager); DISALLOW_COPY_AND_ASSIGN(AppShortcutManager);
......
...@@ -147,6 +147,7 @@ SystemWebAppManager& WebAppProvider::system_web_app_manager() { ...@@ -147,6 +147,7 @@ SystemWebAppManager& WebAppProvider::system_web_app_manager() {
} }
void WebAppProvider::Shutdown() { void WebAppProvider::Shutdown() {
shortcut_manager_->Shutdown();
pending_app_manager_->Shutdown(); pending_app_manager_->Shutdown();
install_manager_->Shutdown(); install_manager_->Shutdown();
manifest_update_manager_->Shutdown(); manifest_update_manager_->Shutdown();
...@@ -247,6 +248,7 @@ void WebAppProvider::OnRegistryControllerReady() { ...@@ -247,6 +248,7 @@ void WebAppProvider::OnRegistryControllerReady() {
external_web_app_manager_->Start(); external_web_app_manager_->Start();
web_app_policy_manager_->Start(); web_app_policy_manager_->Start();
system_web_app_manager_->Start(); system_web_app_manager_->Start();
shortcut_manager_->Start();
manifest_update_manager_->Start(); manifest_update_manager_->Start();
file_handler_manager_->Start(); file_handler_manager_->Start();
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/files/file_path.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -35,6 +36,19 @@ WebAppShortcutManager::WebAppShortcutManager( ...@@ -35,6 +36,19 @@ WebAppShortcutManager::WebAppShortcutManager(
WebAppShortcutManager::~WebAppShortcutManager() = default; WebAppShortcutManager::~WebAppShortcutManager() = default;
void WebAppShortcutManager::OnWebAppWillBeUninstalled(const AppId& app_id) {
const WebApp* app = GetWebAppRegistrar().GetAppById(app_id);
DCHECK(app);
std::unique_ptr<ShortcutInfo> shortcut_info = BuildShortcutInfoForWebApp(app);
base::FilePath shortcut_data_dir =
internals::GetShortcutDataDir(*shortcut_info);
internals::PostShortcutIOTask(
base::BindOnce(&internals::DeletePlatformShortcuts, shortcut_data_dir),
std::move(shortcut_info));
}
void WebAppShortcutManager::GetShortcutInfoForApp( void WebAppShortcutManager::GetShortcutInfoForApp(
const AppId& app_id, const AppId& app_id,
GetShortcutInfoCallback callback) { GetShortcutInfoCallback callback) {
......
...@@ -32,6 +32,9 @@ class WebAppShortcutManager : public AppShortcutManager { ...@@ -32,6 +32,9 @@ class WebAppShortcutManager : public AppShortcutManager {
FileHandlerManager* file_handler_manager); FileHandlerManager* file_handler_manager);
~WebAppShortcutManager() override; ~WebAppShortcutManager() override;
// AppRegistrarObserver:
void OnWebAppWillBeUninstalled(const AppId& app_id) override;
// AppShortcutManager: // AppShortcutManager:
void GetShortcutInfoForApp(const AppId& app_id, void GetShortcutInfoForApp(const AppId& app_id,
GetShortcutInfoCallback callback) override; GetShortcutInfoCallback callback) override;
......
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