Commit 4a0c2940 authored by phillis's avatar phillis Committed by Commit Bot

DPWA: allow callback to be passed to OsIntegrationManager::UninstallOsHooks

This allows caller for OsIntegrationManager::UninstallOsHooks to pass
callback to check the result of the uninstallation of all OS hooks.

Bug: 1108109
Change-Id: I87c3369f9264bdd2cbc4014fd7dc45baef493cdb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2329948
Commit-Queue: Phillis Tang <phillis@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794759}
parent 6930533d
...@@ -27,7 +27,6 @@ void RegisterRunOnOsLoginAndPostCallback(RegisterRunOnOsLoginCallback callback, ...@@ -27,7 +27,6 @@ void RegisterRunOnOsLoginAndPostCallback(RegisterRunOnOsLoginCallback callback,
FROM_HERE, FROM_HERE,
base::BindOnce(std::move(callback), run_on_os_login_registered)); base::BindOnce(std::move(callback), run_on_os_login_registered));
} }
} // namespace } // namespace
namespace internals { namespace internals {
...@@ -41,8 +40,10 @@ bool RegisterRunOnOsLogin(const ShortcutInfo& shortcut_info) { ...@@ -41,8 +40,10 @@ bool RegisterRunOnOsLogin(const ShortcutInfo& shortcut_info) {
// TODO(crbug.com/897302): This boilerplate function is used for platforms // TODO(crbug.com/897302): This boilerplate function is used for platforms
// other than Windows, currently the feature is only supported in Windows. // other than Windows, currently the feature is only supported in Windows.
void UnregisterRunOnOsLogin(const base::FilePath& profile_path, bool UnregisterRunOnOsLogin(const base::FilePath& profile_path,
const base::string16& shortcut_title) {} const base::string16& shortcut_title) {
return true;
}
#endif #endif
} // namespace internals } // namespace internals
...@@ -56,4 +57,16 @@ void ScheduleRegisterRunOnOsLogin(std::unique_ptr<ShortcutInfo> shortcut_info, ...@@ -56,4 +57,16 @@ void ScheduleRegisterRunOnOsLogin(std::unique_ptr<ShortcutInfo> shortcut_info,
std::move(shortcut_info)); std::move(shortcut_info));
} }
void ScheduleUnregisterRunOnOsLogin(const base::FilePath& profile_path,
const base::string16& shortcut_title,
UnregisterRunOnOsLoginCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
internals::GetShortcutIOTaskRunner()->PostTaskAndReplyWithResult(
FROM_HERE,
base::BindOnce(&internals::UnregisterRunOnOsLogin, profile_path,
shortcut_title),
std::move(callback));
}
} // namespace web_app } // namespace web_app
...@@ -25,6 +25,10 @@ struct ShortcutInfo; ...@@ -25,6 +25,10 @@ struct ShortcutInfo;
// registered. // registered.
using RegisterRunOnOsLoginCallback = base::OnceCallback<void(bool success)>; using RegisterRunOnOsLoginCallback = base::OnceCallback<void(bool success)>;
// Callback made when UnregisterRunOnOslogin has finished indicating whether or
// not it was successfully unregistered
using UnregisterRunOnOsLoginCallback = base::OnceCallback<void(bool success)>;
namespace internals { namespace internals {
// Registers the app with the OS to run on OS login. Platform specific // Registers the app with the OS to run on OS login. Platform specific
...@@ -35,7 +39,7 @@ bool RegisterRunOnOsLogin(const ShortcutInfo& shortcut_info); ...@@ -35,7 +39,7 @@ bool RegisterRunOnOsLogin(const ShortcutInfo& shortcut_info);
// Unregisters the app with the OS from running on startup. Platform specific // Unregisters the app with the OS from running on startup. Platform specific
// implementations are required for this. // implementations are required for this.
// See web_app_shortcut_win.cc for Windows. // See web_app_shortcut_win.cc for Windows.
void UnregisterRunOnOsLogin(const base::FilePath& profile_path, bool UnregisterRunOnOsLogin(const base::FilePath& profile_path,
const base::string16& shortcut_title); const base::string16& shortcut_title);
} // namespace internals } // namespace internals
...@@ -46,6 +50,9 @@ void UnregisterRunOnOsLogin(const base::FilePath& profile_path, ...@@ -46,6 +50,9 @@ void UnregisterRunOnOsLogin(const base::FilePath& profile_path,
void ScheduleRegisterRunOnOsLogin(std::unique_ptr<ShortcutInfo> shortcut_info, void ScheduleRegisterRunOnOsLogin(std::unique_ptr<ShortcutInfo> shortcut_info,
RegisterRunOnOsLoginCallback callback); RegisterRunOnOsLoginCallback callback);
void ScheduleUnregisterRunOnOsLogin(const base::FilePath& profile_path,
const base::string16& shortcut_title,
UnregisterRunOnOsLoginCallback callback);
} // namespace web_app } // namespace web_app
#endif // CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_WEB_APP_RUN_ON_OS_LOGIN_H_ #endif // CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_WEB_APP_RUN_ON_OS_LOGIN_H_
...@@ -24,22 +24,24 @@ bool RegisterRunOnOsLogin(const ShortcutInfo& shortcut_info) { ...@@ -24,22 +24,24 @@ bool RegisterRunOnOsLogin(const ShortcutInfo& shortcut_info) {
SHORTCUT_CREATION_BY_USER, shortcut_info); SHORTCUT_CREATION_BY_USER, shortcut_info);
} }
void UnregisterRunOnOsLogin(const base::FilePath& profile_path, bool UnregisterRunOnOsLogin(const base::FilePath& profile_path,
const base::string16& shortcut_title) { const base::string16& shortcut_title) {
web_app::ShortcutLocations all_shortcut_locations; web_app::ShortcutLocations all_shortcut_locations;
all_shortcut_locations.in_startup = true; all_shortcut_locations.in_startup = true;
std::vector<base::FilePath> all_paths = std::vector<base::FilePath> all_paths =
GetShortcutPaths(all_shortcut_locations); GetShortcutPaths(all_shortcut_locations);
bool result = true;
// Only Startup folder is the expected path to be returned in all_paths. // Only Startup folder is the expected path to be returned in all_paths.
for (const auto& path : all_paths) { for (const auto& path : all_paths) {
// Find all app's shortcuts in Startup folder to delete. // Find all app's shortcuts in Startup folder to delete.
std::vector<base::FilePath> shortcut_files = std::vector<base::FilePath> shortcut_files =
FindAppShortcutsByProfileAndTitle(path, profile_path, shortcut_title); FindAppShortcutsByProfileAndTitle(path, profile_path, shortcut_title);
for (const auto& shortcut_file : shortcut_files) { for (const auto& shortcut_file : shortcut_files) {
base::DeleteFile(shortcut_file); if (!base::DeleteFile(shortcut_file))
result = false;
} }
} }
return result;
} }
} // namespace internals } // namespace internals
......
...@@ -71,6 +71,16 @@ void CreatePlatformShortcutsAndPostCallback( ...@@ -71,6 +71,16 @@ void CreatePlatformShortcutsAndPostCallback(
FROM_HERE, base::BindOnce(std::move(callback), shortcut_created)); FROM_HERE, base::BindOnce(std::move(callback), shortcut_created));
} }
void DeletePlatformShortcutsAndPostCallback(
const base::FilePath& shortcut_data_path,
CreateShortcutsCallback callback,
const ShortcutInfo& shortcut_info) {
bool shortcut_deleted =
internals::DeletePlatformShortcuts(shortcut_data_path, shortcut_info);
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), shortcut_deleted));
}
} // namespace } // namespace
ShortcutInfo::ShortcutInfo() = default; ShortcutInfo::ShortcutInfo() = default;
...@@ -166,6 +176,17 @@ void ScheduleCreatePlatformShortcuts( ...@@ -166,6 +176,17 @@ void ScheduleCreatePlatformShortcuts(
std::move(shortcut_info)); std::move(shortcut_info));
} }
void ScheduleDeletePlatformShortcuts(
const base::FilePath& shortcut_data_path,
std::unique_ptr<ShortcutInfo> shortcut_info,
DeleteShortcutsCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
PostShortcutIOTask(base::BindOnce(&DeletePlatformShortcutsAndPostCallback,
shortcut_data_path, std::move(callback)),
std::move(shortcut_info));
}
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,
......
...@@ -123,6 +123,10 @@ base::FilePath GetOsIntegrationResourcesDirectoryForApp( ...@@ -123,6 +123,10 @@ base::FilePath GetOsIntegrationResourcesDirectoryForApp(
// platform shortcuts indicating whether or not they were successfully // platform shortcuts indicating whether or not they were successfully
// created. // created.
using CreateShortcutsCallback = base::OnceCallback<void(bool shortcut_created)>; using CreateShortcutsCallback = base::OnceCallback<void(bool shortcut_created)>;
// Callback made when DeletePlatformShortcuts has finished trying to delete the
// platform shortcuts indicating whether or not they were successfully
// deleted.
using DeleteShortcutsCallback = base::OnceCallback<void(bool shortcut_deleted)>;
// Returns an array of desired icon sizes (in px) to be contained in an app OS // Returns an array of desired icon sizes (in px) to be contained in an app OS
// shortcut, sorted in ascending order (biggest desired icon size is last). // shortcut, sorted in ascending order (biggest desired icon size is last).
...@@ -155,10 +159,15 @@ void ScheduleCreatePlatformShortcuts( ...@@ -155,10 +159,15 @@ void ScheduleCreatePlatformShortcuts(
std::unique_ptr<ShortcutInfo> shortcut_info, std::unique_ptr<ShortcutInfo> shortcut_info,
CreateShortcutsCallback callback); CreateShortcutsCallback callback);
void ScheduleDeletePlatformShortcuts(
const base::FilePath& shortcut_data_path,
std::unique_ptr<ShortcutInfo> shortcut_info,
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.
void DeletePlatformShortcuts(const base::FilePath& shortcut_data_path, bool DeletePlatformShortcuts(const base::FilePath& shortcut_data_path,
const ShortcutInfo& shortcut_info); const ShortcutInfo& shortcut_info);
// Delete the multi-profile (non-profile_scoped) shortcuts for the specified // Delete the multi-profile (non-profile_scoped) shortcuts for the specified
......
...@@ -15,8 +15,10 @@ bool CreatePlatformShortcuts(const base::FilePath& web_app_path, ...@@ -15,8 +15,10 @@ bool CreatePlatformShortcuts(const base::FilePath& web_app_path,
return true; return true;
} }
void DeletePlatformShortcuts(const base::FilePath& web_app_path, bool DeletePlatformShortcuts(const base::FilePath& web_app_path,
const ShortcutInfo& shortcut_info) {} const ShortcutInfo& shortcut_info) {
return true;
}
void UpdatePlatformShortcuts(const base::FilePath& web_app_path, void UpdatePlatformShortcuts(const base::FilePath& web_app_path,
const base::string16& old_app_title, const base::string16& old_app_title,
......
...@@ -281,13 +281,15 @@ base::FilePath GetAppShortcutFilename(const base::FilePath& profile_path, ...@@ -281,13 +281,15 @@ base::FilePath GetAppShortcutFilename(const base::FilePath& profile_path,
return base::FilePath(filename.append(".desktop")); return base::FilePath(filename.append(".desktop"));
} }
void DeleteShortcutOnDesktop(const base::FilePath& shortcut_filename) { bool DeleteShortcutOnDesktop(const base::FilePath& shortcut_filename) {
base::FilePath desktop_path; base::FilePath desktop_path;
bool result = false;
if (base::PathService::Get(base::DIR_USER_DESKTOP, &desktop_path)) if (base::PathService::Get(base::DIR_USER_DESKTOP, &desktop_path))
base::DeleteFile(desktop_path.Append(shortcut_filename)); result = base::DeleteFile(desktop_path.Append(shortcut_filename));
return result;
} }
void DeleteShortcutInApplicationsMenu( bool DeleteShortcutInApplicationsMenu(
const base::FilePath& shortcut_filename, const base::FilePath& shortcut_filename,
const base::FilePath& directory_filename) { const base::FilePath& directory_filename) {
std::vector<std::string> argv; std::vector<std::string> argv;
...@@ -306,7 +308,7 @@ void DeleteShortcutInApplicationsMenu( ...@@ -306,7 +308,7 @@ void DeleteShortcutInApplicationsMenu(
argv.push_back(directory_filename.value()); argv.push_back(directory_filename.value());
argv.push_back(shortcut_filename.value()); argv.push_back(shortcut_filename.value());
int exit_code; int exit_code;
shell_integration_linux::LaunchXdgUtility(argv, &exit_code); return shell_integration_linux::LaunchXdgUtility(argv, &exit_code);
} }
bool CreateDesktopShortcut(const ShortcutInfo& shortcut_info, bool CreateDesktopShortcut(const ShortcutInfo& shortcut_info,
...@@ -447,7 +449,7 @@ ShortcutLocations GetExistingShortcutLocations( ...@@ -447,7 +449,7 @@ ShortcutLocations GetExistingShortcutLocations(
return locations; return locations;
} }
void DeleteDesktopShortcuts(const base::FilePath& profile_path, bool DeleteDesktopShortcuts(const base::FilePath& profile_path,
const std::string& extension_id) { const std::string& extension_id) {
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE, base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
base::BlockingType::MAY_BLOCK); base::BlockingType::MAY_BLOCK);
...@@ -456,21 +458,22 @@ void DeleteDesktopShortcuts(const base::FilePath& profile_path, ...@@ -456,21 +458,22 @@ void DeleteDesktopShortcuts(const base::FilePath& profile_path,
GetAppShortcutFilename(profile_path, extension_id); GetAppShortcutFilename(profile_path, extension_id);
DCHECK(!shortcut_filename.empty()); DCHECK(!shortcut_filename.empty());
DeleteShortcutOnDesktop(shortcut_filename); bool deleted_from_desktop = DeleteShortcutOnDesktop(shortcut_filename);
// Delete shortcuts from |kDirectoryFilename|. // Delete shortcuts from |kDirectoryFilename|.
// Note that it is possible that shortcuts were not created in the Chrome Apps // Note that it is possible that shortcuts were not created in the Chrome Apps
// directory. It doesn't matter: this will still delete the shortcut even if // directory. It doesn't matter: this will still delete the shortcut even if
// it isn't in the directory. // it isn't in the directory.
DeleteShortcutInApplicationsMenu(shortcut_filename, bool deleted_from_application_menu = DeleteShortcutInApplicationsMenu(
base::FilePath(kDirectoryFilename)); shortcut_filename, base::FilePath(kDirectoryFilename));
return (deleted_from_desktop && deleted_from_application_menu);
} }
void DeleteAllDesktopShortcuts(const base::FilePath& profile_path) { bool DeleteAllDesktopShortcuts(const base::FilePath& profile_path) {
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE, base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
base::BlockingType::MAY_BLOCK); base::BlockingType::MAY_BLOCK);
std::unique_ptr<base::Environment> env(base::Environment::Create()); std::unique_ptr<base::Environment> env(base::Environment::Create());
bool result = true;
// Delete shortcuts from Desktop. // Delete shortcuts from Desktop.
base::FilePath desktop_path; base::FilePath desktop_path;
if (base::PathService::Get(base::DIR_USER_DESKTOP, &desktop_path)) { if (base::PathService::Get(base::DIR_USER_DESKTOP, &desktop_path)) {
...@@ -478,7 +481,8 @@ void DeleteAllDesktopShortcuts(const base::FilePath& profile_path) { ...@@ -478,7 +481,8 @@ void DeleteAllDesktopShortcuts(const base::FilePath& profile_path) {
shell_integration_linux::GetExistingProfileShortcutFilenames( shell_integration_linux::GetExistingProfileShortcutFilenames(
profile_path, desktop_path); profile_path, desktop_path);
for (const auto& shortcut : shortcut_filenames_desktop) { for (const auto& shortcut : shortcut_filenames_desktop) {
DeleteShortcutOnDesktop(shortcut); if (!DeleteShortcutOnDesktop(shortcut))
result = false;
} }
} }
...@@ -490,8 +494,12 @@ void DeleteAllDesktopShortcuts(const base::FilePath& profile_path) { ...@@ -490,8 +494,12 @@ void DeleteAllDesktopShortcuts(const base::FilePath& profile_path) {
shell_integration_linux::GetExistingProfileShortcutFilenames( shell_integration_linux::GetExistingProfileShortcutFilenames(
profile_path, applications_menu); profile_path, applications_menu);
for (const auto& menu : shortcut_filenames_app_menu) { for (const auto& menu : shortcut_filenames_app_menu) {
DeleteShortcutInApplicationsMenu(menu, base::FilePath(kDirectoryFilename)); if (!DeleteShortcutInApplicationsMenu(menu,
base::FilePath(kDirectoryFilename))) {
result = false;
}
} }
return result;
} }
namespace internals { namespace internals {
...@@ -509,12 +517,13 @@ bool CreatePlatformShortcuts(const base::FilePath& web_app_path, ...@@ -509,12 +517,13 @@ bool CreatePlatformShortcuts(const base::FilePath& web_app_path,
#endif #endif
} }
void DeletePlatformShortcuts(const base::FilePath& web_app_path, bool DeletePlatformShortcuts(const base::FilePath& web_app_path,
const ShortcutInfo& shortcut_info) { const ShortcutInfo& shortcut_info) {
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
DeleteDesktopShortcuts(shortcut_info.profile_path, return DeleteDesktopShortcuts(shortcut_info.profile_path,
shortcut_info.extension_id); shortcut_info.extension_id);
#endif #endif
return true;
} }
void UpdatePlatformShortcuts(const base::FilePath& web_app_path, void UpdatePlatformShortcuts(const base::FilePath& web_app_path,
......
...@@ -49,13 +49,14 @@ ShortcutLocations GetExistingShortcutLocations( ...@@ -49,13 +49,14 @@ ShortcutLocations GetExistingShortcutLocations(
const base::FilePath& desktop_path); const base::FilePath& desktop_path);
// Delete any desktop shortcuts on desktop or in the application menu that have // Delete any desktop shortcuts on desktop or in the application menu that have
// been added for the extension with |extension_id| in |profile_path|. // been added for the extension with |extension_id| in |profile_path|. Returns
void DeleteDesktopShortcuts(const base::FilePath& profile_path, // true on successful deletion.
bool DeleteDesktopShortcuts(const base::FilePath& profile_path,
const std::string& extension_id); const std::string& extension_id);
// Delete any desktop shortcuts on desktop or in the application menu that have // Delete any desktop shortcuts on desktop or in the application menu that have
// for the profile in |profile_path|. // for the profile in |profile_path|. Returns true on successful deletion.
void DeleteAllDesktopShortcuts(const base::FilePath& profile_path); bool DeleteAllDesktopShortcuts(const base::FilePath& profile_path);
} // namespace web_app } // namespace web_app
......
...@@ -1328,15 +1328,19 @@ bool CreatePlatformShortcuts(const base::FilePath& app_data_path, ...@@ -1328,15 +1328,19 @@ bool CreatePlatformShortcuts(const base::FilePath& app_data_path,
return shortcut_creator.CreateShortcuts(creation_reason, creation_locations); return shortcut_creator.CreateShortcuts(creation_reason, creation_locations);
} }
void DeletePlatformShortcuts(const base::FilePath& app_data_path, bool DeletePlatformShortcuts(const base::FilePath& app_data_path,
const ShortcutInfo& shortcut_info) { const ShortcutInfo& shortcut_info) {
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE, base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
base::BlockingType::MAY_BLOCK); base::BlockingType::MAY_BLOCK);
const std::string bundle_id = GetBundleIdentifier(shortcut_info.extension_id, const std::string bundle_id = GetBundleIdentifier(shortcut_info.extension_id,
shortcut_info.profile_path); shortcut_info.profile_path);
auto bundle_infos = SearchForBundlesById(bundle_id); auto bundle_infos = SearchForBundlesById(bundle_id);
for (const auto& bundle_info : bundle_infos) bool result = true;
base::DeletePathRecursively(bundle_info.bundle_path()); for (const auto& bundle_info : bundle_infos) {
if (!base::DeletePathRecursively(bundle_info.bundle_path()))
result = false;
}
return result;
} }
void DeleteMultiProfileShortcutsForApp(const std::string& app_id) { void DeleteMultiProfileShortcutsForApp(const std::string& app_id) {
......
...@@ -229,12 +229,14 @@ bool CreateShortcutsInPaths(const base::FilePath& web_app_path, ...@@ -229,12 +229,14 @@ bool CreateShortcutsInPaths(const base::FilePath& web_app_path,
// for this app were found (and deleted). This will delete duplicate shortcuts, // for this app were found (and deleted). This will delete duplicate shortcuts,
// but only return each path once, even if it contained multiple deleted // but only return each path once, even if it contained multiple deleted
// shortcuts. Both of these may be NULL. // shortcuts. Both of these may be NULL.
void GetShortcutLocationsAndDeleteShortcuts( bool GetShortcutLocationsAndDeleteShortcuts(
const base::FilePath& web_app_path, const base::FilePath& web_app_path,
const base::FilePath& profile_path, const base::FilePath& profile_path,
const base::string16& title, const base::string16& title,
bool* was_pinned_to_taskbar, bool* was_pinned_to_taskbar,
std::vector<base::FilePath>* shortcut_paths) { std::vector<base::FilePath>* shortcut_paths) {
bool result = true;
// Get all possible locations for shortcuts. // Get all possible locations for shortcuts.
web_app::ShortcutLocations all_shortcut_locations; web_app::ShortcutLocations all_shortcut_locations;
all_shortcut_locations.in_quick_launch_bar = true; all_shortcut_locations.in_quick_launch_bar = true;
...@@ -275,9 +277,11 @@ void GetShortcutLocationsAndDeleteShortcuts( ...@@ -275,9 +277,11 @@ void GetShortcutLocationsAndDeleteShortcuts(
// Any shortcut could have been pinned, either by chrome or the user, so // Any shortcut could have been pinned, either by chrome or the user, so
// they are all unpinned. // they are all unpinned.
base::win::UnpinShortcutFromTaskbar(*j); base::win::UnpinShortcutFromTaskbar(*j);
base::DeleteFile(*j); if (base::DeleteFile(*j))
result = false;
} }
} }
return result;
} }
void CreateIconAndSetRelaunchDetails( void CreateIconAndSetRelaunchDetails(
...@@ -472,11 +476,11 @@ void UpdatePlatformShortcuts(const base::FilePath& web_app_path, ...@@ -472,11 +476,11 @@ void UpdatePlatformShortcuts(const base::FilePath& web_app_path,
CheckAndSaveIcon(icon_file, shortcut_info.favicon, true); CheckAndSaveIcon(icon_file, shortcut_info.favicon, true);
} }
void DeletePlatformShortcuts(const base::FilePath& web_app_path, bool DeletePlatformShortcuts(const base::FilePath& web_app_path,
const ShortcutInfo& shortcut_info) { const ShortcutInfo& shortcut_info) {
GetShortcutLocationsAndDeleteShortcuts(web_app_path, bool result = GetShortcutLocationsAndDeleteShortcuts(
shortcut_info.profile_path, web_app_path, shortcut_info.profile_path, shortcut_info.title, nullptr,
shortcut_info.title, NULL, NULL); nullptr);
// If there are no more shortcuts in the Chrome Apps subdirectory, remove it. // If there are no more shortcuts in the Chrome Apps subdirectory, remove it.
base::FilePath chrome_apps_dir; base::FilePath chrome_apps_dir;
...@@ -488,7 +492,9 @@ void DeletePlatformShortcuts(const base::FilePath& web_app_path, ...@@ -488,7 +492,9 @@ void DeletePlatformShortcuts(const base::FilePath& web_app_path,
} }
// Delete downloaded shortcut icons for the web app. // Delete downloaded shortcut icons for the web app.
web_app::internals::DeleteShortcutsMenuIcons(web_app_path); if (!web_app::internals::DeleteShortcutsMenuIcons(web_app_path))
result = false;
return result;
} }
void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) { void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) {
......
...@@ -25,10 +25,12 @@ void RegisterShortcutsMenuWithOs( ...@@ -25,10 +25,12 @@ void RegisterShortcutsMenuWithOs(
DCHECK(ShouldRegisterShortcutsMenuWithOs()); DCHECK(ShouldRegisterShortcutsMenuWithOs());
} }
void UnregisterShortcutsMenuWithOs(const AppId& app_id, bool UnregisterShortcutsMenuWithOs(const AppId& app_id,
const base::FilePath& profile_path) { const base::FilePath& profile_path) {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
DCHECK(ShouldRegisterShortcutsMenuWithOs()); DCHECK(ShouldRegisterShortcutsMenuWithOs());
return true;
} }
#endif // !defined(OS_WIN) #endif // !defined(OS_WIN)
......
...@@ -30,8 +30,8 @@ void RegisterShortcutsMenuWithOs( ...@@ -30,8 +30,8 @@ void RegisterShortcutsMenuWithOs(
const ShortcutsMenuIconsBitmaps& shortcuts_menu_icons_bitmaps); const ShortcutsMenuIconsBitmaps& shortcuts_menu_icons_bitmaps);
// Deletes the ShortcutsMenu from the OS. This should be called during the // Deletes the ShortcutsMenu from the OS. This should be called during the
// uninstallation process. // uninstallation process. Returns true on successful deletion.
void UnregisterShortcutsMenuWithOs(const AppId& app_id, bool UnregisterShortcutsMenuWithOs(const AppId& app_id,
const base::FilePath& profile_path); const base::FilePath& profile_path);
} // namespace web_app } // namespace web_app
......
...@@ -211,22 +211,23 @@ void RegisterShortcutsMenuWithOs( ...@@ -211,22 +211,23 @@ void RegisterShortcutsMenuWithOs(
shortcuts_menu_icons_bitmaps)); shortcuts_menu_icons_bitmaps));
} }
void UnregisterShortcutsMenuWithOs(const AppId& app_id, bool UnregisterShortcutsMenuWithOs(const AppId& app_id,
const base::FilePath& profile_path) { const base::FilePath& profile_path) {
if (!JumpListUpdater::DeleteJumpList( if (!JumpListUpdater::DeleteJumpList(
GenerateAppUserModelId(profile_path, app_id))) { GenerateAppUserModelId(profile_path, app_id))) {
RecordUnregistration(UnregistrationResult::kFailedToDeleteJumpList); RecordUnregistration(UnregistrationResult::kFailedToDeleteJumpList);
return; return false;
} }
RecordUnregistration(UnregistrationResult::kSuccess); RecordUnregistration(UnregistrationResult::kSuccess);
return true;
} }
namespace internals { namespace internals {
void DeleteShortcutsMenuIcons(const base::FilePath& shortcut_data_dir) { bool DeleteShortcutsMenuIcons(const base::FilePath& shortcut_data_dir) {
base::FilePath shortcuts_menu_icons_path = base::FilePath shortcuts_menu_icons_path =
GetShortcutsMenuIconsDirectory(shortcut_data_dir); GetShortcutsMenuIconsDirectory(shortcut_data_dir);
base::DeletePathRecursively(shortcuts_menu_icons_path); return base::DeletePathRecursively(shortcuts_menu_icons_path);
} }
} // namespace internals } // namespace internals
......
...@@ -13,7 +13,7 @@ namespace internals { ...@@ -13,7 +13,7 @@ namespace internals {
// Deletes all .ico shortcuts menu icons that were written to disk at PWA // Deletes all .ico shortcuts menu icons that were written to disk at PWA
// install time. Call this when PWA is uninstalled on Windows. // install time. Call this when PWA is uninstalled on Windows.
void DeleteShortcutsMenuIcons(const base::FilePath& web_app_path); bool DeleteShortcutsMenuIcons(const base::FilePath& web_app_path);
} // namespace internals } // namespace internals
......
...@@ -81,7 +81,7 @@ void BookmarkAppRegistrar::OnExtensionUninstalled( ...@@ -81,7 +81,7 @@ void BookmarkAppRegistrar::OnExtensionUninstalled(
NotifyWebAppUninstalled(extension->id()); NotifyWebAppUninstalled(extension->id());
web_app::WebAppProviderBase::GetProviderBase(profile()) web_app::WebAppProviderBase::GetProviderBase(profile())
->os_integration_manager() ->os_integration_manager()
.UninstallOsHooks(extension->id()); .UninstallOsHooks(extension->id(), base::DoNothing());
bookmark_app_being_observed_ = nullptr; bookmark_app_being_observed_ = nullptr;
} }
...@@ -104,7 +104,7 @@ void BookmarkAppRegistrar::OnExtensionUnloaded( ...@@ -104,7 +104,7 @@ void BookmarkAppRegistrar::OnExtensionUnloaded(
NotifyWebAppProfileWillBeDeleted(extension->id()); NotifyWebAppProfileWillBeDeleted(extension->id());
web_app::WebAppProviderBase::GetProviderBase(profile()) web_app::WebAppProviderBase::GetProviderBase(profile())
->os_integration_manager() ->os_integration_manager()
.UninstallOsHooks(extension->id()); .UninstallOsHooks(extension->id(), base::DoNothing());
} }
bookmark_app_being_observed_ = nullptr; bookmark_app_being_observed_ = nullptr;
......
...@@ -268,9 +268,8 @@ void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) { ...@@ -268,9 +268,8 @@ void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) {
ShortcutInfoForExtensionAndProfile(app, profile)); ShortcutInfoForExtensionAndProfile(app, profile));
base::FilePath shortcut_data_dir = base::FilePath shortcut_data_dir =
internals::GetShortcutDataDir(*shortcut_info); internals::GetShortcutDataDir(*shortcut_info);
internals::PostShortcutIOTask( internals::ScheduleDeletePlatformShortcuts(
base::BindOnce(&internals::DeletePlatformShortcuts, shortcut_data_dir), shortcut_data_dir, std::move(shortcut_info), base::DoNothing());
std::move(shortcut_info));
} }
void UpdateAllShortcuts(const base::string16& old_app_title, void UpdateAllShortcuts(const base::string16& old_app_title,
......
...@@ -30,11 +30,11 @@ class OsHooksBarrierInfo { ...@@ -30,11 +30,11 @@ class OsHooksBarrierInfo {
explicit OsHooksBarrierInfo(InstallOsHooksCallback done_callback) explicit OsHooksBarrierInfo(InstallOsHooksCallback done_callback)
: done_callback_(std::move(done_callback)) {} : done_callback_(std::move(done_callback)) {}
void Run(OsHookType::Type os_hook, bool created) { void Run(OsHookType::Type os_hook, bool completed) {
DCHECK(!os_hooks_called_[os_hook]); DCHECK(!os_hooks_called_[os_hook]);
os_hooks_called_[os_hook] = true; os_hooks_called_[os_hook] = true;
os_hooks_results_[os_hook] = created; os_hooks_results_[os_hook] = completed;
if (os_hooks_called_.all()) { if (os_hooks_called_.all()) {
std::move(done_callback_).Run(os_hooks_results_); std::move(done_callback_).Run(os_hooks_results_);
...@@ -103,7 +103,7 @@ void OsIntegrationManager::InstallOsHooks( ...@@ -103,7 +103,7 @@ void OsIntegrationManager::InstallOsHooks(
// callback for every type. Developers should double check that Run is // callback for every type. Developers should double check that Run is
// called for every OsHookType::Type. If there is any missing type, the // called for every OsHookType::Type. If there is any missing type, the
// InstallOsHooksCallback will not get run. // InstallOsHooksCallback will not get run.
base::RepeatingCallback<void(OsHookType::Type os_hook, bool created)> base::RepeatingCallback<void(OsHookType::Type os_hook, bool completed)>
barrier = base::BindRepeating( barrier = base::BindRepeating(
&OsHooksBarrierInfo::Run, &OsHooksBarrierInfo::Run,
base::Owned(new OsHooksBarrierInfo(std::move(callback)))); base::Owned(new OsHooksBarrierInfo(std::move(callback))));
...@@ -127,12 +127,24 @@ void OsIntegrationManager::InstallOsHooks( ...@@ -127,12 +127,24 @@ void OsIntegrationManager::InstallOsHooks(
} }
} }
void OsIntegrationManager::UninstallOsHooks(const AppId& app_id) { void OsIntegrationManager::UninstallOsHooks(const AppId& app_id,
UninstallOsHooksCallback callback) {
DCHECK(shortcut_manager_);
if (suppress_os_hooks_for_testing_) if (suppress_os_hooks_for_testing_)
return; return;
if (ShouldRegisterShortcutsMenuWithOs()) base::RepeatingCallback<void(OsHookType::Type os_hook, bool completed)>
UnregisterShortcutsMenuWithOs(app_id, profile_->GetPath()); barrier = base::BindRepeating(
&OsHooksBarrierInfo::Run,
base::Owned(new OsHooksBarrierInfo(std::move(callback))));
if (ShouldRegisterShortcutsMenuWithOs()) {
barrier.Run(OsHookType::kShortcutsMenu,
UnregisterShortcutsMenuWithOs(app_id, profile_->GetPath()));
} else {
barrier.Run(OsHookType::kShortcutsMenu, /*completed=*/true);
}
std::unique_ptr<ShortcutInfo> shortcut_info = std::unique_ptr<ShortcutInfo> shortcut_info =
shortcut_manager_->BuildShortcutInfo(app_id); shortcut_manager_->BuildShortcutInfo(app_id);
...@@ -140,17 +152,19 @@ void OsIntegrationManager::UninstallOsHooks(const AppId& app_id) { ...@@ -140,17 +152,19 @@ void OsIntegrationManager::UninstallOsHooks(const AppId& app_id) {
internals::GetShortcutDataDir(*shortcut_info); internals::GetShortcutDataDir(*shortcut_info);
if (base::FeatureList::IsEnabled(features::kDesktopPWAsRunOnOsLogin)) { if (base::FeatureList::IsEnabled(features::kDesktopPWAsRunOnOsLogin)) {
internals::GetShortcutIOTaskRunner()->PostTask( ScheduleUnregisterRunOnOsLogin(
FROM_HERE, shortcut_info->profile_path, shortcut_info->title,
base::BindOnce(&internals::UnregisterRunOnOsLogin, base::BindOnce(barrier, OsHookType::kRunOnOsLogin));
shortcut_info->profile_path, shortcut_info->title));
} }
internals::PostShortcutIOTask( internals::ScheduleDeletePlatformShortcuts(
base::BindOnce(&internals::DeletePlatformShortcuts, shortcut_data_dir), shortcut_data_dir, std::move(shortcut_info),
std::move(shortcut_info)); base::BindOnce(barrier, OsHookType::kShortcuts));
// TODO(https://crbug.com/1108109) we should return the result of file handler
// unregistration and record errors during unregistration.
file_handler_manager_->DisableAndUnregisterOsFileHandlers(app_id); file_handler_manager_->DisableAndUnregisterOsFileHandlers(app_id);
barrier.Run(OsHookType::kFileHandlers, /*completed=*/true);
DeleteSharedAppShims(app_id); DeleteSharedAppShims(app_id);
} }
...@@ -169,12 +183,12 @@ void OsIntegrationManager::OnShortcutsCreated( ...@@ -169,12 +183,12 @@ void OsIntegrationManager::OnShortcutsCreated(
DCHECK(file_handler_manager_); DCHECK(file_handler_manager_);
DCHECK(ui_manager_); DCHECK(ui_manager_);
barrier_callback.Run(OsHookType::kShortcuts, true); barrier_callback.Run(OsHookType::kShortcuts, /*completed=*/true);
// 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); file_handler_manager_->EnableAndRegisterOsFileHandlers(app_id);
barrier_callback.Run(OsHookType::kFileHandlers, true); barrier_callback.Run(OsHookType::kFileHandlers, /*completed=*/true);
if (options.add_to_quick_launch_bar && if (options.add_to_quick_launch_bar &&
ui_manager_->CanAddAppToQuickLaunchBar()) { ui_manager_->CanAddAppToQuickLaunchBar()) {
...@@ -187,13 +201,13 @@ void OsIntegrationManager::OnShortcutsCreated( ...@@ -187,13 +201,13 @@ void OsIntegrationManager::OnShortcutsCreated(
web_app_info->shortcuts_menu_icons_bitmaps); web_app_info->shortcuts_menu_icons_bitmaps);
// TODO(https://crbug.com/1098471): fix RegisterShortcutsMenuWithOs to // TODO(https://crbug.com/1098471): fix RegisterShortcutsMenuWithOs to
// take callback. // take callback.
barrier_callback.Run(OsHookType::kShortcutsMenu, true); barrier_callback.Run(OsHookType::kShortcutsMenu, /*completed=*/true);
} else { } else {
shortcut_manager_->ReadAllShortcutsMenuIconsAndRegisterShortcutsMenu( shortcut_manager_->ReadAllShortcutsMenuIconsAndRegisterShortcutsMenu(
app_id, base::BindOnce(barrier_callback, OsHookType::kShortcutsMenu)); app_id, base::BindOnce(barrier_callback, OsHookType::kShortcutsMenu));
} }
} else { } else {
barrier_callback.Run(OsHookType::kShortcutsMenu, false); barrier_callback.Run(OsHookType::kShortcutsMenu, /*completed=*/false);
} }
if (base::FeatureList::IsEnabled(features::kDesktopPWAsRunOnOsLogin) && if (base::FeatureList::IsEnabled(features::kDesktopPWAsRunOnOsLogin) &&
......
...@@ -34,11 +34,14 @@ struct InstallOsHooksOptions { ...@@ -34,11 +34,14 @@ struct InstallOsHooksOptions {
bool run_on_os_login = false; bool run_on_os_login = false;
}; };
// Callback made when InstallOsHooks has finished trying to deploy all // Callback made after InstallOsHooks is finished.
// needed OS hooks.
using InstallOsHooksCallback = using InstallOsHooksCallback =
base::OnceCallback<void(OsHooksResults os_hooks_info)>; base::OnceCallback<void(OsHooksResults os_hooks_info)>;
// Callback made after UninstallOsHooks is finished.
using UninstallOsHooksCallback =
base::OnceCallback<void(OsHooksResults os_hooks_info)>;
// OsIntegrationManager is responsible of creating/updating/deleting // OsIntegrationManager is responsible of creating/updating/deleting
// all OS hooks during Web App lifecycle. // all OS hooks during Web App lifecycle.
// It contains individual OS integration managers and takes // It contains individual OS integration managers and takes
...@@ -67,7 +70,8 @@ class OsIntegrationManager { ...@@ -67,7 +70,8 @@ class OsIntegrationManager {
// Uninstall all OS hooks for the web app. // Uninstall all OS hooks for the web app.
// TODO(https://crbug.com/1108109) we should record uninstall result and allow // TODO(https://crbug.com/1108109) we should record uninstall result and allow
// callback. virtual for testing // callback. virtual for testing
virtual void UninstallOsHooks(const AppId& app_id); virtual void UninstallOsHooks(const AppId& app_id,
UninstallOsHooksCallback callback);
void SuppressOsHooksForTesting(); void SuppressOsHooksForTesting();
......
...@@ -57,7 +57,9 @@ void TestOsIntegrationManager::InstallOsHooks( ...@@ -57,7 +57,9 @@ void TestOsIntegrationManager::InstallOsHooks(
base::BindOnce(std::move(callback), std::move(os_hooks_results))); base::BindOnce(std::move(callback), std::move(os_hooks_results)));
} }
void TestOsIntegrationManager::UninstallOsHooks(const AppId& app_id) { void TestOsIntegrationManager::UninstallOsHooks(
const AppId& app_id,
UninstallOsHooksCallback callback) {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
......
...@@ -23,7 +23,8 @@ class TestOsIntegrationManager : public OsIntegrationManager { ...@@ -23,7 +23,8 @@ class TestOsIntegrationManager : public OsIntegrationManager {
InstallOsHooksCallback callback, InstallOsHooksCallback callback,
std::unique_ptr<WebApplicationInfo> web_app_info, std::unique_ptr<WebApplicationInfo> web_app_info,
InstallOsHooksOptions options) override; InstallOsHooksOptions options) override;
void UninstallOsHooks(const AppId& app_id) override; void UninstallOsHooks(const AppId& app_id,
UninstallOsHooksCallback callback) override;
size_t num_create_shortcuts_calls() const { size_t num_create_shortcuts_calls() const {
return num_create_shortcuts_calls_; return num_create_shortcuts_calls_;
......
...@@ -384,7 +384,7 @@ void WebAppInstallFinalizer::UninstallWebApp(const AppId& app_id, ...@@ -384,7 +384,7 @@ void WebAppInstallFinalizer::UninstallWebApp(const AppId& app_id,
registrar().NotifyWebAppUninstalled(app_id); registrar().NotifyWebAppUninstalled(app_id);
WebAppProviderBase::GetProviderBase(profile_) WebAppProviderBase::GetProviderBase(profile_)
->os_integration_manager() ->os_integration_manager()
.UninstallOsHooks(app_id); .UninstallOsHooks(app_id, base::DoNothing());
ScopedRegistryUpdate update(registry_controller().AsWebAppSyncBridge()); ScopedRegistryUpdate update(registry_controller().AsWebAppSyncBridge());
update->DeleteApp(app_id); update->DeleteApp(app_id);
......
...@@ -191,7 +191,7 @@ void WebAppRegistrar::OnProfileMarkedForPermanentDeletion( ...@@ -191,7 +191,7 @@ void WebAppRegistrar::OnProfileMarkedForPermanentDeletion(
NotifyWebAppProfileWillBeDeleted(app.app_id()); NotifyWebAppProfileWillBeDeleted(app.app_id());
WebAppProviderBase::GetProviderBase(profile()) WebAppProviderBase::GetProviderBase(profile())
->os_integration_manager() ->os_integration_manager()
.UninstallOsHooks(app.app_id()); .UninstallOsHooks(app.app_id(), base::DoNothing());
} }
// We can't do registry_.clear() here because it makes in-memory registry // We can't do registry_.clear() here because it makes in-memory registry
// diverged from the sync server registry and from the on-disk registry // diverged from the sync server registry and from the on-disk registry
......
...@@ -513,7 +513,7 @@ void WebAppSyncBridge::ApplySyncChangesToRegistrar( ...@@ -513,7 +513,7 @@ void WebAppSyncBridge::ApplySyncChangesToRegistrar(
registrar_->NotifyWebAppUninstalled(app_id); registrar_->NotifyWebAppUninstalled(app_id);
WebAppProviderBase::GetProviderBase(profile()) WebAppProviderBase::GetProviderBase(profile())
->os_integration_manager() ->os_integration_manager()
.UninstallOsHooks(app_id); .UninstallOsHooks(app_id, base::DoNothing());
} }
std::vector<WebApp*> apps_to_install; std::vector<WebApp*> apps_to_install;
......
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