OLD | NEW |
1 // Copyright (c) 2010 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/chrome_process_util.h" | 5 #include "chrome/test/chrome_process_util.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 #include <set> | 8 #include <set> |
9 | 9 |
| 10 #include "base/command_line.h" |
10 #include "base/process_util.h" | 11 #include "base/process_util.h" |
11 #include "base/time.h" | 12 #include "base/time.h" |
12 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
| 14 #include "chrome/test/test_switches.h" |
13 #include "content/common/result_codes.h" | 15 #include "content/common/result_codes.h" |
14 | 16 |
15 using base::TimeDelta; | 17 using base::TimeDelta; |
16 using base::TimeTicks; | 18 using base::TimeTicks; |
17 | 19 |
18 void TerminateAllChromeProcesses(base::ProcessId browser_pid) { | 20 void TerminateAllChromeProcesses(base::ProcessId browser_pid) { |
19 ChromeProcessList process_pids(GetRunningChromeProcesses(browser_pid)); | 21 ChromeProcessList process_pids(GetRunningChromeProcesses(browser_pid)); |
20 | 22 |
21 ChromeProcessList::const_iterator it; | 23 ChromeProcessList::const_iterator it; |
22 for (it = process_pids.begin(); it != process_pids.end(); ++it) { | 24 for (it = process_pids.begin(); it != process_pids.end(); ++it) { |
(...skipping 20 matching lines...) Expand all Loading... |
43 virtual bool Includes(const base::ProcessEntry& entry) const { | 45 virtual bool Includes(const base::ProcessEntry& entry) const { |
44 return parent_pids_.find(entry.parent_pid()) != parent_pids_.end(); | 46 return parent_pids_.find(entry.parent_pid()) != parent_pids_.end(); |
45 } | 47 } |
46 | 48 |
47 private: | 49 private: |
48 const std::set<base::ProcessId> parent_pids_; | 50 const std::set<base::ProcessId> parent_pids_; |
49 | 51 |
50 DISALLOW_COPY_AND_ASSIGN(ChildProcessFilter); | 52 DISALLOW_COPY_AND_ASSIGN(ChildProcessFilter); |
51 }; | 53 }; |
52 | 54 |
| 55 const FilePath::CharType* GetRunningExecutableName() { |
| 56 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 57 if (cmd_line->HasSwitch(switches::kEnableChromiumBranding)) |
| 58 return chrome::kBrowserProcessExecutableNameChromium; |
| 59 return chrome::kBrowserProcessExecutableName; |
| 60 } |
| 61 |
53 ChromeProcessList GetRunningChromeProcesses(base::ProcessId browser_pid) { | 62 ChromeProcessList GetRunningChromeProcesses(base::ProcessId browser_pid) { |
| 63 const FilePath::CharType* executable_name = GetRunningExecutableName(); |
54 ChromeProcessList result; | 64 ChromeProcessList result; |
55 if (browser_pid == static_cast<base::ProcessId>(-1)) | 65 if (browser_pid == static_cast<base::ProcessId>(-1)) |
56 return result; | 66 return result; |
57 | 67 |
58 ChildProcessFilter filter(browser_pid); | 68 ChildProcessFilter filter(browser_pid); |
59 base::NamedProcessIterator it(chrome::kBrowserProcessExecutableName, &filter); | 69 base::NamedProcessIterator it(executable_name, &filter); |
60 while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) { | 70 while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) { |
61 result.push_back(process_entry->pid()); | 71 result.push_back(process_entry->pid()); |
62 } | 72 } |
63 | 73 |
64 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 74 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
65 // On Unix we might be running with a zygote process for the renderers. | 75 // On Unix we might be running with a zygote process for the renderers. |
66 // Because of that we sweep the list of processes again and pick those which | 76 // Because of that we sweep the list of processes again and pick those which |
67 // are children of one of the processes that we've already seen. | 77 // are children of one of the processes that we've already seen. |
68 { | 78 { |
69 ChildProcessFilter filter(result); | 79 ChildProcessFilter filter(result); |
70 base::NamedProcessIterator it(chrome::kBrowserProcessExecutableName, | 80 base::NamedProcessIterator it(executable_name, &filter); |
71 &filter); | |
72 while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) | 81 while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) |
73 result.push_back(process_entry->pid()); | 82 result.push_back(process_entry->pid()); |
74 } | 83 } |
75 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) | 84 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
76 | 85 |
77 #if defined(OS_POSIX) | 86 #if defined(OS_POSIX) |
78 // On Mac OS X we run the subprocesses with a different bundle, and | 87 // On Mac OS X we run the subprocesses with a different bundle, and |
79 // on Linux via /proc/self/exe, so they end up with a different | 88 // on Linux via /proc/self/exe, so they end up with a different |
80 // name. We must collect them in a second pass. | 89 // name. We must collect them in a second pass. |
81 { | 90 { |
82 ChildProcessFilter filter(browser_pid); | 91 ChildProcessFilter filter(browser_pid); |
83 base::NamedProcessIterator it(chrome::kHelperProcessExecutableName, | 92 base::NamedProcessIterator it(executable_name, &filter); |
84 &filter); | |
85 while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) | 93 while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) |
86 result.push_back(process_entry->pid()); | 94 result.push_back(process_entry->pid()); |
87 } | 95 } |
88 #endif // defined(OS_MACOSX) | 96 #endif // defined(OS_MACOSX) |
89 | 97 |
90 result.push_back(browser_pid); | 98 result.push_back(browser_pid); |
91 | 99 |
92 return result; | 100 return result; |
93 } | 101 } |
94 | 102 |
(...skipping 15 matching lines...) Expand all Loading... |
110 base::ProcessHandle process) { | 118 base::ProcessHandle process) { |
111 #if !defined(OS_MACOSX) | 119 #if !defined(OS_MACOSX) |
112 process_metrics_.reset( | 120 process_metrics_.reset( |
113 base::ProcessMetrics::CreateProcessMetrics(process)); | 121 base::ProcessMetrics::CreateProcessMetrics(process)); |
114 #else | 122 #else |
115 process_metrics_.reset( | 123 process_metrics_.reset( |
116 base::ProcessMetrics::CreateProcessMetrics(process, NULL)); | 124 base::ProcessMetrics::CreateProcessMetrics(process, NULL)); |
117 #endif | 125 #endif |
118 process_handle_ = process; | 126 process_handle_ = process; |
119 } | 127 } |
OLD | NEW |