Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: chrome/test/chrome_process_util.cc

Issue 1689012: Move common code into process_util.cc (Closed)
Patch Set: More fixes Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/process_singleton_win_uitest.cc ('k') | chrome_frame/test_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/process_util.h" 10 #include "base/process_util.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 51 }
52 52
53 class ChildProcessFilter : public base::ProcessFilter { 53 class ChildProcessFilter : public base::ProcessFilter {
54 public: 54 public:
55 explicit ChildProcessFilter(base::ProcessId parent_pid) 55 explicit ChildProcessFilter(base::ProcessId parent_pid)
56 : parent_pids_(&parent_pid, (&parent_pid) + 1) {} 56 : parent_pids_(&parent_pid, (&parent_pid) + 1) {}
57 57
58 explicit ChildProcessFilter(std::vector<base::ProcessId> parent_pids) 58 explicit ChildProcessFilter(std::vector<base::ProcessId> parent_pids)
59 : parent_pids_(parent_pids.begin(), parent_pids.end()) {} 59 : parent_pids_(parent_pids.begin(), parent_pids.end()) {}
60 60
61 virtual bool Includes(base::ProcessId pid, base::ProcessId parent_pid) const { 61 virtual bool Includes(const base::ProcessEntry& entry) const {
62 return parent_pids_.find(parent_pid) != parent_pids_.end(); 62 return parent_pids_.find(entry.parent_pid()) != parent_pids_.end();
63 } 63 }
64 64
65 private: 65 private:
66 const std::set<base::ProcessId> parent_pids_; 66 const std::set<base::ProcessId> parent_pids_;
67 67
68 DISALLOW_COPY_AND_ASSIGN(ChildProcessFilter); 68 DISALLOW_COPY_AND_ASSIGN(ChildProcessFilter);
69 }; 69 };
70 70
71 ChromeProcessList GetRunningChromeProcesses(base::ProcessId browser_pid) { 71 ChromeProcessList GetRunningChromeProcesses(base::ProcessId browser_pid) {
72 ChromeProcessList result; 72 ChromeProcessList result;
73 if (browser_pid == static_cast<base::ProcessId>(-1)) 73 if (browser_pid == static_cast<base::ProcessId>(-1))
74 return result; 74 return result;
75 75
76 ChildProcessFilter filter(browser_pid); 76 ChildProcessFilter filter(browser_pid);
77 base::NamedProcessIterator it(chrome::kBrowserProcessExecutableName, &filter); 77 base::NamedProcessIterator it(chrome::kBrowserProcessExecutableName, &filter);
78 while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) { 78 while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) {
79 #if defined(OS_WIN) 79 result.push_back(process_entry->pid());
80 result.push_back(process_entry->th32ProcessID);
81 #elif defined(OS_POSIX)
82 result.push_back(process_entry->pid);
83 #endif
84 } 80 }
85 81
86 #if defined(OS_LINUX) 82 #if defined(OS_LINUX)
87 // On Linux we might be running with a zygote process for the renderers. 83 // On Linux we might be running with a zygote process for the renderers.
88 // Because of that we sweep the list of processes again and pick those which 84 // Because of that we sweep the list of processes again and pick those which
89 // are children of one of the processes that we've already seen. 85 // are children of one of the processes that we've already seen.
90 { 86 {
91 ChildProcessFilter filter(result); 87 ChildProcessFilter filter(result);
92 base::NamedProcessIterator it(chrome::kBrowserProcessExecutableName, 88 base::NamedProcessIterator it(chrome::kBrowserProcessExecutableName,
93 &filter); 89 &filter);
94 while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) 90 while (const base::ProcessEntry* process_entry = it.NextProcessEntry())
95 result.push_back(process_entry->pid); 91 result.push_back(process_entry->pid());
96 } 92 }
97 #endif // defined(OS_LINUX) 93 #endif // defined(OS_LINUX)
98 94
99 #if defined(OS_LINUX) || defined(OS_MACOSX) 95 #if defined(OS_LINUX) || defined(OS_MACOSX)
100 // On Mac OS X we run the subprocesses with a different bundle, and 96 // On Mac OS X we run the subprocesses with a different bundle, and
101 // on Linux via /proc/self/exe, so they end up with a different 97 // on Linux via /proc/self/exe, so they end up with a different
102 // name. We must collect them in a second pass. 98 // name. We must collect them in a second pass.
103 { 99 {
104 ChildProcessFilter filter(browser_pid); 100 ChildProcessFilter filter(browser_pid);
105 base::NamedProcessIterator it(chrome::kHelperProcessExecutableName, 101 base::NamedProcessIterator it(chrome::kHelperProcessExecutableName,
106 &filter); 102 &filter);
107 while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) 103 while (const base::ProcessEntry* process_entry = it.NextProcessEntry())
108 result.push_back(process_entry->pid); 104 result.push_back(process_entry->pid());
109 } 105 }
110 #endif // defined(OS_MACOSX) 106 #endif // defined(OS_MACOSX)
111 107
112 result.push_back(browser_pid); 108 result.push_back(browser_pid);
113 109
114 return result; 110 return result;
115 } 111 }
116 112
117 #if !defined(OS_MACOSX) 113 #if !defined(OS_MACOSX)
118 114
119 size_t ChromeTestProcessMetrics::GetPagefileUsage() { 115 size_t ChromeTestProcessMetrics::GetPagefileUsage() {
120 return process_metrics_->GetPagefileUsage(); 116 return process_metrics_->GetPagefileUsage();
121 } 117 }
122 118
123 size_t ChromeTestProcessMetrics::GetWorkingSetSize() { 119 size_t ChromeTestProcessMetrics::GetWorkingSetSize() {
124 return process_metrics_->GetWorkingSetSize(); 120 return process_metrics_->GetWorkingSetSize();
125 } 121 }
126 122
127 #endif // !defined(OS_MACOSX) 123 #endif // !defined(OS_MACOSX)
OLDNEW
« no previous file with comments | « chrome/browser/process_singleton_win_uitest.cc ('k') | chrome_frame/test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698