summaryrefslogtreecommitdiffstats
path: root/chrome/test/chrome_process_util.cc
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-12 17:36:55 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-12 17:36:55 +0000
commitcc8f146d34a3b13cd80d8b3530fd76445774b1c6 (patch)
tree65ddd346a7b468f716f0022507112ec7215a17f7 /chrome/test/chrome_process_util.cc
parent9ab7d838fba71523a32d1b1e50e5d9a1c20815b2 (diff)
downloadchromium_src-cc8f146d34a3b13cd80d8b3530fd76445774b1c6.zip
chromium_src-cc8f146d34a3b13cd80d8b3530fd76445774b1c6.tar.gz
chromium_src-cc8f146d34a3b13cd80d8b3530fd76445774b1c6.tar.bz2
Linux: refactor zygote support
http://code.google.com/p/chromium/wiki/LinuxZygote * Move Chrome specific bits out of base * Move away from the idea of reserved file descriptors (which don't really work with zygotes) * Load resources before forking renderers (means that we don't need communication between the zygote process and the renderers) * Make sure that gdb works against the browser again * Make sure that we have different ASLR between the renderers and the browser. http://codereview.chromium.org/119335 (This is a reland. First landed in r18109, reverted in r18112.) git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18291 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/chrome_process_util.cc')
-rw-r--r--chrome/test/chrome_process_util.cc78
1 files changed, 36 insertions, 42 deletions
diff --git a/chrome/test/chrome_process_util.cc b/chrome/test/chrome_process_util.cc
index 296b291..9d858e4 100644
--- a/chrome/test/chrome_process_util.cc
+++ b/chrome/test/chrome_process_util.cc
@@ -5,6 +5,7 @@
#include "chrome/test/chrome_process_util.h"
#include <vector>
+#include <set>
#include "base/process_util.h"
#include "base/time.h"
@@ -14,26 +15,6 @@
using base::Time;
using base::TimeDelta;
-namespace {
-
-class ChromeProcessFilter : public base::ProcessFilter {
- public:
- explicit ChromeProcessFilter(base::ProcessId browser_pid)
- : browser_pid_(browser_pid) {}
-
- virtual bool Includes(base::ProcessId pid, base::ProcessId parent_pid) const {
- // Match browser process itself and its children.
- return browser_pid_ == pid || browser_pid_ == parent_pid;
- }
-
- private:
- base::ProcessId browser_pid_;
-
- DISALLOW_COPY_AND_ASSIGN(ChromeProcessFilter);
-};
-
-} // namespace
-
void TerminateAllChromeProcesses(const FilePath& data_dir) {
// Total time the function will wait for chrome processes
// to terminate after it told them to do so.
@@ -70,44 +51,57 @@ void TerminateAllChromeProcesses(const FilePath& data_dir) {
base::CloseProcessHandle(*it);
}
+class ChildProcessFilter : public base::ProcessFilter {
+ public:
+ explicit ChildProcessFilter(base::ProcessId parent_pid)
+ : parent_pids_(&parent_pid, (&parent_pid) + 1) {}
+
+ 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();
+ }
+
+ private:
+ const std::set<base::ProcessId> parent_pids_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChildProcessFilter);
+};
+
ChromeProcessList GetRunningChromeProcesses(const FilePath& data_dir) {
ChromeProcessList result;
base::ProcessId browser_pid = ChromeBrowserProcessId(data_dir);
- if (browser_pid < 0)
+ if (browser_pid == (base::ProcessId) -1)
return result;
- // Normally, the browser is the parent process for all the renderers
- base::ProcessId parent_pid = browser_pid;
-
-#if defined(OS_LINUX)
- // But if the browser's parent is the same executable as the browser,
- // then it's the zygote manager, and it's the parent for all the renderers.
- base::ProcessId manager_pid = base::GetParentProcessId(browser_pid);
- FilePath selfPath = base::GetProcessExecutablePath(browser_pid);
- FilePath managerPath = base::GetProcessExecutablePath(manager_pid);
- if (!selfPath.empty() && !managerPath.empty() && selfPath == managerPath) {
- LOG(INFO) << "Zygote manager in use.";
- parent_pid = manager_pid;
- }
-#endif
-
- ChromeProcessFilter filter(parent_pid);
+ ChildProcessFilter filter(browser_pid);
base::NamedProcessIterator it(chrome::kBrowserProcessExecutableName, &filter);
const ProcessEntry* process_entry;
while ((process_entry = it.NextProcessEntry())) {
#if defined(OS_WIN)
result.push_back(process_entry->th32ProcessID);
-#elif defined(OS_LINUX)
- // Don't count the zygote manager, that screws up unit tests,
- // and it will exit cleanly on its own when first client exits.
- if (process_entry->pid != manager_pid)
- result.push_back(process_entry->pid);
#elif defined(OS_POSIX)
result.push_back(process_entry->pid);
#endif
}
+#if defined(OS_LINUX)
+ // On Linux we might be running with a zygote process for the renderers.
+ // Because of that we sweep the list of processes again and pick those which
+ // are children of one of the processes that we've already seen.
+ {
+ ChildProcessFilter filter(result);
+ base::NamedProcessIterator it(chrome::kBrowserProcessExecutableName,
+ &filter);
+ while ((process_entry = it.NextProcessEntry()))
+ result.push_back(process_entry->pid);
+ }
+#endif
+
+ result.push_back(browser_pid);
+
return result;
}