summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authormaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-11 19:10:30 +0000
committermaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-11 19:10:30 +0000
commitbaead4f9f167731fc67d6fe5e8d8270057c7e530 (patch)
treed990edeb0aed8a1cab94421f066835eef8f57128 /base
parentd50ec48c066f8933357da543ae3b93ab3c983759 (diff)
downloadchromium_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
Diffstat (limited to 'base')
-rw-r--r--base/process_util.cc4
-rw-r--r--base/process_util.h4
-rw-r--r--base/process_util_unittest.cc35
3 files changed, 26 insertions, 17 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