diff options
author | rvargas <rvargas@chromium.org> | 2015-03-17 18:36:33 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-18 01:37:05 +0000 |
commit | 486b2f5612c0f9711d6fced550d7ed904fea4319 (patch) | |
tree | 2c47ea91fe136b689fac00badd324d18e94e58e7 /cloud_print/service/win | |
parent | 0017478eedcbdb70040454ef30f1993ee7752f05 (diff) | |
download | chromium_src-486b2f5612c0f9711d6fced550d7ed904fea4319.zip chromium_src-486b2f5612c0f9711d6fced550d7ed904fea4319.tar.gz chromium_src-486b2f5612c0f9711d6fced550d7ed904fea4319.tar.bz2 |
Remove uses of KillProcess()
BUG=417532
Review URL: https://codereview.chromium.org/999033003
Cr-Commit-Position: refs/heads/master@{#321045}
Diffstat (limited to 'cloud_print/service/win')
-rw-r--r-- | cloud_print/service/win/chrome_launcher.cc | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/cloud_print/service/win/chrome_launcher.cc b/cloud_print/service/win/chrome_launcher.cc index 2b1ce80..adf9c24 100644 --- a/cloud_print/service/win/chrome_launcher.cc +++ b/cloud_print/service/win/chrome_launcher.cc @@ -10,7 +10,7 @@ #include "base/files/scoped_temp_dir.h" #include "base/json/json_reader.h" #include "base/json/json_writer.h" -#include "base/process/kill.h" +#include "base/process/process.h" #include "base/process/process.h" #include "base/values.h" #include "base/win/registry.h" @@ -37,13 +37,14 @@ static const base::char16 kAutoRunKeyPath[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; // Terminates any process. -void ShutdownChrome(HANDLE process, DWORD thread_id) { +void ShutdownChrome(base::Process process, DWORD thread_id) { if (::PostThreadMessage(thread_id, WM_QUIT, 0, 0) && - WAIT_OBJECT_0 == ::WaitForSingleObject(process, kShutdownTimeoutMs)) { + WAIT_OBJECT_0 == ::WaitForSingleObject(process.Handle(), + kShutdownTimeoutMs)) { return; } LOG(ERROR) << "Failed to shutdown process."; - base::KillProcess(process, 0, true); + process.Terminate(0, true); } BOOL CALLBACK CloseIfPidEqual(HWND wnd, LPARAM lparam) { @@ -59,12 +60,13 @@ void CloseAllProcessWindows(HANDLE process) { } // Close Chrome browser window. -void CloseChrome(HANDLE process, DWORD thread_id) { - CloseAllProcessWindows(process); - if (WAIT_OBJECT_0 == ::WaitForSingleObject(process, kShutdownTimeoutMs)) { +void CloseChrome(base::Process process, DWORD thread_id) { + CloseAllProcessWindows(process.Handle()); + if (WAIT_OBJECT_0 == + ::WaitForSingleObject(process.Handle(), kShutdownTimeoutMs)) { return; } - ShutdownChrome(process, thread_id); + ShutdownChrome(process.Pass(), thread_id); } bool LaunchProcess(const base::CommandLine& cmdline, @@ -224,8 +226,11 @@ void ChromeLauncher::Run() { base::Time started = base::Time::Now(); DWORD thread_id = 0; LaunchProcess(cmd, &chrome_handle, &thread_id); + base::Process chrome_process; + if (chrome_handle.IsValid()) + chrome_process = base::Process(chrome_handle.Take()); - HANDLE handles[] = { stop_event_.handle(), chrome_handle.Get() }; + HANDLE handles[] = { stop_event_.handle(), chrome_process.Handle() }; DWORD wait_result = WAIT_TIMEOUT; while (wait_result == WAIT_TIMEOUT) { cloud_print::SetGoogleUpdateUsage(kGoogleUpdateId); @@ -233,7 +238,7 @@ void ChromeLauncher::Run() { FALSE, kUsageUpdateTimeoutMs); } if (wait_result == WAIT_OBJECT_0) { - ShutdownChrome(chrome_handle.Get(), thread_id); + ShutdownChrome(chrome_process.Pass(), thread_id); break; } else if (wait_result == WAIT_OBJECT_0 + 1) { LOG(ERROR) << "Chrome process exited."; @@ -302,9 +307,10 @@ std::string ChromeLauncher::CreateServiceStateFile( LOG(ERROR) << "Unable to launch Chrome."; return std::string(); } + base::Process chrome_process(chrome_handle.Take()); for (;;) { - DWORD wait_result = ::WaitForSingleObject(chrome_handle.Get(), 500); + DWORD wait_result = ::WaitForSingleObject(chrome_process.Handle(), 500); std::string json = ReadAndUpdateServiceState(temp_user_data.path(), proxy_id); if (wait_result == WAIT_OBJECT_0) { @@ -317,7 +323,7 @@ std::string ChromeLauncher::CreateServiceStateFile( } if (!json.empty()) { // Close chrome because Service State is ready. - CloseChrome(chrome_handle.Get(), thread_id); + CloseChrome(chrome_process.Pass(), thread_id); return json; } } |