From 32f720c5a051885d45b79533522c06870e7037ff Mon Sep 17 00:00:00 2001 From: "kuchhal@chromium.org" Date: Mon, 3 Nov 2008 23:13:54 +0000 Subject: On silent uninstall (--force-uninstall) close all Chrome processes without prompting the user. BUG=1445145 Review URL: http://codereview.chromium.org/8943 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4511 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/installer/setup/uninstall.cc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'chrome/installer/setup') diff --git a/chrome/installer/setup/uninstall.cc b/chrome/installer/setup/uninstall.cc index 5136f88..fe62e67 100644 --- a/chrome/installer/setup/uninstall.cc +++ b/chrome/installer/setup/uninstall.cc @@ -12,6 +12,7 @@ #include "base/file_util.h" #include "base/path_service.h" +#include "base/process_util.h" #include "base/registry.h" #include "base/scoped_ptr.h" #include "base/string_util.h" @@ -36,6 +37,34 @@ namespace { +// This functions checks for any Chrome instances that are +// running and first asks them to close politely by sending a Windows message. +// If there is an error while sending message or if there are still Chrome +// procesess active after the message has been sent, this function will try +// to kill them. +void CloseAllChromeProcesses() { + for (int j = 0; j < 4; ++j) { + std::wstring wnd_class(L"Chrome_ContainerWin_"); + wnd_class.append(IntToWString(j)); + HWND window = FindWindowEx(NULL, NULL, wnd_class.c_str(), NULL); + while (window) { + HWND tmpWnd = window; + window = FindWindowEx(NULL, window, wnd_class.c_str(), NULL); + if (!SendMessageTimeout(tmpWnd, WM_CLOSE, 0, 0, SMTO_BLOCK, 3000, NULL) && + (GetLastError() == ERROR_TIMEOUT)) { + process_util::CleanupProcesses(installer_util::kChromeExe, 0, + ResultCodes::HUNG, NULL); + return; + } + } + } + + // If asking politely didn't work, wait for 15 seconds and then kill all + // chrome.exe. This check is just in case Chrome is ignoring WM_CLOSE messages. + process_util::CleanupProcesses(installer_util::kChromeExe, 15000, + ResultCodes::HUNG, NULL); +} + // This method deletes Chrome shortcut folder from Windows Start menu. It // checks system_uninstall to see if the shortcut is in all users start menu // or current user start menu. @@ -183,6 +212,10 @@ installer_util::InstallStatus installer_setup::UninstallChrome( IsChromeActiveOrUserCancelled(system_uninstall); if (status != installer_util::UNINSTALL_CONFIRMED) return status; + } else { + // Since --force-uninstall command line option is used, we are going to + // do silent uninstall. Try to close all running Chrome instances. + CloseAllChromeProcesses(); } #if defined(GOOGLE_CHROME_BUILD) -- cgit v1.1