| 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 <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/process/kill.h" | 12 #include "base/process/kill.h" |
| 13 #include "base/process/process_iterator.h" | 13 #include "base/process/process_iterator.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "chrome/common/chrome_constants.h" | 15 #include "chrome/common/chrome_constants.h" |
| 16 #include "chrome/test/base/test_switches.h" | 16 #include "chrome/test/base/test_switches.h" |
| 17 #include "content/public/common/result_codes.h" | 17 #include "content/public/common/result_codes.h" |
| 18 | 18 |
| 19 using base::TimeDelta; | 19 using base::TimeDelta; |
| 20 using base::TimeTicks; | 20 using base::TimeTicks; |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // Returns the executable name of the current Chrome browser process. | |
| 25 const base::FilePath::CharType* GetRunningBrowserExecutableName() { | |
| 26 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | |
| 27 if (cmd_line->HasSwitch(switches::kEnableChromiumBranding)) | |
| 28 return chrome::kBrowserProcessExecutableNameChromium; | |
| 29 return chrome::kBrowserProcessExecutableName; | |
| 30 } | |
| 31 | |
| 32 // Returns the executable name of the current Chrome helper process. | 24 // Returns the executable name of the current Chrome helper process. |
| 33 std::vector<base::FilePath::StringType> GetRunningHelperExecutableNames() { | 25 std::vector<base::FilePath::StringType> GetRunningHelperExecutableNames() { |
| 34 base::FilePath::StringType name; | 26 base::FilePath::StringType name = chrome::kHelperProcessExecutableName; |
| 35 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | |
| 36 if (cmd_line->HasSwitch(switches::kEnableChromiumBranding)) { | |
| 37 name = chrome::kHelperProcessExecutableNameChromium; | |
| 38 } else { | |
| 39 name = chrome::kHelperProcessExecutableName; | |
| 40 } | |
| 41 | 27 |
| 42 std::vector<base::FilePath::StringType> names; | 28 std::vector<base::FilePath::StringType> names; |
| 43 names.push_back(name); | 29 names.push_back(name); |
| 44 | 30 |
| 45 #if defined(OS_MACOSX) | 31 #if defined(OS_MACOSX) |
| 46 // The helper might show up as these different flavors depending on the | 32 // The helper might show up as these different flavors depending on the |
| 47 // executable flags required. | 33 // executable flags required. |
| 48 for (const char* const* suffix = chrome::kHelperFlavorSuffixes; | 34 for (const char* const* suffix = chrome::kHelperFlavorSuffixes; |
| 49 *suffix; | 35 *suffix; |
| 50 ++suffix) { | 36 ++suffix) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 74 } |
| 89 | 75 |
| 90 private: | 76 private: |
| 91 const std::set<base::ProcessId> parent_pids_; | 77 const std::set<base::ProcessId> parent_pids_; |
| 92 | 78 |
| 93 DISALLOW_COPY_AND_ASSIGN(ChildProcessFilter); | 79 DISALLOW_COPY_AND_ASSIGN(ChildProcessFilter); |
| 94 }; | 80 }; |
| 95 | 81 |
| 96 ChromeProcessList GetRunningChromeProcesses(base::ProcessId browser_pid) { | 82 ChromeProcessList GetRunningChromeProcesses(base::ProcessId browser_pid) { |
| 97 const base::FilePath::CharType* executable_name = | 83 const base::FilePath::CharType* executable_name = |
| 98 GetRunningBrowserExecutableName(); | 84 chrome::kBrowserProcessExecutableName; |
| 99 ChromeProcessList result; | 85 ChromeProcessList result; |
| 100 if (browser_pid == static_cast<base::ProcessId>(-1)) | 86 if (browser_pid == static_cast<base::ProcessId>(-1)) |
| 101 return result; | 87 return result; |
| 102 | 88 |
| 103 ChildProcessFilter filter(browser_pid); | 89 ChildProcessFilter filter(browser_pid); |
| 104 base::NamedProcessIterator it(executable_name, &filter); | 90 base::NamedProcessIterator it(executable_name, &filter); |
| 105 while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) { | 91 while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) { |
| 106 result.push_back(process_entry->pid()); | 92 result.push_back(process_entry->pid()); |
| 107 } | 93 } |
| 108 | 94 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 base::ProcessHandle process) { | 144 base::ProcessHandle process) { |
| 159 #if !defined(OS_MACOSX) | 145 #if !defined(OS_MACOSX) |
| 160 process_metrics_.reset( | 146 process_metrics_.reset( |
| 161 base::ProcessMetrics::CreateProcessMetrics(process)); | 147 base::ProcessMetrics::CreateProcessMetrics(process)); |
| 162 #else | 148 #else |
| 163 process_metrics_.reset( | 149 process_metrics_.reset( |
| 164 base::ProcessMetrics::CreateProcessMetrics(process, NULL)); | 150 base::ProcessMetrics::CreateProcessMetrics(process, NULL)); |
| 165 #endif | 151 #endif |
| 166 process_handle_ = process; | 152 process_handle_ = process; |
| 167 } | 153 } |
| OLD | NEW |