Commit b94143e8 authored by Mike Jackson's avatar Mike Jackson Committed by Commit Bot

dpwas: Move delete shared mac shim to behind shortcuts

While working on Run On OS Login for Mac, I noticed that the shared
app shims were being deleted when toggling Run On OS Login. This happens
because the app shims unconditionally delete the app shims.

This change moves the code to delete the shared app shims behind
the shortcut check. On Mac you can have both per profile shims,
and shared shims, so the callbacks are chained together only on
that platform.

Bug: 897302
Change-Id: I318137ac0f34e4f2429a5119d47e3fe5c3c96892
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2519877
Commit-Queue: Mike Jackson <mjackson@microsoft.com>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarccameron <ccameron@chromium.org>
Reviewed-by: default avatarPhillis Tang <phillis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825165}
parent 1e598ab9
...@@ -199,7 +199,8 @@ void OsIntegrationManager::UninstallOsHooks(const AppId& app_id, ...@@ -199,7 +199,8 @@ void OsIntegrationManager::UninstallOsHooks(const AppId& app_id,
if (os_hooks[OsHookType::kShortcuts]) { if (os_hooks[OsHookType::kShortcuts]) {
internals::ScheduleDeletePlatformShortcuts( internals::ScheduleDeletePlatformShortcuts(
shortcut_data_dir, std::move(shortcut_info), shortcut_data_dir, std::move(shortcut_info),
base::BindOnce(barrier, OsHookType::kShortcuts)); base::BindOnce(&OsIntegrationManager::OnShortcutsDeleted,
weak_ptr_factory_.GetWeakPtr(), app_id, barrier));
} else { } else {
barrier.Run(OsHookType::kShortcuts, /*completed=*/true); barrier.Run(OsHookType::kShortcuts, /*completed=*/true);
} }
...@@ -213,8 +214,6 @@ void OsIntegrationManager::UninstallOsHooks(const AppId& app_id, ...@@ -213,8 +214,6 @@ void OsIntegrationManager::UninstallOsHooks(const AppId& app_id,
if (os_hooks[OsHookType::kFileHandlers]) if (os_hooks[OsHookType::kFileHandlers])
file_handler_manager_->DisableAndUnregisterOsFileHandlers(app_id); file_handler_manager_->DisableAndUnregisterOsFileHandlers(app_id);
barrier.Run(OsHookType::kFileHandlers, /*completed=*/true); barrier.Run(OsHookType::kFileHandlers, /*completed=*/true);
DeleteSharedAppShims(app_id);
} }
void OsIntegrationManager::UpdateOsHooks( void OsIntegrationManager::UpdateOsHooks(
...@@ -367,17 +366,21 @@ void OsIntegrationManager::OnShortcutsCreated( ...@@ -367,17 +366,21 @@ void OsIntegrationManager::OnShortcutsCreated(
} }
} }
void OsIntegrationManager::DeleteSharedAppShims(const AppId& app_id) { void OsIntegrationManager::OnShortcutsDeleted(
const AppId& app_id,
base::RepeatingCallback<void(OsHookType::Type os_hook, bool deleted)>
barrier_callback,
bool shortcuts_deleted) {
#if defined(OS_MAC) #if defined(OS_MAC)
bool delete_multi_profile_shortcuts = bool delete_multi_profile_shortcuts =
AppShimRegistry::Get()->OnAppUninstalledForProfile(app_id, AppShimRegistry::Get()->OnAppUninstalledForProfile(app_id,
profile_->GetPath()); profile_->GetPath());
if (delete_multi_profile_shortcuts) { if (delete_multi_profile_shortcuts) {
web_app::internals::GetShortcutIOTaskRunner()->PostTask( internals::ScheduleDeleteMultiProfileShortcutsForApp(
FROM_HERE, app_id, base::BindOnce(barrier_callback, OsHookType::kRunOnOsLogin));
base::BindOnce(&web_app::internals::DeleteMultiProfileShortcutsForApp,
app_id));
} }
#else
barrier_callback.Run(OsHookType::kShortcuts, /*completed=*/shortcuts_deleted);
#endif #endif
} }
......
...@@ -150,6 +150,12 @@ class OsIntegrationManager { ...@@ -150,6 +150,12 @@ class OsIntegrationManager {
bool created)> callback, bool created)> callback,
bool shortcuts_created); bool shortcuts_created);
void OnShortcutsDeleted(
const AppId& app_id,
base::RepeatingCallback<void(OsHookType::Type os_hook, bool deleted)>
barrier_callback,
bool shortcuts_deleted);
void RegisterRunOnOsLogin(const AppId& app_id, void RegisterRunOnOsLogin(const AppId& app_id,
RegisterRunOnOsLoginCallback callback); RegisterRunOnOsLoginCallback callback);
...@@ -157,8 +163,6 @@ class OsIntegrationManager { ...@@ -157,8 +163,6 @@ class OsIntegrationManager {
RegisterRunOnOsLoginCallback callback, RegisterRunOnOsLoginCallback callback,
std::unique_ptr<ShortcutInfo> info); std::unique_ptr<ShortcutInfo> info);
void DeleteSharedAppShims(const AppId& app_id);
Profile* const profile_; Profile* const profile_;
AppRegistrar* registrar_ = nullptr; AppRegistrar* registrar_ = nullptr;
WebAppUiManager* ui_manager_ = nullptr; WebAppUiManager* ui_manager_ = nullptr;
......
...@@ -80,6 +80,14 @@ void DeletePlatformShortcutsAndPostCallback( ...@@ -80,6 +80,14 @@ void DeletePlatformShortcutsAndPostCallback(
FROM_HERE, base::BindOnce(std::move(callback), shortcut_deleted)); FROM_HERE, base::BindOnce(std::move(callback), shortcut_deleted));
} }
void DeleteMultiProfileShortcutsForAppAndPostCallback(
const std::string& app_id,
CreateShortcutsCallback callback) {
web_app::internals::DeleteMultiProfileShortcutsForApp(app_id);
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), true));
}
} // namespace } // namespace
ShortcutInfo::ShortcutInfo() = default; ShortcutInfo::ShortcutInfo() = default;
...@@ -186,6 +194,17 @@ void ScheduleDeletePlatformShortcuts( ...@@ -186,6 +194,17 @@ void ScheduleDeletePlatformShortcuts(
std::move(shortcut_info)); std::move(shortcut_info));
} }
void ScheduleDeleteMultiProfileShortcutsForApp(
const std::string& app_id,
DeleteShortcutsCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
GetShortcutIOTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&DeleteMultiProfileShortcutsForAppAndPostCallback, app_id,
std::move(callback)));
}
void PostShortcutIOTaskAndReply( void PostShortcutIOTaskAndReply(
base::OnceCallback<void(const ShortcutInfo&)> task, base::OnceCallback<void(const ShortcutInfo&)> task,
std::unique_ptr<ShortcutInfo> shortcut_info, std::unique_ptr<ShortcutInfo> shortcut_info,
......
...@@ -164,6 +164,10 @@ void ScheduleDeletePlatformShortcuts( ...@@ -164,6 +164,10 @@ void ScheduleDeletePlatformShortcuts(
std::unique_ptr<ShortcutInfo> shortcut_info, std::unique_ptr<ShortcutInfo> shortcut_info,
DeleteShortcutsCallback callback); DeleteShortcutsCallback callback);
void ScheduleDeleteMultiProfileShortcutsForApp(
const std::string& app_id,
DeleteShortcutsCallback callback);
// Delete all the shortcuts we have added for this extension. This is the // Delete all the shortcuts we have added for this extension. This is the
// platform specific implementation of the DeleteAllShortcuts function, and // platform specific implementation of the DeleteAllShortcuts function, and
// is executed on the FILE thread. // is executed on the FILE thread.
......
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