| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/test/base/chrome_process_util.h" | 5 #include "chrome/test/base/chrome_process_util.h" |
| 6 | 6 |
| 7 #include <set> |
| 7 #include <vector> | 8 #include <vector> |
| 8 #include <set> | |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
| 14 #include "chrome/test/base/test_switches.h" | 14 #include "chrome/test/base/test_switches.h" |
| 15 #include "content/common/result_codes.h" | 15 #include "content/common/result_codes.h" |
| 16 | 16 |
| 17 using base::TimeDelta; | 17 using base::TimeDelta; |
| 18 using base::TimeTicks; | 18 using base::TimeTicks; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 DISALLOW_COPY_AND_ASSIGN(ChildProcessFilter); | 52 DISALLOW_COPY_AND_ASSIGN(ChildProcessFilter); |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 const FilePath::CharType* GetRunningBrowserExecutableName() { | 55 const FilePath::CharType* GetRunningBrowserExecutableName() { |
| 56 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 56 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 57 if (cmd_line->HasSwitch(switches::kEnableChromiumBranding)) | 57 if (cmd_line->HasSwitch(switches::kEnableChromiumBranding)) |
| 58 return chrome::kBrowserProcessExecutableNameChromium; | 58 return chrome::kBrowserProcessExecutableNameChromium; |
| 59 return chrome::kBrowserProcessExecutableName; | 59 return chrome::kBrowserProcessExecutableName; |
| 60 } | 60 } |
| 61 | 61 |
| 62 const FilePath::CharType* GetRunningHelperExecutableName() { | 62 std::vector<FilePath::StringType> GetRunningHelperExecutableNames() { |
| 63 FilePath::StringType name; |
| 63 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 64 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 64 if (cmd_line->HasSwitch(switches::kEnableChromiumBranding)) | 65 if (cmd_line->HasSwitch(switches::kEnableChromiumBranding)) { |
| 65 return chrome::kHelperProcessExecutableNameChromium; | 66 name = chrome::kHelperProcessExecutableNameChromium; |
| 66 return chrome::kHelperProcessExecutableName; | 67 } else { |
| 68 name = chrome::kHelperProcessExecutableName; |
| 69 } |
| 70 |
| 71 std::vector<FilePath::StringType> names; |
| 72 names.push_back(name); |
| 73 |
| 74 #if defined(OS_MACOSX) |
| 75 // The helper might show up as these different flavors depending on the |
| 76 // executable flags required. |
| 77 std::string name_eh(name); |
| 78 name_eh.append(" EH"); |
| 79 names.push_back(name_eh); |
| 80 |
| 81 std::string name_np(name); |
| 82 name_np.append(" NP"); |
| 83 names.push_back(name_np); |
| 84 #endif |
| 85 |
| 86 return names; |
| 67 } | 87 } |
| 68 | 88 |
| 69 ChromeProcessList GetRunningChromeProcesses(base::ProcessId browser_pid) { | 89 ChromeProcessList GetRunningChromeProcesses(base::ProcessId browser_pid) { |
| 70 const FilePath::CharType* executable_name = GetRunningBrowserExecutableName(); | 90 const FilePath::CharType* executable_name = GetRunningBrowserExecutableName(); |
| 71 ChromeProcessList result; | 91 ChromeProcessList result; |
| 72 if (browser_pid == static_cast<base::ProcessId>(-1)) | 92 if (browser_pid == static_cast<base::ProcessId>(-1)) |
| 73 return result; | 93 return result; |
| 74 | 94 |
| 75 ChildProcessFilter filter(browser_pid); | 95 ChildProcessFilter filter(browser_pid); |
| 76 base::NamedProcessIterator it(executable_name, &filter); | 96 base::NamedProcessIterator it(executable_name, &filter); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 88 while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) | 108 while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) |
| 89 result.push_back(process_entry->pid()); | 109 result.push_back(process_entry->pid()); |
| 90 } | 110 } |
| 91 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) | 111 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
| 92 | 112 |
| 93 #if defined(OS_POSIX) | 113 #if defined(OS_POSIX) |
| 94 // On Mac OS X we run the subprocesses with a different bundle, and | 114 // On Mac OS X we run the subprocesses with a different bundle, and |
| 95 // on Linux via /proc/self/exe, so they end up with a different | 115 // on Linux via /proc/self/exe, so they end up with a different |
| 96 // name. We must collect them in a second pass. | 116 // name. We must collect them in a second pass. |
| 97 { | 117 { |
| 98 ChildProcessFilter filter(browser_pid); | 118 std::vector<FilePath::StringType> names = GetRunningHelperExecutableNames(); |
| 99 base::NamedProcessIterator it(GetRunningHelperExecutableName(), &filter); | 119 for (size_t i = 0; i < names.size(); ++i) { |
| 100 while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) | 120 FilePath::StringType name = names[i]; |
| 101 result.push_back(process_entry->pid()); | 121 ChildProcessFilter filter(browser_pid); |
| 122 base::NamedProcessIterator it(name, &filter); |
| 123 while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) |
| 124 result.push_back(process_entry->pid()); |
| 125 } |
| 102 } | 126 } |
| 103 #endif // defined(OS_MACOSX) | 127 #endif // defined(OS_POSIX) |
| 104 | 128 |
| 105 result.push_back(browser_pid); | 129 result.push_back(browser_pid); |
| 106 | 130 |
| 107 return result; | 131 return result; |
| 108 } | 132 } |
| 109 | 133 |
| 110 #if !defined(OS_MACOSX) | 134 #if !defined(OS_MACOSX) |
| 111 | 135 |
| 112 size_t ChromeTestProcessMetrics::GetPagefileUsage() { | 136 size_t ChromeTestProcessMetrics::GetPagefileUsage() { |
| 113 return process_metrics_->GetPagefileUsage(); | 137 return process_metrics_->GetPagefileUsage(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 125 base::ProcessHandle process) { | 149 base::ProcessHandle process) { |
| 126 #if !defined(OS_MACOSX) | 150 #if !defined(OS_MACOSX) |
| 127 process_metrics_.reset( | 151 process_metrics_.reset( |
| 128 base::ProcessMetrics::CreateProcessMetrics(process)); | 152 base::ProcessMetrics::CreateProcessMetrics(process)); |
| 129 #else | 153 #else |
| 130 process_metrics_.reset( | 154 process_metrics_.reset( |
| 131 base::ProcessMetrics::CreateProcessMetrics(process, NULL)); | 155 base::ProcessMetrics::CreateProcessMetrics(process, NULL)); |
| 132 #endif | 156 #endif |
| 133 process_handle_ = process; | 157 process_handle_ = process; |
| 134 } | 158 } |
| OLD | NEW |