diff options
-rw-r--r-- | base/base.gypi | 1 | ||||
-rw-r--r-- | base/process.h | 4 | ||||
-rw-r--r-- | base/process_util.cc | 63 | ||||
-rw-r--r-- | base/process_util.h | 77 | ||||
-rw-r--r-- | base/process_util_linux.cc | 58 | ||||
-rw-r--r-- | base/process_util_mac.mm | 84 | ||||
-rw-r--r-- | base/process_util_posix.cc | 54 | ||||
-rw-r--r-- | base/process_util_unittest.cc | 128 | ||||
-rw-r--r-- | base/process_util_win.cc | 64 | ||||
-rw-r--r-- | base/shared_memory.h | 21 | ||||
-rw-r--r-- | chrome/browser/memory_details_mac.cc | 8 | ||||
-rw-r--r-- | chrome/browser/memory_details_win.cc | 2 | ||||
-rw-r--r-- | chrome/browser/process_singleton_win_uitest.cc | 7 | ||||
-rw-r--r-- | chrome/test/chrome_process_util.cc | 14 | ||||
-rw-r--r-- | chrome_frame/test_utils.cc | 4 |
15 files changed, 293 insertions, 296 deletions
diff --git a/base/base.gypi b/base/base.gypi index 20c1a63..22a72f9 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -154,6 +154,7 @@ 'process.h', 'process_linux.cc', 'process_posix.cc', + 'process_util.cc', 'process_util.h', 'process_util_linux.cc', 'process_util_mac.mm', diff --git a/base/process.h b/base/process.h index f52c455..096d1b3 100644 --- a/base/process.h +++ b/base/process.h @@ -9,7 +9,7 @@ #include "build/build_config.h" #include <sys/types.h> -#ifdef OS_WIN +#if defined(OS_WIN) #include <windows.h> #endif @@ -28,7 +28,7 @@ const ProcessHandle kNullProcessHandle = NULL; typedef pid_t ProcessHandle; typedef pid_t ProcessId; const ProcessHandle kNullProcessHandle = 0; -#endif +#endif // defined(OS_WIN) #if defined(OS_POSIX) && !defined(OS_MACOSX) // saved_priority_ will be set to this to indicate that it's not holding diff --git a/base/process_util.cc b/base/process_util.cc new file mode 100644 index 0000000..8814956 --- /dev/null +++ b/base/process_util.cc @@ -0,0 +1,63 @@ +// Copyright (c) 2010 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 "base/process_util.h" + +namespace base { + +int GetProcessCount(const std::wstring& executable_name, + const ProcessFilter* filter) { + int count = 0; + NamedProcessIterator iter(executable_name, filter); + while (iter.NextProcessEntry()) + ++count; + return count; +} + +bool KillProcesses(const std::wstring& executable_name, int exit_code, + const ProcessFilter* filter) { + bool result = true; + NamedProcessIterator iter(executable_name, filter); + while (const ProcessEntry* entry = iter.NextProcessEntry()) { +#if defined(OS_WIN) + result &= KillProcessById(entry->pid(), exit_code, true); +#else + result &= KillProcess(entry->pid(), exit_code, true); +#endif + } + return result; +} + +const ProcessEntry* ProcessIterator::NextProcessEntry() { + bool result = false; + do { + result = CheckForNextProcess(); + } while (result && !IncludeEntry()); + if (result) + return &entry_; + return NULL; +} + +bool ProcessIterator::IncludeEntry() { + return !filter_ || filter_->Includes(entry_); +} + +std::list<ProcessEntry> ProcessIterator::Snapshot() { + std::list<ProcessEntry> found; + while (const ProcessEntry* process_entry = NextProcessEntry()) { + found.push_back(*process_entry); + } + return found; +} + +NamedProcessIterator::NamedProcessIterator(const std::wstring& executable_name, + const ProcessFilter* filter) + : ProcessIterator(filter), + executable_name_(executable_name) { +} + +NamedProcessIterator::~NamedProcessIterator() { +} + +} // namespace base diff --git a/base/process_util.h b/base/process_util.h index 5df4fbd..ec3510a 100644 --- a/base/process_util.h +++ b/base/process_util.h @@ -24,6 +24,7 @@ struct kinfo_proc; #include <sys/types.h> #endif +#include <list> #include <string> #include <utility> #include <vector> @@ -46,16 +47,25 @@ namespace base { #if defined(OS_WIN) struct ProcessEntry : public PROCESSENTRY32 { + ProcessId pid() const { return th32ProcessID; } + ProcessId parent_pid() const { return th32ParentProcessID; } + const wchar_t* exe_file() const { return szExeFile; } }; + struct IoCounters : public IO_COUNTERS { }; #elif defined(OS_POSIX) struct ProcessEntry { - base::ProcessId pid; - base::ProcessId ppid; - char szExeFile[NAME_MAX + 1]; + ProcessId pid_; + ProcessId ppid_; + ProcessId gid_; + std::string exe_file_; + + ProcessId pid() const { return pid_; } + ProcessId parent_pid() const { return ppid_; } + const char* exe_file() const { return exe_file_.c_str(); } }; struct IoCounters { @@ -126,7 +136,7 @@ bool AdjustOOMScore(ProcessId process, int score); // Close all file descriptors, expect those which are a destination in the // given multimap. Only call this function in a child process where you know // that there aren't any other threads. -void CloseSuperfluousFds(const base::InjectiveMultimap& saved_map); +void CloseSuperfluousFds(const InjectiveMultimap& saved_map); #endif #if defined(OS_WIN) @@ -239,7 +249,7 @@ class ProcessFilter { public: // Returns true to indicate set-inclusion and false otherwise. This method // should not have side-effects and should be idempotent. - virtual bool Includes(ProcessId pid, ProcessId parent_pid) const = 0; + virtual bool Includes(const ProcessEntry& entry) const = 0; }; // Returns the number of processes on the machine that are running from the @@ -312,15 +322,14 @@ bool CleanupProcesses(const std::wstring& executable_name, int exit_code, const ProcessFilter* filter); -// This class provides a way to iterate through the list of processes -// on the current machine that were started from the given executable -// name. To use, create an instance and then call NextProcessEntry() -// until it returns false. -class NamedProcessIterator { +// This class provides a way to iterate through a list of processes on the +// current machine with a specified filter. +// To use, create an instance and then call NextProcessEntry() until it returns +// false. +class ProcessIterator { public: - NamedProcessIterator(const std::wstring& executable_name, - const ProcessFilter* filter); - ~NamedProcessIterator(); + explicit ProcessIterator(const ProcessFilter* filter); + virtual ~ProcessIterator(); // If there's another process that matches the given executable name, // returns a const pointer to the corresponding PROCESSENTRY32. @@ -329,20 +338,23 @@ class NamedProcessIterator { // is called again or this NamedProcessIterator goes out of scope. const ProcessEntry* NextProcessEntry(); + // Takes a snapshot of all the ProcessEntry found. + std::list<ProcessEntry> Snapshot(); + + protected: + virtual bool IncludeEntry(); + const ProcessEntry& entry() { return entry_; } + private: // Determines whether there's another process (regardless of executable) // left in the list of all processes. Returns true and sets entry_ to // that process's info if there is one, false otherwise. bool CheckForNextProcess(); - bool IncludeEntry(); - // Initializes a PROCESSENTRY32 data structure so that it's ready for // use with Process32First/Process32Next. void InitProcessEntry(ProcessEntry* entry); - std::wstring executable_name_; - #if defined(OS_WIN) HANDLE snapshot_; bool started_iteration_; @@ -355,7 +367,26 @@ class NamedProcessIterator { ProcessEntry entry_; const ProcessFilter* filter_; - DISALLOW_EVIL_CONSTRUCTORS(NamedProcessIterator); + DISALLOW_COPY_AND_ASSIGN(ProcessIterator); +}; + +// This class provides a way to iterate through the list of processes +// on the current machine that were started from the given executable +// name. To use, create an instance and then call NextProcessEntry() +// until it returns false. +class NamedProcessIterator : public ProcessIterator { + public: + NamedProcessIterator(const std::wstring& executable_name, + const ProcessFilter* filter); + virtual ~NamedProcessIterator(); + + protected: + virtual bool IncludeEntry(); + + private: + std::wstring executable_name_; + + DISALLOW_COPY_AND_ASSIGN(NamedProcessIterator); }; // Working Set (resident) memory usage broken down by @@ -435,7 +466,7 @@ class ProcessMetrics { // only returns valid metrics if |process| is the current process. static ProcessMetrics* CreateProcessMetrics(ProcessHandle process, PortProvider* port_provider); -#endif +#endif // !defined(OS_MACOSX) ~ProcessMetrics(); @@ -487,7 +518,7 @@ class ProcessMetrics { explicit ProcessMetrics(ProcessHandle process); #else ProcessMetrics(ProcessHandle process, PortProvider* port_provider); -#endif +#endif // !defined(OS_MACOSX) ProcessHandle process_; @@ -506,9 +537,9 @@ class ProcessMetrics { #elif defined(OS_POSIX) // Jiffie count at the last_time_ we updated. int last_cpu_; -#endif +#endif // defined(OS_MACOSX) - DISALLOW_EVIL_CONSTRUCTORS(ProcessMetrics); + DISALLOW_COPY_AND_ASSIGN(ProcessMetrics); }; // Returns the memory commited by the system in KBytes. @@ -553,7 +584,7 @@ void RaiseProcessToHighPriority(); // in the child after forking will restore the standard exception handler. // See http://crbug.com/20371/ for more details. void RestoreDefaultExceptionHandler(); -#endif +#endif // defined(OS_MACOSX) } // namespace base diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc index 45e719c..61ad97e 100644 --- a/base/process_util_linux.cc +++ b/base/process_util_linux.cc @@ -19,6 +19,7 @@ #include "base/logging.h" #include "base/string_tokenizer.h" #include "base/string_util.h" +#include "base/sys_info.h" namespace { @@ -87,32 +88,19 @@ FilePath GetProcessExecutablePath(ProcessHandle process) { return FilePath(std::string(exename, len)); } -NamedProcessIterator::NamedProcessIterator(const std::wstring& executable_name, - const ProcessFilter* filter) - : executable_name_(executable_name), filter_(filter) { +ProcessIterator::ProcessIterator(const ProcessFilter* filter) + : filter_(filter) { procfs_dir_ = opendir("/proc"); } -NamedProcessIterator::~NamedProcessIterator() { +ProcessIterator::~ProcessIterator() { if (procfs_dir_) { closedir(procfs_dir_); procfs_dir_ = NULL; } } -const ProcessEntry* NamedProcessIterator::NextProcessEntry() { - bool result = false; - do { - result = CheckForNextProcess(); - } while (result && !IncludeEntry()); - - if (result) - return &entry_; - - return NULL; -} - -bool NamedProcessIterator::CheckForNextProcess() { +bool ProcessIterator::CheckForNextProcess() { // TODO(port): skip processes owned by different UID dirent* slot = 0; @@ -155,8 +143,8 @@ bool NamedProcessIterator::CheckForNextProcess() { return false; // Parse the status. It is formatted like this: - // %d (%s) %c %d ... - // pid (name) runstate ppid + // %d (%s) %c %d %d ... + // pid (name) runstate ppid gid // To avoid being fooled by names containing a closing paren, scan // backwards. openparen = strchr(buf, '('); @@ -179,27 +167,37 @@ bool NamedProcessIterator::CheckForNextProcess() { return false; } - entry_.pid = atoi(slot->d_name); - entry_.ppid = atoi(closeparen + 3); + // This seems fragile. + entry_.pid_ = atoi(slot->d_name); + entry_.ppid_ = atoi(closeparen + 3); + entry_.gid_ = atoi(strchr(closeparen + 4, ' ')); // TODO(port): read pid's commandline's $0, like killall does. Using the // short name between openparen and closeparen won't work for long names! int len = closeparen - openparen - 1; - if (len > NAME_MAX) - len = NAME_MAX; - memcpy(entry_.szExeFile, openparen + 1, len); - entry_.szExeFile[len] = 0; - + entry_.exe_file_.assign(openparen + 1, len); return true; } bool NamedProcessIterator::IncludeEntry() { // TODO(port): make this also work for non-ASCII filenames - if (WideToASCII(executable_name_) != entry_.szExeFile) + if (WideToASCII(executable_name_) != entry().exe_file()) return false; - if (!filter_) - return true; - return filter_->Includes(entry_.pid, entry_.ppid); + return ProcessIterator::IncludeEntry(); +} + + +ProcessMetrics::ProcessMetrics(ProcessHandle process) + : process_(process), + last_time_(0), + last_system_time_(0), + last_cpu_(0) { + processor_count_ = base::SysInfo::NumberOfProcessors(); +} + +// static +ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) { + return new ProcessMetrics(process); } // On linux, we return vsize. diff --git a/base/process_util_mac.mm b/base/process_util_mac.mm index 4cf597c..f119e78 100644 --- a/base/process_util_mac.mm +++ b/base/process_util_mac.mm @@ -48,10 +48,8 @@ void RestoreDefaultExceptionHandler() { EXCEPTION_DEFAULT, THREAD_STATE_NONE); } -NamedProcessIterator::NamedProcessIterator(const std::wstring& executable_name, - const ProcessFilter* filter) - : executable_name_(executable_name), - index_of_kinfo_proc_(0), +ProcessIterator::ProcessIterator(const ProcessFilter* filter) + : index_of_kinfo_proc_(0), filter_(filter) { // Get a snapshot of all of my processes (yes, as we loop it can go stale, but // but trying to find where we were in a constantly changing list is basically @@ -75,7 +73,7 @@ NamedProcessIterator::NamedProcessIterator(const std::wstring& executable_name, size_t num_of_kinfo_proc = len / sizeof(struct kinfo_proc); // Leave some spare room for process table growth (more could show up // between when we check and now) - num_of_kinfo_proc += 4; + num_of_kinfo_proc += 16; kinfo_procs_.resize(num_of_kinfo_proc); len = num_of_kinfo_proc * sizeof(struct kinfo_proc); // Load the list of processes @@ -102,38 +100,21 @@ NamedProcessIterator::NamedProcessIterator(const std::wstring& executable_name, } } -NamedProcessIterator::~NamedProcessIterator() { +ProcessIterator::~ProcessIterator() { } -const ProcessEntry* NamedProcessIterator::NextProcessEntry() { - bool result = false; - do { - result = CheckForNextProcess(); - } while (result && !IncludeEntry()); - - if (result) { - return &entry_; - } - - return NULL; -} - -bool NamedProcessIterator::CheckForNextProcess() { - std::string executable_name_utf8(base::SysWideToUTF8(executable_name_)); - +bool ProcessIterator::CheckForNextProcess() { std::string data; - std::string exec_name; - for (; index_of_kinfo_proc_ < kinfo_procs_.size(); ++index_of_kinfo_proc_) { - kinfo_proc* kinfo = &kinfo_procs_[index_of_kinfo_proc_]; + kinfo_proc& kinfo = kinfo_procs_[index_of_kinfo_proc_]; // Skip processes just awaiting collection - if ((kinfo->kp_proc.p_pid > 0) && (kinfo->kp_proc.p_stat == SZOMB)) + if ((kinfo.kp_proc.p_pid > 0) && (kinfo.kp_proc.p_stat == SZOMB)) continue; - int mib[] = { CTL_KERN, KERN_PROCARGS, kinfo->kp_proc.p_pid }; + int mib[] = { CTL_KERN, KERN_PROCARGS, kinfo.kp_proc.p_pid }; - // Found out what size buffer we need + // Find out what size buffer we need. size_t data_len = 0; if (sysctl(mib, arraysize(mib), NULL, &data_len, NULL, 0) < 0) { LOG(ERROR) << "failed to figure out the buffer size for a commandline"; @@ -154,32 +135,26 @@ bool NamedProcessIterator::CheckForNextProcess() { LOG(ERROR) << "command line data didn't match expected format"; continue; } + entry_.pid_ = kinfo.kp_proc.p_pid; + entry_.ppid_ = kinfo.kp_eproc.e_ppid; + entry_.gid_ = kinfo.kp_eproc.e_pgid; size_t last_slash = data.rfind('/', exec_name_end); if (last_slash == std::string::npos) - exec_name = data.substr(0, exec_name_end); + entry_.exe_file_.assign(data, 0, exec_name_end); else - exec_name = data.substr(last_slash + 1, exec_name_end - last_slash - 1); - - // Check the name - if (executable_name_utf8 == exec_name) { - entry_.pid = kinfo->kp_proc.p_pid; - entry_.ppid = kinfo->kp_eproc.e_ppid; - base::strlcpy(entry_.szExeFile, exec_name.c_str(), - sizeof(entry_.szExeFile)); - // Start w/ the next entry next time through - ++index_of_kinfo_proc_; - // Done - return true; - } + entry_.exe_file_.assign(data, last_slash + 1, + exec_name_end - last_slash - 1); + // Start w/ the next entry next time through + ++index_of_kinfo_proc_; + // Done + return true; } return false; } bool NamedProcessIterator::IncludeEntry() { - // Don't need to check the name, we did that w/in CheckForNextProcess. - if (!filter_) - return true; - return filter_->Includes(entry_.pid, entry_.ppid); + return (base::SysWideToUTF8(executable_name_) == entry().exe_file() && + ProcessIterator::IncludeEntry()); } @@ -192,6 +167,23 @@ bool NamedProcessIterator::IncludeEntry() { // call). Child processes ipc their port, so return something if available, // otherwise return 0. // + +ProcessMetrics::ProcessMetrics(ProcessHandle process, + ProcessMetrics::PortProvider* port_provider) + : process_(process), + last_time_(0), + last_system_time_(0), + port_provider_(port_provider) { + processor_count_ = base::SysInfo::NumberOfProcessors(); +} + +// static +ProcessMetrics* ProcessMetrics::CreateProcessMetrics( + ProcessHandle process, + ProcessMetrics::PortProvider* port_provider) { + return new ProcessMetrics(process, port_provider); +} + bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const { return false; } diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc index 0deb2f2..17a461d 100644 --- a/base/process_util_posix.cc +++ b/base/process_util_posix.cc @@ -25,7 +25,6 @@ #include "base/process_util.h" #include "base/rand_util.h" #include "base/scoped_ptr.h" -#include "base/sys_info.h" #include "base/time.h" #include "base/waitable_event.h" @@ -577,37 +576,6 @@ bool LaunchApp(const CommandLine& cl, return LaunchApp(cl.argv(), no_files, wait, process_handle); } -#if !defined(OS_MACOSX) -ProcessMetrics::ProcessMetrics(ProcessHandle process) -#else -ProcessMetrics::ProcessMetrics(ProcessHandle process, - ProcessMetrics::PortProvider* port_provider) -#endif - : process_(process), - last_time_(0), - last_system_time_(0) -#if defined(OS_MACOSX) - , port_provider_(port_provider) -#elif defined(OS_POSIX) - , last_cpu_(0) -#endif -{ - processor_count_ = base::SysInfo::NumberOfProcessors(); -} - -// static -#if !defined(OS_MACOSX) -ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) { - return new ProcessMetrics(process); -} -#else -ProcessMetrics* ProcessMetrics::CreateProcessMetrics( - ProcessHandle process, - ProcessMetrics::PortProvider* port_provider) { - return new ProcessMetrics(process, port_provider); -} -#endif - ProcessMetrics::~ProcessMetrics() { } void EnableTerminationOnHeapCorruption() { @@ -877,28 +845,6 @@ bool GetAppOutputRestricted(const CommandLine& cl, return GetAppOutputInternal(cl, &empty_environ, output, max_output, false); } -int GetProcessCount(const std::wstring& executable_name, - const ProcessFilter* filter) { - int count = 0; - - NamedProcessIterator iter(executable_name, filter); - while (iter.NextProcessEntry()) - ++count; - return count; -} - -bool KillProcesses(const std::wstring& executable_name, int exit_code, - const ProcessFilter* filter) { - bool result = true; - const ProcessEntry* entry; - - NamedProcessIterator iter(executable_name, filter); - while ((entry = iter.NextProcessEntry()) != NULL) - result = KillProcess((*entry).pid, exit_code, true) && result; - - return result; -} - bool WaitForProcessesToExit(const std::wstring& executable_name, int64 wait_milliseconds, const ProcessFilter* filter) { diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc index b4d9b9f..9c4aa5d 100644 --- a/base/process_util_unittest.cc +++ b/base/process_util_unittest.cc @@ -13,6 +13,7 @@ #include "base/path_service.h" #include "base/platform_thread.h" #include "base/process_util.h" +#include "base/scoped_ptr.h" #include "testing/gtest/include/gtest/gtest.h" #if defined(OS_LINUX) @@ -33,7 +34,15 @@ #include "base/process_util_unittest_mac.h" #endif -namespace base { +namespace { + +#if defined(OS_WIN) +const wchar_t* const kProcessName = L"base_unittests.exe"; +#else +const wchar_t* const kProcessName = L"base_unittests"; +#endif // defined(OS_WIN) + +} // namespace class ProcessUtilTest : public MultiProcessTest { #if defined(OS_POSIX) @@ -48,10 +57,10 @@ MULTIPROCESS_TEST_MAIN(SimpleChildProcess) { } TEST_F(ProcessUtilTest, SpawnChild) { - ProcessHandle handle = this->SpawnChild(L"SimpleChildProcess"); + base::ProcessHandle handle = this->SpawnChild(L"SimpleChildProcess"); ASSERT_NE(base::kNullProcessHandle, handle); - EXPECT_TRUE(WaitForSingleProcess(handle, 5000)); + EXPECT_TRUE(base::WaitForSingleProcess(handle, 5000)); base::CloseProcessHandle(handle); } @@ -70,7 +79,7 @@ MULTIPROCESS_TEST_MAIN(SlowChildProcess) { TEST_F(ProcessUtilTest, KillSlowChild) { remove("SlowChildProcess.die"); - ProcessHandle handle = this->SpawnChild(L"SlowChildProcess"); + base::ProcessHandle handle = this->SpawnChild(L"SlowChildProcess"); ASSERT_NE(base::kNullProcessHandle, handle); FILE *fp = fopen("SlowChildProcess.die", "w"); fclose(fp); @@ -80,7 +89,7 @@ TEST_F(ProcessUtilTest, KillSlowChild) { TEST_F(ProcessUtilTest, DidProcessCrash) { remove("SlowChildProcess.die"); - ProcessHandle handle = this->SpawnChild(L"SlowChildProcess"); + base::ProcessHandle handle = this->SpawnChild(L"SlowChildProcess"); ASSERT_NE(base::kNullProcessHandle, handle); bool child_exited = true; @@ -92,7 +101,6 @@ TEST_F(ProcessUtilTest, DidProcessCrash) { EXPECT_TRUE(base::WaitForSingleProcess(handle, 5000)); EXPECT_FALSE(base::DidProcessCrash(&child_exited, handle)); - base::CloseProcessHandle(handle); } @@ -101,8 +109,8 @@ TEST_F(ProcessUtilTest, DidProcessCrash) { // Note: a platform may not be willing or able to lower the priority of // a process. The calls to SetProcessBackground should be noops then. TEST_F(ProcessUtilTest, SetProcessBackgrounded) { - ProcessHandle handle = this->SpawnChild(L"SimpleChildProcess"); - Process process(handle); + base::ProcessHandle handle = this->SpawnChild(L"SimpleChildProcess"); + base::Process process(handle); int old_priority = process.GetPriority(); process.SetProcessBackgrounded(true); process.SetProcessBackgrounded(false); @@ -113,7 +121,7 @@ TEST_F(ProcessUtilTest, SetProcessBackgrounded) { // TODO(estade): if possible, port these 2 tests. #if defined(OS_WIN) TEST_F(ProcessUtilTest, EnableLFH) { - ASSERT_TRUE(EnableLowFragmentationHeap()); + ASSERT_TRUE(base::EnableLowFragmentationHeap()); if (IsDebuggerPresent()) { // Under these conditions, LFH can't be enabled. There's no point to test // anything. @@ -144,13 +152,13 @@ TEST_F(ProcessUtilTest, EnableLFH) { } TEST_F(ProcessUtilTest, CalcFreeMemory) { - ProcessMetrics* metrics = - ProcessMetrics::CreateProcessMetrics(::GetCurrentProcess()); - ASSERT_TRUE(NULL != metrics); + scoped_ptr<base::ProcessMetrics> metrics( + base::ProcessMetrics::CreateProcessMetrics(::GetCurrentProcess())); + ASSERT_TRUE(NULL != metrics.get()); // Typical values here is ~1900 for total and ~1000 for largest. Obviously // it depends in what other tests have done to this process. - FreeMBytes free_mem1 = {0}; + base::FreeMBytes free_mem1 = {0}; EXPECT_TRUE(metrics->CalculateFreeMemory(&free_mem1)); EXPECT_LT(10u, free_mem1.total); EXPECT_LT(10u, free_mem1.largest); @@ -161,21 +169,16 @@ TEST_F(ProcessUtilTest, CalcFreeMemory) { // Allocate 20M and check again. It should have gone down. const int kAllocMB = 20; - char* alloc = new char[kAllocMB * 1024 * 1024]; - EXPECT_TRUE(NULL != alloc); - + scoped_array<char> alloc(new char[kAllocMB * 1024 * 1024]); size_t expected_total = free_mem1.total - kAllocMB; size_t expected_largest = free_mem1.largest; - FreeMBytes free_mem2 = {0}; + base::FreeMBytes free_mem2 = {0}; EXPECT_TRUE(metrics->CalculateFreeMemory(&free_mem2)); EXPECT_GE(free_mem2.total, free_mem2.largest); EXPECT_GE(expected_total, free_mem2.total); EXPECT_GE(expected_largest, free_mem2.largest); EXPECT_TRUE(NULL != free_mem2.largest_ptr); - - delete[] alloc; - delete metrics; } TEST_F(ProcessUtilTest, GetAppOutput) { @@ -221,6 +224,9 @@ TEST_F(ProcessUtilTest, LaunchAsUser) { #endif // defined(OS_WIN) #if defined(OS_POSIX) + +namespace { + // Returns the maximum number of files that a process can have open. // Returns 0 on error. int GetMaxFilesOpenInProcess() { @@ -240,6 +246,9 @@ int GetMaxFilesOpenInProcess() { } const int kChildPipe = 20; // FD # for write end of pipe in child process. + +} // namespace + MULTIPROCESS_TEST_MAIN(ProcessUtilsLeakFDChildProcess) { // This child process counts the number of open FDs, it then writes that // number out to a pipe connected to the parent. @@ -270,11 +279,10 @@ int ProcessUtilTest::CountOpenFDsInChild() { if (pipe(fds) < 0) NOTREACHED(); - file_handle_mapping_vector fd_mapping_vec; + base::file_handle_mapping_vector fd_mapping_vec; fd_mapping_vec.push_back(std::pair<int, int>(fds[1], kChildPipe)); - ProcessHandle handle = this->SpawnChild(L"ProcessUtilsLeakFDChildProcess", - fd_mapping_vec, - false); + base::ProcessHandle handle = this->SpawnChild( + L"ProcessUtilsLeakFDChildProcess", fd_mapping_vec, false); CHECK(handle); int ret = HANDLE_EINTR(close(fds[1])); DPCHECK(ret == 0); @@ -285,7 +293,7 @@ int ProcessUtilTest::CountOpenFDsInChild() { HANDLE_EINTR(read(fds[0], &num_open_files, sizeof(num_open_files))); CHECK_EQ(bytes_read, static_cast<ssize_t>(sizeof(num_open_files))); - CHECK(WaitForSingleProcess(handle, 1000)); + CHECK(base::WaitForSingleProcess(handle, 1000)); base::CloseProcessHandle(handle); ret = HANDLE_EINTR(close(fds[0])); DPCHECK(ret == 0); @@ -296,7 +304,7 @@ int ProcessUtilTest::CountOpenFDsInChild() { TEST_F(ProcessUtilTest, FDRemapping) { int fds_before = CountOpenFDsInChild(); - // open some dummy fds to make sure they don't propogate over to the + // open some dummy fds to make sure they don't propagate over to the // child process. int dev_null = open("/dev/null", O_RDONLY); int sockets[2]; @@ -315,10 +323,12 @@ TEST_F(ProcessUtilTest, FDRemapping) { DPCHECK(ret == 0); } -static std::string TestLaunchApp(const base::environment_vector& env_changes) { +namespace { + +std::string TestLaunchApp(const base::environment_vector& env_changes) { std::vector<std::string> args; base::file_handle_mapping_vector fds_to_remap; - ProcessHandle handle; + base::ProcessHandle handle; args.push_back("bash"); args.push_back("-c"); @@ -328,7 +338,7 @@ static std::string TestLaunchApp(const base::environment_vector& env_changes) { PCHECK(pipe(fds) == 0); fds_to_remap.push_back(std::make_pair(fds[1], 1)); - EXPECT_TRUE(LaunchApp(args, env_changes, fds_to_remap, + EXPECT_TRUE(base::LaunchApp(args, env_changes, fds_to_remap, true /* wait for exit */, &handle)); PCHECK(close(fds[1]) == 0); @@ -338,7 +348,7 @@ static std::string TestLaunchApp(const base::environment_vector& env_changes) { return std::string(buf, n); } -static const char kLargeString[] = +const char kLargeString[] = "0123456789012345678901234567890123456789012345678901234567890123456789" "0123456789012345678901234567890123456789012345678901234567890123456789" "0123456789012345678901234567890123456789012345678901234567890123456789" @@ -347,6 +357,8 @@ static const char kLargeString[] = "0123456789012345678901234567890123456789012345678901234567890123456789" "0123456789012345678901234567890123456789012345678901234567890123456789"; +} // namespace + TEST_F(ProcessUtilTest, LaunchApp) { base::environment_vector env_changes; @@ -375,59 +387,59 @@ TEST_F(ProcessUtilTest, LaunchApp) { } TEST_F(ProcessUtilTest, AlterEnvironment) { - static const char* empty[] = { NULL }; - static const char* a2[] = { "A=2", NULL }; + const char* const empty[] = { NULL }; + const char* const a2[] = { "A=2", NULL }; base::environment_vector changes; char** e; - e = AlterEnvironment(changes, empty); + e = base::AlterEnvironment(changes, empty); EXPECT_TRUE(e[0] == NULL); delete[] e; changes.push_back(std::make_pair(std::string("A"), std::string("1"))); - e = AlterEnvironment(changes, empty); + e = base::AlterEnvironment(changes, empty); EXPECT_EQ(std::string("A=1"), e[0]); EXPECT_TRUE(e[1] == NULL); delete[] e; changes.clear(); changes.push_back(std::make_pair(std::string("A"), std::string(""))); - e = AlterEnvironment(changes, empty); + e = base::AlterEnvironment(changes, empty); EXPECT_TRUE(e[0] == NULL); delete[] e; changes.clear(); - e = AlterEnvironment(changes, a2); + e = base::AlterEnvironment(changes, a2); EXPECT_EQ(std::string("A=2"), e[0]); EXPECT_TRUE(e[1] == NULL); delete[] e; changes.clear(); changes.push_back(std::make_pair(std::string("A"), std::string("1"))); - e = AlterEnvironment(changes, a2); + e = base::AlterEnvironment(changes, a2); EXPECT_EQ(std::string("A=1"), e[0]); EXPECT_TRUE(e[1] == NULL); delete[] e; changes.clear(); changes.push_back(std::make_pair(std::string("A"), std::string(""))); - e = AlterEnvironment(changes, a2); + e = base::AlterEnvironment(changes, a2); EXPECT_TRUE(e[0] == NULL); delete[] e; } TEST_F(ProcessUtilTest, GetAppOutput) { std::string output; - EXPECT_TRUE(GetAppOutput(CommandLine(FilePath("true")), &output)); + EXPECT_TRUE(base::GetAppOutput(CommandLine(FilePath("true")), &output)); EXPECT_STREQ("", output.c_str()); - EXPECT_FALSE(GetAppOutput(CommandLine(FilePath("false")), &output)); + EXPECT_FALSE(base::GetAppOutput(CommandLine(FilePath("false")), &output)); std::vector<std::string> argv; argv.push_back("/bin/echo"); argv.push_back("-n"); argv.push_back("foobar42"); - EXPECT_TRUE(GetAppOutput(CommandLine(argv), &output)); + EXPECT_TRUE(base::GetAppOutput(CommandLine(argv), &output)); EXPECT_STREQ("foobar42", output.c_str()); } @@ -444,35 +456,35 @@ TEST_F(ProcessUtilTest, GetAppOutputRestricted) { // need absolute paths). argv.push_back("exit 0"); // argv[2]; equivalent to "true" std::string output = "abc"; - EXPECT_TRUE(GetAppOutputRestricted(CommandLine(argv), &output, 100)); + EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 100)); EXPECT_STREQ("", output.c_str()); // On failure, should not touch |output|. As above, but for |false|. argv[2] = "exit 1"; // equivalent to "false" output = "abc"; - EXPECT_FALSE(GetAppOutputRestricted(CommandLine(argv), + EXPECT_FALSE(base::GetAppOutputRestricted(CommandLine(argv), &output, 100)); EXPECT_STREQ("abc", output.c_str()); // Amount of output exactly equal to space allowed. argv[2] = "echo 123456789"; // (the sh built-in doesn't take "-n") output.clear(); - EXPECT_TRUE(GetAppOutputRestricted(CommandLine(argv), &output, 10)); + EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 10)); EXPECT_STREQ("123456789\n", output.c_str()); // Amount of output greater than space allowed. output.clear(); - EXPECT_TRUE(GetAppOutputRestricted(CommandLine(argv), &output, 5)); + EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 5)); EXPECT_STREQ("12345", output.c_str()); // Amount of output less than space allowed. output.clear(); - EXPECT_TRUE(GetAppOutputRestricted(CommandLine(argv), &output, 15)); + EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 15)); EXPECT_STREQ("123456789\n", output.c_str()); // Zero space allowed. output = "abc"; - EXPECT_TRUE(GetAppOutputRestricted(CommandLine(argv), &output, 0)); + EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 0)); EXPECT_STREQ("", output.c_str()); } @@ -486,21 +498,21 @@ TEST_F(ProcessUtilTest, GetAppOutputRestrictedNoZombies) { // 10.5) times with an output buffer big enough to capture all output. for (int i = 0; i < 300; i++) { std::string output; - EXPECT_TRUE(GetAppOutputRestricted(CommandLine(argv), &output, 100)); + EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 100)); EXPECT_STREQ("123456789012345678901234567890\n", output.c_str()); } // Ditto, but with an output buffer too small to capture all output. for (int i = 0; i < 300; i++) { std::string output; - EXPECT_TRUE(GetAppOutputRestricted(CommandLine(argv), &output, 10)); + EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 10)); EXPECT_STREQ("1234567890", output.c_str()); } } #if defined(OS_LINUX) TEST_F(ProcessUtilTest, GetParentProcessId) { - base::ProcessId ppid = GetParentProcessId(GetCurrentProcId()); + base::ProcessId ppid = base::GetParentProcessId(base::GetCurrentProcId()); EXPECT_EQ(ppid, getppid()); } @@ -512,7 +524,7 @@ TEST_F(ProcessUtilTest, ParseProcStatCPU) { "20 0 1 0 121946157 15077376 314 18446744073709551615 4194304 " "4246868 140733983044336 18446744073709551615 140244213071219 " "0 0 0 138047495 0 0 0 17 1 0 0 0 0 0"; - EXPECT_EQ(12 + 16, ParseProcStatCPU(kTopStat)); + EXPECT_EQ(12 + 16, base::ParseProcStatCPU(kTopStat)); // cat /proc/self/stat on a random other machine I have. const char kSelfStat[] = "5364 (cat) R 5354 5364 5354 34819 5364 " @@ -521,7 +533,7 @@ TEST_F(ProcessUtilTest, ParseProcStatCPU) { "16 0 1 0 1676099790 2957312 114 4294967295 134512640 134528148 " "3221224832 3221224344 3086339742 0 0 0 0 0 0 0 17 0 0 0"; - EXPECT_EQ(0, ParseProcStatCPU(kSelfStat)); + EXPECT_EQ(0, base::ParseProcStatCPU(kSelfStat)); } #endif @@ -549,7 +561,7 @@ class OutOfMemoryTest : public testing::Test { virtual void SetUp() { // Must call EnableTerminationOnOutOfMemory() because that is called from // chrome's main function and therefore hasn't been called yet. - EnableTerminationOnOutOfMemory(); + base::EnableTerminationOnOutOfMemory(); #if defined(USE_TCMALLOC) tc_set_new_mode(1); } @@ -622,26 +634,24 @@ TEST_F(OutOfMemoryTest, Posix_memalign) { TEST_F(OutOfMemoryTest, CFAllocatorSystemDefault) { ASSERT_DEATH(while ((value_ = - AllocateViaCFAllocatorSystemDefault(signed_test_size_))) {}, ""); + base::AllocateViaCFAllocatorSystemDefault(signed_test_size_))) {}, ""); } TEST_F(OutOfMemoryTest, CFAllocatorMalloc) { ASSERT_DEATH(while ((value_ = - AllocateViaCFAllocatorMalloc(signed_test_size_))) {}, ""); + base::AllocateViaCFAllocatorMalloc(signed_test_size_))) {}, ""); } TEST_F(OutOfMemoryTest, CFAllocatorMallocZone) { ASSERT_DEATH(while ((value_ = - AllocateViaCFAllocatorMallocZone(signed_test_size_))) {}, ""); + base::AllocateViaCFAllocatorMallocZone(signed_test_size_))) {}, ""); } TEST_F(OutOfMemoryTest, PsychoticallyBigObjCObject) { ASSERT_DEATH(while ((value_ = - AllocatePsychoticallyBigObjCObject())) {}, ""); + base::AllocatePsychoticallyBigObjCObject())) {}, ""); } #endif // OS_MACOSX #endif // !defined(OS_WIN) - -} // namespace base diff --git a/base/process_util_win.cc b/base/process_util_win.cc index 3299f60..8df8de5 100644 --- a/base/process_util_win.cc +++ b/base/process_util_win.cc @@ -222,9 +222,11 @@ bool KillProcessById(ProcessId process_id, int exit_code, bool wait) { HANDLE process = OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE, FALSE, // Don't inherit handle process_id); - if (!process) + if (!process) { + DLOG(ERROR) << "Unable to open process " << process_id << " : " + << GetLastError(); return false; - + } bool ret = KillProcess(process, exit_code, wait); CloseHandle(process); return ret; @@ -384,33 +386,17 @@ bool WaitForExitCodeWithTimeout(ProcessHandle handle, int* exit_code, return true; } -NamedProcessIterator::NamedProcessIterator(const std::wstring& executable_name, - const ProcessFilter* filter) +ProcessIterator::ProcessIterator(const ProcessFilter* filter) : started_iteration_(false), - executable_name_(executable_name), filter_(filter) { snapshot_ = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); } -NamedProcessIterator::~NamedProcessIterator() { +ProcessIterator::~ProcessIterator() { CloseHandle(snapshot_); } - -const ProcessEntry* NamedProcessIterator::NextProcessEntry() { - bool result = false; - do { - result = CheckForNextProcess(); - } while (result && !IncludeEntry()); - - if (result) { - return &entry_; - } - - return NULL; -} - -bool NamedProcessIterator::CheckForNextProcess() { +bool ProcessIterator::CheckForNextProcess() { InitProcessEntry(&entry_); if (!started_iteration_) { @@ -421,39 +407,15 @@ bool NamedProcessIterator::CheckForNextProcess() { return !!Process32Next(snapshot_, &entry_); } -bool NamedProcessIterator::IncludeEntry() { - return _wcsicmp(executable_name_.c_str(), entry_.szExeFile) == 0 && - (!filter_ || filter_->Includes(entry_.th32ProcessID, - entry_.th32ParentProcessID)); -} - -void NamedProcessIterator::InitProcessEntry(ProcessEntry* entry) { +void ProcessIterator::InitProcessEntry(ProcessEntry* entry) { memset(entry, 0, sizeof(*entry)); entry->dwSize = sizeof(*entry); } -int GetProcessCount(const std::wstring& executable_name, - const ProcessFilter* filter) { - int count = 0; - - NamedProcessIterator iter(executable_name, filter); - while (iter.NextProcessEntry()) - ++count; - return count; -} - -bool KillProcesses(const std::wstring& executable_name, int exit_code, - const ProcessFilter* filter) { - bool result = true; - const ProcessEntry* entry; - - NamedProcessIterator iter(executable_name, filter); - while (entry = iter.NextProcessEntry()) { - if (!KillProcessById((*entry).th32ProcessID, exit_code, true)) - result = false; - } - - return result; +bool NamedProcessIterator::IncludeEntry() { + // Case insensitive. + return _wcsicmp(executable_name_.c_str(), entry().exe_file()) == 0 && + ProcessIterator::IncludeEntry(); } bool WaitForProcessesToExit(const std::wstring& executable_name, @@ -722,7 +684,7 @@ double ProcessMetrics::GetCPUUsage() { return cpu; } -bool ProcessMetrics::GetIOCounters(base::IoCounters* io_counters) const { +bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const { return GetProcessIoCounters(process_, io_counters) != FALSE; } diff --git a/base/shared_memory.h b/base/shared_memory.h index 48ba857..e2077ae 100644 --- a/base/shared_memory.h +++ b/base/shared_memory.h @@ -40,7 +40,6 @@ typedef ino_t SharedMemoryId; // around the OS primitive for a memory mapped file. class SharedMemory { public: - // Create a new SharedMemory object. SharedMemory(); // Create a new SharedMemory object from an existing, open @@ -51,19 +50,19 @@ class SharedMemory { // shared memory file that was created by a remote process and not shared // to the current process. SharedMemory(SharedMemoryHandle handle, bool read_only, - base::ProcessHandle process); + ProcessHandle process); - // Destructor. Will close any open files. + // Closes any open files. ~SharedMemory(); // Return true iff the given handle is valid (i.e. not the distingished // invalid value; NULL for a HANDLE and -1 for a file descriptor) static bool IsHandleValid(const SharedMemoryHandle& handle); - // Return invalid handle (see comment above for exact definition). + // Returns invalid handle (see comment above for exact definition). static SharedMemoryHandle NULLHandle(); - // Close a shared memory handle. + // Closes a shared memory handle. static void CloseHandle(const SharedMemoryHandle& handle); // Creates or opens a shared memory segment based on a name. @@ -106,13 +105,13 @@ class SharedMemory { // Mapped via Map(). Returns NULL if it is not mapped. void *memory() const { return memory_; } - // Get access to the underlying OS handle for this segment. + // Returns the underlying OS handle for this segment. // Use of this handle for anything other than an opaque // identifier is not portable. SharedMemoryHandle handle() const; #if defined(OS_POSIX) - // Return a unique identifier for this shared memory segment. Inode numbers + // Returns a unique identifier for this shared memory segment. Inode numbers // are technically only unique to a single filesystem. However, we always // allocate shared memory backing files from the same directory, so will end // up on the same filesystem. @@ -123,13 +122,13 @@ class SharedMemory { // It is safe to call Close repeatedly. void Close(); - // Share the shared memory to another process. Attempts + // Shares the shared memory to another process. Attempts // to create a platform-specific new_handle which can be // used in a remote process to access the shared memory // file. new_handle is an ouput parameter to receive // the handle for use in the remote process. // Returns true on success, false otherwise. - bool ShareToProcess(base::ProcessHandle process, + bool ShareToProcess(ProcessHandle process, SharedMemoryHandle* new_handle) { return ShareToProcessCommon(process, new_handle, false); } @@ -145,7 +144,7 @@ class SharedMemory { return ShareToProcessCommon(process, new_handle, true); } - // Lock the shared memory. + // Locks the shared memory. // This is a cross-process lock which may be recursively // locked by the same thread. // TODO(port): @@ -156,7 +155,7 @@ class SharedMemory { // across Mac and Linux. void Lock(); - // Release the shared memory lock. + // Releases the shared memory lock. void Unlock(); private: diff --git a/chrome/browser/memory_details_mac.cc b/chrome/browser/memory_details_mac.cc index dd1116b5..bf58193 100644 --- a/chrome/browser/memory_details_mac.cc +++ b/chrome/browser/memory_details_mac.cc @@ -106,8 +106,8 @@ void MemoryDetails::CollectProcessData( NULL); while (const base::ProcessEntry* entry = process_it.NextProcessEntry()) { - pids_by_browser[index].push_back(entry->pid); - all_pids.push_back(entry->pid); + pids_by_browser[index].push_back(entry->pid()); + all_pids.push_back(entry->pid()); } } @@ -117,8 +117,8 @@ void MemoryDetails::CollectProcessData( base::NamedProcessIterator helper_it(chrome::kHelperProcessExecutableName, NULL); while (const base::ProcessEntry* entry = helper_it.NextProcessEntry()) { - helper_pids.push_back(entry->pid); - all_pids.push_back(entry->pid); + helper_pids.push_back(entry->pid()); + all_pids.push_back(entry->pid()); } } diff --git a/chrome/browser/memory_details_win.cc b/chrome/browser/memory_details_win.cc index 56ae424..84497ba 100644 --- a/chrome/browser/memory_details_win.cc +++ b/chrome/browser/memory_details_win.cc @@ -101,7 +101,7 @@ void MemoryDetails::CollectProcessData( } for (int index2 = 0; index2 < arraysize(g_process_template); index2++) { if (_wcsicmp(process_data_[index2].process_name.c_str(), - process_entry.szExeFile) != 0) + process_entry.szExeFile) != 0) continue; if (index2 == IE_BROWSER && is_64bit_process) continue; // Should use IE_64BIT_BROWSER diff --git a/chrome/browser/process_singleton_win_uitest.cc b/chrome/browser/process_singleton_win_uitest.cc index 929e271b2..bc783a6 100644 --- a/chrome/browser/process_singleton_win_uitest.cc +++ b/chrome/browser/process_singleton_win_uitest.cc @@ -139,10 +139,9 @@ class ProcessSingletonWinTest : public UITest { explicit ProcessTreeFilter(base::ProcessId parent_pid) { ancestor_pids_.insert(parent_pid); } - virtual bool Includes(base::ProcessId pid, - base::ProcessId parent_pid) const { - if (ancestor_pids_.find(parent_pid) != ancestor_pids_.end()) { - ancestor_pids_.insert(pid); + virtual bool Includes(const base::ProcessEntry & entry) const { + if (ancestor_pids_.find(entry.parent_pid()) != ancestor_pids_.end()) { + ancestor_pids_.insert(entry.pid()); return true; } else { return false; diff --git a/chrome/test/chrome_process_util.cc b/chrome/test/chrome_process_util.cc index 5f47df0..8e86e60 100644 --- a/chrome/test/chrome_process_util.cc +++ b/chrome/test/chrome_process_util.cc @@ -58,8 +58,8 @@ class ChildProcessFilter : public base::ProcessFilter { explicit ChildProcessFilter(std::vector<base::ProcessId> parent_pids) : parent_pids_(parent_pids.begin(), parent_pids.end()) {} - virtual bool Includes(base::ProcessId pid, base::ProcessId parent_pid) const { - return parent_pids_.find(parent_pid) != parent_pids_.end(); + virtual bool Includes(const base::ProcessEntry& entry) const { + return parent_pids_.find(entry.parent_pid()) != parent_pids_.end(); } private: @@ -76,11 +76,7 @@ ChromeProcessList GetRunningChromeProcesses(base::ProcessId browser_pid) { ChildProcessFilter filter(browser_pid); base::NamedProcessIterator it(chrome::kBrowserProcessExecutableName, &filter); while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) { -#if defined(OS_WIN) - result.push_back(process_entry->th32ProcessID); -#elif defined(OS_POSIX) - result.push_back(process_entry->pid); -#endif + result.push_back(process_entry->pid()); } #if defined(OS_LINUX) @@ -92,7 +88,7 @@ ChromeProcessList GetRunningChromeProcesses(base::ProcessId browser_pid) { base::NamedProcessIterator it(chrome::kBrowserProcessExecutableName, &filter); while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) - result.push_back(process_entry->pid); + result.push_back(process_entry->pid()); } #endif // defined(OS_LINUX) @@ -105,7 +101,7 @@ ChromeProcessList GetRunningChromeProcesses(base::ProcessId browser_pid) { base::NamedProcessIterator it(chrome::kHelperProcessExecutableName, &filter); while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) - result.push_back(process_entry->pid); + result.push_back(process_entry->pid()); } #endif // defined(OS_MACOSX) diff --git a/chrome_frame/test_utils.cc b/chrome_frame/test_utils.cc index 319aa54..e1377c7 100644 --- a/chrome_frame/test_utils.cc +++ b/chrome_frame/test_utils.cc @@ -244,10 +244,10 @@ class ArgumentFilter : public base::ProcessFilter { // Returns true to indicate set-inclusion and false otherwise. This method // should not have side-effects and should be idempotent. - virtual bool Includes(base::ProcessId pid, base::ProcessId parent_pid) const { + virtual bool Includes(const base::ProcessEntry& entry) const { bool found = false; std::wstring command_line; - if (GetCommandLineForProcess(pid, &command_line)) { + if (GetCommandLineForProcess(entry.pid(), &command_line)) { std::wstring::const_iterator it = std::search(command_line.begin(), command_line.end(), |