diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-09 22:44:57 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-09 22:44:57 +0000 |
commit | 6aa9349ef5c1110d9c096945840e6a105e8a8295 (patch) | |
tree | 8afce0e1f3aae77e05105cfbe0d24ea3bdae9106 /chrome/test/chrome_process_util.cc | |
parent | b61236c6679615af0811d59d130c91397d8c6be7 (diff) | |
download | chromium_src-6aa9349ef5c1110d9c096945840e6a105e8a8295.zip chromium_src-6aa9349ef5c1110d9c096945840e6a105e8a8295.tar.gz chromium_src-6aa9349ef5c1110d9c096945840e6a105e8a8295.tar.bz2 |
Replace chrome_process_filter with chrome_process_util.
- move code only used by tests to chrome/test
- make a better, more portable abstraction
For now, it still only works on Windows. But this is the first step
to porting this part of code.
Patch by phajdan.jr@chromium.org: <http://codereview.chromium.org/54003>
Review URL: http://codereview.chromium.org/67004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13476 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/chrome_process_util.cc')
-rw-r--r-- | chrome/test/chrome_process_util.cc | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/chrome/test/chrome_process_util.cc b/chrome/test/chrome_process_util.cc new file mode 100644 index 0000000..128ec33 --- /dev/null +++ b/chrome/test/chrome_process_util.cc @@ -0,0 +1,50 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/test/chrome_process_util.h" + +#include <vector> + +#include "base/process_util.h" +#include "base/time.h" +#include "chrome/common/result_codes.h" + +using base::Time; +using base::TimeDelta; + +void TerminateAllChromeProcesses(const FilePath& data_dir) { + // Total time the function will wait for chrome processes + // to terminate after it told them to do so. + const TimeDelta kExitTimeout = TimeDelta::FromMilliseconds(5000); + + ChromeProcessList process_pids(GetRunningChromeProcesses(data_dir)); + + std::vector<base::ProcessHandle> handles; + { + ChromeProcessList::const_iterator it; + for (it = process_pids.begin(); it != process_pids.end(); ++it) { + base::ProcessHandle handle; + // Ignore processes for which we can't open the handle. We don't guarantee + // that all processes will terminate, only try to do so. + if (base::OpenProcessHandle(*it, &handle)) + handles.push_back(handle); + } + } + + std::vector<base::ProcessHandle>::const_iterator it; + for (it = handles.begin(); it != handles.end(); ++it) + base::KillProcess(*it, ResultCodes::TASKMAN_KILL, false); + + const Time start = Time::Now(); + for (it = handles.begin(); + it != handles.end() && Time::Now() - start < kExitTimeout; + ++it) { + // TODO(phajdan.jr): Fix int/int64 problems with TimeDelta::InMilliseconds. + int wait_time_ms = static_cast<int>((Time::Now() - start).InMilliseconds()); + base::WaitForSingleProcess(*it, wait_time_ms); + } + + for (it = handles.begin(); it != handles.end(); ++it) + base::CloseProcessHandle(*it); +} |