Commit 486b2f56 authored by rvargas's avatar rvargas Committed by Commit bot

Remove uses of KillProcess()

BUG=417532

Review URL: https://codereview.chromium.org/999033003

Cr-Commit-Position: refs/heads/master@{#321045}
parent 0017478e
......@@ -8,8 +8,8 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "base/process/kill.h"
#include "base/process/launch.h"
#include "base/process/process.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
......@@ -163,7 +163,7 @@ bool NativeProcessLauncher::LaunchNativeProcess(
bool stdin_connected = ConnectNamedPipe(stdin_pipe.Get(), NULL) ?
TRUE : GetLastError() == ERROR_PIPE_CONNECTED;
if (!stdout_connected || !stdin_connected) {
base::KillProcess(cmd_process.Handle(), 0, false);
cmd_process.Terminate(0, false);
LOG(ERROR) << "Failed to connect IO pipes when starting "
<< command_line.GetProgram().MaybeAsASCII();
return false;
......
......@@ -11,7 +11,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/prefs/pref_service.h"
#include "base/process/kill.h"
#include "base/process/process.h"
#include "base/process/process_handle.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
......@@ -306,7 +306,7 @@ void SessionEnding() {
// termination as soon as it hides or destroys its windows. Since any
// execution past that point will be non-deterministically cut short, we
// might as well put ourselves out of that misery deterministically.
base::KillProcess(base::GetCurrentProcessHandle(), 0, false);
base::Process::Current().Terminate(0, false);
}
void IncrementKeepAliveCount() {
......
......@@ -66,11 +66,11 @@ class WebRtcApprtcBrowserTest : public WebRtcTestBase {
// especially if the test hangs or if we're on Windows.
LOG(INFO) << "Entering TearDown";
if (dev_appserver_.IsValid())
base::KillProcess(dev_appserver_.Handle(), 0, false);
dev_appserver_.Terminate(0, false);
if (collider_server_.IsValid())
base::KillProcess(collider_server_.Handle(), 0, false);
collider_server_.Terminate(0, false);
if (firefox_.IsValid())
base::KillProcess(firefox_.Handle(), 0, false);
firefox_.Terminate(0, false);
LOG(INFO) << "Exiting TearDown";
}
......
......@@ -6,7 +6,6 @@
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/process/kill.h"
#include "base/process/launch.h"
#include "chrome/browser/media/test_license_server_config.h"
......@@ -50,8 +49,7 @@ bool TestLicenseServer::Stop() {
if (!license_server_process_.IsValid())
return true;
DVLOG(0) << "Killing license server.";
bool kill_succeeded =
base::KillProcess(license_server_process_.Handle(), 1, true);
bool kill_succeeded = license_server_process_.Terminate(1, true);
if (kill_succeeded) {
license_server_process_.Close();
......
......@@ -14,9 +14,8 @@
#include "base/logging.h"
#include "base/mac/mac_util.h"
#include "base/posix/eintr_wrapper.h"
#include "base/process/kill.h"
#include "base/process/launch.h"
#include "base/process/process_handle.h"
#include "base/process/process.h"
#include "base/process/process_metrics.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -143,6 +142,6 @@ TEST_F(ProcessInfoSnapshotMacTest, EffectiveVsRealUserIDTest) {
// Real user ID should match the calling process's user id.
EXPECT_EQ(proc_info.uid, geteuid());
ASSERT_TRUE(base::KillProcess(process.Handle(), 0, true));
ASSERT_TRUE(process.Terminate(0, true));
PCHECK(IGNORE_EINTR(close(fds[0])) == 0);
}
......@@ -16,7 +16,6 @@
#include "base/files/scoped_temp_dir.h"
#include "base/memory/ref_counted.h"
#include "base/path_service.h"
#include "base/process/kill.h"
#include "base/process/launch.h"
#include "base/process/process.h"
#include "base/process/process_iterator.h"
......@@ -160,7 +159,7 @@ class ProcessSingletonTest : public InProcessBrowserTest {
// flaky wait. Instead, we kill all descendants of the main process after we
// killed it, relying on the fact that we can still get the parent id of a
// child process, even when the parent dies.
void KillProcessTree(base::ProcessHandle process_handle) {
void KillProcessTree(const base::Process& process) {
class ProcessTreeFilter : public base::ProcessFilter {
public:
explicit ProcessTreeFilter(base::ProcessId parent_pid) {
......@@ -176,11 +175,11 @@ class ProcessSingletonTest : public InProcessBrowserTest {
}
private:
mutable std::set<base::ProcessId> ancestor_pids_;
} process_tree_filter(base::GetProcId(process_handle));
} process_tree_filter(process.Pid());
// Start by explicitly killing the main process we know about...
static const int kExitCode = 42;
EXPECT_TRUE(base::KillProcess(process_handle, kExitCode, true /* wait */));
EXPECT_TRUE(process.Terminate(kExitCode, true /* wait */));
// Then loop until we can't find any of its descendant.
// But don't try more than kNbTries times...
......@@ -303,7 +302,7 @@ IN_PROC_BROWSER_TEST_F(ProcessSingletonTest, MAYBE_StartupRaceCondition) {
// But we let the last loop turn finish so that we can properly
// kill all remaining processes. Starting with this one...
if (chrome_starters_[starter_index]->process_.IsValid()) {
KillProcessTree(chrome_starters_[starter_index]->process_.Handle());
KillProcessTree(chrome_starters_[starter_index]->process_);
}
}
pending_starters.erase(pending_starters.begin() + done_index);
......@@ -314,7 +313,7 @@ IN_PROC_BROWSER_TEST_F(ProcessSingletonTest, MAYBE_StartupRaceCondition) {
size_t last_index = pending_starters.front();
pending_starters.clear();
if (chrome_starters_[last_index]->process_.IsValid()) {
KillProcessTree(chrome_starters_[last_index]->process_.Handle());
KillProcessTree(chrome_starters_[last_index]->process_);
chrome_starters_[last_index]->done_event_.Wait();
}
}
......
......@@ -10,7 +10,6 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/process/kill.h"
#include "base/process/process.h"
#include "base/process/process_info.h"
#include "base/strings/string_number_conversions.h"
......@@ -301,7 +300,7 @@ ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() {
funnel.RecordEvent(L"HungBrowserTerminated");
// Time to take action. Kill the browser process.
base::KillProcess(process.Handle(), content::RESULT_CODE_HUNG, true);
process.Terminate(content::RESULT_CODE_HUNG, true);
remote_window_ = NULL;
return PROCESS_NONE;
}
......
......@@ -839,7 +839,7 @@ bool SyncTest::TearDownLocalPythonTestServer() {
bool SyncTest::TearDownLocalTestServer() {
if (test_server_.IsValid()) {
EXPECT_TRUE(base::KillProcess(test_server_.Handle(), 0, false))
EXPECT_TRUE(test_server_.Terminate(0, false))
<< "Could not stop local test server.";
test_server_.Close();
}
......
......@@ -15,9 +15,7 @@
#include "base/logging.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/metrics/histogram.h"
#include "base/process/kill.h"
#include "base/process/launch.h"
#include "base/process/process_handle.h"
#include "base/task_runner_util.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_utility_printing_messages.h"
......@@ -163,7 +161,7 @@ ServiceUtilityProcessHost::ServiceUtilityProcessHost(
ServiceUtilityProcessHost::~ServiceUtilityProcessHost() {
// We need to kill the child process when the host dies.
base::KillProcess(process_.Handle(), content::RESULT_CODE_NORMAL_EXIT, false);
process_.Terminate(content::RESULT_CODE_NORMAL_EXIT, false);
}
bool ServiceUtilityProcessHost::StartRenderPDFPagesToMetafile(
......
......@@ -9,7 +9,6 @@
#include <vector>
#include "base/command_line.h"
#include "base/process/kill.h"
#include "base/process/process.h"
#include "base/process/process_iterator.h"
#include "base/time/time.h"
......@@ -54,7 +53,7 @@ void TerminateAllChromeProcesses(const ChromeProcessList& process_pids) {
if (process.IsValid()) {
// Ignore processes for which we can't open the handle. We don't
// guarantee that all processes will terminate, only try to do so.
base::KillProcess(process.Handle(), content::RESULT_CODE_KILLED, true);
process.Terminate(content::RESULT_CODE_KILLED, true);
}
}
}
......
......@@ -27,15 +27,15 @@
namespace {
bool KillProcess(base::ProcessHandle process_id, bool kill_gracefully) {
bool KillProcess(const base::Process& process, bool kill_gracefully) {
#if defined(OS_POSIX)
if (!kill_gracefully) {
kill(process_id, SIGKILL);
kill(process.Pid(), SIGKILL);
base::TimeTicks deadline =
base::TimeTicks::Now() + base::TimeDelta::FromSeconds(30);
while (base::TimeTicks::Now() < deadline) {
pid_t pid = HANDLE_EINTR(waitpid(process_id, NULL, WNOHANG));
if (pid == process_id)
pid_t pid = HANDLE_EINTR(waitpid(process.Pid(), NULL, WNOHANG));
if (pid == process.Pid())
return true;
if (pid == -1) {
if (errno == ECHILD) {
......@@ -43,7 +43,7 @@ bool KillProcess(base::ProcessHandle process_id, bool kill_gracefully) {
// the same pid, causing the process state to get cleaned up.
return true;
}
LOG(WARNING) << "Error waiting for process " << process_id;
LOG(WARNING) << "Error waiting for process " << process.Pid();
}
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(50));
}
......@@ -51,9 +51,9 @@ bool KillProcess(base::ProcessHandle process_id, bool kill_gracefully) {
}
#endif
if (!base::KillProcess(process_id, 0, true)) {
if (!process.Terminate(0, true)) {
int exit_code;
return base::GetTerminationStatus(process_id, &exit_code) !=
return base::GetTerminationStatus(process.Handle(), &exit_code) !=
base::TERMINATION_STATUS_STILL_RUNNING;
}
return true;
......@@ -173,7 +173,7 @@ Status ChromeDesktopImpl::QuitImpl() {
// everything back out to the user data directory and exit cleanly.If
// we're using a temporary user data directory, we're going to delete
// the temporary directory anyway, so just send SIGKILL immediately.
if (!KillProcess(process_.Handle(), !user_data_dir_.IsValid()))
if (!KillProcess(process_, !user_data_dir_.IsValid()))
return Status(kUnknownError, "cannot kill Chrome");
return Status(kOk);
}
......
......@@ -20,6 +20,7 @@
#include "base/logging.h"
#include "base/process/kill.h"
#include "base/process/launch.h"
#include "base/process/process.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
......@@ -387,7 +388,7 @@ Status LaunchDesktopChrome(
return Status(kUnknownError,
"Chrome failed to start: " + termination_reason);
}
if (!base::KillProcess(process.Handle(), 0, true)) {
if (!process.Terminate(0, true)) {
int exit_code;
if (base::GetTerminationStatus(process.Handle(), &exit_code) ==
base::TERMINATION_STATUS_STILL_RUNNING)
......
......@@ -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;
}
}
......
......@@ -16,6 +16,7 @@
#include "base/metrics/histogram.h"
#include "base/process/kill.h"
#include "base/process/launch.h"
#include "base/process/process.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
......@@ -221,7 +222,7 @@ StorageMonitor::EjectStatus EjectPathOnFileThread(
int exit_code = -1;
if (!process.WaitForExitWithTimeout(base::TimeDelta::FromMilliseconds(3000),
&exit_code)) {
base::KillProcess(process.Handle(), -1, false);
process.Terminate(-1, false);
base::EnsureProcessTerminated(process.Pass());
return StorageMonitor::EJECT_FAILURE;
}
......
......@@ -256,8 +256,7 @@ void BrowserChildProcessHostImpl::OnBadMessageReceived(
switches::kDisableKillAfterBadIPC)) {
return;
}
base::KillProcess(child_process_->GetProcess().Handle(),
RESULT_CODE_KILLED_BAD_MESSAGE, false);
child_process_->GetProcess().Terminate(RESULT_CODE_KILLED_BAD_MESSAGE, false);
}
bool BrowserChildProcessHostImpl::CanShutdown() {
......
......@@ -18,7 +18,7 @@
#include "base/message_loop/message_loop.h"
#include "base/message_loop/timer_slack.h"
#include "base/metrics/field_trial.h"
#include "base/process/kill.h"
#include "base/process/process.h"
#include "base/process/process_handle.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
......@@ -713,7 +713,7 @@ void ChildThreadImpl::OnProcessFinalRelease() {
void ChildThreadImpl::EnsureConnected() {
VLOG(0) << "ChildThreadImpl::EnsureConnected()";
base::KillProcess(base::GetCurrentProcessHandle(), 0, false);
base::Process::Current().Terminate(0, false);
}
void ChildThreadImpl::OnProcessBackgrounded(bool background) {
......
......@@ -16,8 +16,7 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "base/process/kill.h"
#include "base/process/process_handle.h"
#include "base/process/process.h"
#include "base/threading/thread_local.h"
#include "content/child/blink_platform_impl.h"
#include "content/child/child_process.h"
......@@ -57,7 +56,7 @@ class EnsureTerminateMessageFilter : public IPC::MessageFilter {
private:
void Terminate() {
base::KillProcess(base::GetCurrentProcessHandle(), 0, false);
base::Process::Current().Terminate(0, false);
}
};
......@@ -116,7 +115,7 @@ void PluginThread::Shutdown() {
PluginLib::UnloadAllPlugins();
if (forcefully_terminate_plugin_process_)
base::KillProcess(base::GetCurrentProcessHandle(), 0, /* wait= */ false);
base::Process::Current().Terminate(0, /* wait= */ false);
lazy_tls.Pointer()->Set(NULL);
}
......
......@@ -14,7 +14,6 @@
#include "base/debug/dump_without_crashing.h"
#include "base/i18n/char_iterator.h"
#include "base/metrics/histogram.h"
#include "base/process/kill.h"
#include "base/process/process.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
......@@ -339,7 +338,7 @@ void MaybeHandleDebugURL(const GURL& url) {
// of base::debug::DumpWithoutCrashing for more details.
base::debug::DumpWithoutCrashing();
} else if (url == GURL(kChromeUIKillURL)) {
base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
base::Process::Current().Terminate(1, false);
} else if (url == GURL(kChromeUIHangURL)) {
for (;;) {
base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
......
......@@ -18,7 +18,7 @@
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "base/posix/eintr_wrapper.h"
#include "base/process/kill.h"
#include "base/process/process.h"
#include "base/test/multiprocess_test.h"
#include "base/test/test_timeouts.h"
#include "ipc/ipc_listener.h"
......@@ -339,7 +339,7 @@ TEST_F(IPCChannelPosixTest, ResetState) {
IPC::Message::PRIORITY_NORMAL);
channel->Send(message);
SpinRunLoop(TestTimeouts::action_timeout());
EXPECT_TRUE(base::KillProcess(process.Handle(), 0, false));
EXPECT_TRUE(process.Terminate(0, false));
int exit_code = 0;
EXPECT_TRUE(process2.WaitForExit(&exit_code));
EXPECT_EQ(0, exit_code);
......
......@@ -8,7 +8,6 @@
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/process/kill.h"
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
#include "net/base/host_port_pair.h"
......@@ -128,7 +127,7 @@ bool LocalTestServer::Stop() {
int exit_code;
bool ret = process_.WaitForExitWithTimeout(base::TimeDelta(), &exit_code);
if (!ret)
ret = base::KillProcess(process_.Handle(), 1, true);
ret = process_.Terminate(1, true);
if (ret)
process_.Close();
......
......@@ -18,9 +18,8 @@
#include "base/logging.h"
#include "base/md5.h"
#include "base/path_service.h"
#include "base/process/kill.h"
#include "base/process/launch.h"
#include "base/process/process_handle.h"
#include "base/process/process.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
......@@ -113,7 +112,7 @@ bool RunHostScriptWithTimeout(
}
if (!process.WaitForExitWithTimeout(timeout, exit_code)) {
base::KillProcess(process.Handle(), 0, false);
process.Terminate(0, false);
LOG(ERROR) << "Timeout exceeded for command: "
<< command_line.GetCommandLineString();
return false;
......
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