diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-11 19:10:30 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-11 19:10:30 +0000 |
commit | baead4f9f167731fc67d6fe5e8d8270057c7e530 (patch) | |
tree | d990edeb0aed8a1cab94421f066835eef8f57128 | |
parent | d50ec48c066f8933357da543ae3b93ab3c983759 (diff) | |
download | chromium_src-baead4f9f167731fc67d6fe5e8d8270057c7e530.zip chromium_src-baead4f9f167731fc67d6fe5e8d8270057c7e530.tar.gz chromium_src-baead4f9f167731fc67d6fe5e8d8270057c7e530.tar.bz2 |
Minor cleanups of usage of process_util code.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2791006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49568 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/process_util.cc | 4 | ||||
-rw-r--r-- | base/process_util.h | 4 | ||||
-rw-r--r-- | base/process_util_unittest.cc | 35 | ||||
-rw-r--r-- | chrome/common/process_watcher_win.cc | 2 | ||||
-rw-r--r-- | chrome/test/ui/ui_test.cc | 4 | ||||
-rw-r--r-- | chrome_frame/test_utils.cc | 2 |
6 files changed, 30 insertions, 21 deletions
diff --git a/base/process_util.cc b/base/process_util.cc index 8814956..f6e0d84 100644 --- a/base/process_util.cc +++ b/base/process_util.cc @@ -43,8 +43,8 @@ bool ProcessIterator::IncludeEntry() { return !filter_ || filter_->Includes(entry_); } -std::list<ProcessEntry> ProcessIterator::Snapshot() { - std::list<ProcessEntry> found; +ProcessIterator::ProcessEntries ProcessIterator::Snapshot() { + ProcessEntries found; while (const ProcessEntry* process_entry = NextProcessEntry()) { found.push_back(*process_entry); } diff --git a/base/process_util.h b/base/process_util.h index d6aed0d..9a28282 100644 --- a/base/process_util.h +++ b/base/process_util.h @@ -327,6 +327,8 @@ bool CleanupProcesses(const std::wstring& executable_name, // false. class ProcessIterator { public: + typedef std::list<ProcessEntry> ProcessEntries; + explicit ProcessIterator(const ProcessFilter* filter); virtual ~ProcessIterator(); @@ -338,7 +340,7 @@ class ProcessIterator { const ProcessEntry* NextProcessEntry(); // Takes a snapshot of all the ProcessEntry found. - std::list<ProcessEntry> Snapshot(); + ProcessEntries Snapshot(); protected: virtual bool IncludeEntry(); diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc index 15405f4..4a42342 100644 --- a/base/process_util_unittest.cc +++ b/base/process_util_unittest.cc @@ -42,6 +42,22 @@ const wchar_t* const kProcessName = L"base_unittests.exe"; const wchar_t* const kProcessName = L"base_unittests"; #endif // defined(OS_WIN) +// Sleeps until file filename is created. +void WaitToDie(const char* filename) { + FILE *fp; + do { + PlatformThread::Sleep(10); + fp = fopen(filename, "r"); + } while (!fp); + fclose(fp); +} + +// Signals children they should die now. +void SignalChildren(const char* filename) { + FILE *fp = fopen(filename, "w"); + fclose(fp); +} + } // namespace class ProcessUtilTest : public MultiProcessTest { @@ -58,22 +74,13 @@ MULTIPROCESS_TEST_MAIN(SimpleChildProcess) { TEST_F(ProcessUtilTest, SpawnChild) { base::ProcessHandle handle = this->SpawnChild(L"SimpleChildProcess"); - ASSERT_NE(base::kNullProcessHandle, handle); EXPECT_TRUE(base::WaitForSingleProcess(handle, 5000)); base::CloseProcessHandle(handle); } MULTIPROCESS_TEST_MAIN(SlowChildProcess) { - // Sleep until file "SlowChildProcess.die" is created. - FILE *fp; - do { - PlatformThread::Sleep(100); - fp = fopen("SlowChildProcess.die", "r"); - } while (!fp); - fclose(fp); - remove("SlowChildProcess.die"); - exit(0); + WaitToDie("SlowChildProcess.die"); return 0; } @@ -81,10 +88,10 @@ TEST_F(ProcessUtilTest, KillSlowChild) { remove("SlowChildProcess.die"); base::ProcessHandle handle = this->SpawnChild(L"SlowChildProcess"); ASSERT_NE(base::kNullProcessHandle, handle); - FILE *fp = fopen("SlowChildProcess.die", "w"); - fclose(fp); + SignalChildren("SlowChildProcess.die"); EXPECT_TRUE(base::WaitForSingleProcess(handle, 5000)); base::CloseProcessHandle(handle); + remove("SlowChildProcess.die"); } TEST_F(ProcessUtilTest, DidProcessCrash) { @@ -96,12 +103,12 @@ TEST_F(ProcessUtilTest, DidProcessCrash) { EXPECT_FALSE(base::DidProcessCrash(&child_exited, handle)); EXPECT_FALSE(child_exited); - FILE *fp = fopen("SlowChildProcess.die", "w"); - fclose(fp); + SignalChildren("SlowChildProcess.die"); EXPECT_TRUE(base::WaitForSingleProcess(handle, 5000)); EXPECT_FALSE(base::DidProcessCrash(&child_exited, handle)); base::CloseProcessHandle(handle); + remove("SlowChildProcess.die"); } // Ensure that the priority of a process is restored correctly after diff --git a/chrome/common/process_watcher_win.cc b/chrome/common/process_watcher_win.cc index 59f7899..2b4e9d8 100644 --- a/chrome/common/process_watcher_win.cc +++ b/chrome/common/process_watcher_win.cc @@ -62,7 +62,7 @@ class TimerExpiredTask : public Task, public base::ObjectWatcher::Delegate { // terminates. We just care that it eventually terminates, and that's what // TerminateProcess should do for us. Don't check for the result code since // it fails quite often. This should be investigated eventually. - TerminateProcess(process_, ResultCodes::HUNG); + base::KillProcess(process_, ResultCodes::HUNG, false); // Now, just cleanup as if the process exited normally. OnObjectSignaled(process_); diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc index 7312b8c..5afd1a7 100644 --- a/chrome/test/ui/ui_test.cc +++ b/chrome/test/ui/ui_test.cc @@ -113,7 +113,7 @@ UITestBase::UITestBase() homepage_(L"about:blank"), wait_for_initial_loads_(true), dom_automation_enabled_(false), - process_(0), // NULL on Windows, 0 PID on POSIX. + process_(base::kNullProcessHandle), process_id_(-1), show_window_(false), clear_profile_(true), @@ -139,7 +139,7 @@ UITestBase::UITestBase(MessageLoop::Type msg_loop_type) homepage_(L"about:blank"), wait_for_initial_loads_(true), dom_automation_enabled_(false), - process_(0), // NULL on Windows, 0 PID on POSIX. + process_(base::kNullProcessHandle), process_id_(-1), show_window_(false), clear_profile_(true), diff --git a/chrome_frame/test_utils.cc b/chrome_frame/test_utils.cc index 6e9f6bf..18f5f44 100644 --- a/chrome_frame/test_utils.cc +++ b/chrome_frame/test_utils.cc @@ -298,7 +298,7 @@ bool KillAllNamedProcessesWithArgument(const std::wstring& process_name, ArgumentFilter filter(argument); base::NamedProcessIterator iter(process_name, &filter); while (const base::ProcessEntry* entry = iter.NextProcessEntry()) { - if (!base::KillProcessById((*entry).th32ProcessID, 0, true)) { + if (!base::KillProcessById(entry->pid(), 0, true)) { DLOG(ERROR) << "Failed to kill process " << (*entry).th32ProcessID; result = false; } |