OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/test/chrome_process_util.h" |
| 6 |
| 7 #include <windows.h> |
| 8 |
| 9 #include <vector> |
| 10 |
| 11 #include "base/logging.h" |
| 12 #include "base/process_util.h" |
| 13 #include "chrome/common/chrome_constants.h" |
| 14 |
| 15 namespace { |
| 16 |
| 17 class ChromeProcessFilter : public base::ProcessFilter { |
| 18 public: |
| 19 explicit ChromeProcessFilter(base::ProcessId browser_pid) |
| 20 : browser_pid_(browser_pid) {} |
| 21 |
| 22 virtual bool Includes(base::ProcessId pid, base::ProcessId parent_pid) const { |
| 23 // Match browser process itself and its children. |
| 24 return browser_pid_ == pid || browser_pid_ == parent_pid; |
| 25 } |
| 26 |
| 27 private: |
| 28 base::ProcessId browser_pid_; |
| 29 |
| 30 DISALLOW_COPY_AND_ASSIGN(ChromeProcessFilter); |
| 31 }; |
| 32 |
| 33 } // namespace |
| 34 |
| 35 base::ProcessId ChromeBrowserProcessId(const FilePath& data_dir) { |
| 36 HWND message_window = FindWindowEx(HWND_MESSAGE, NULL, |
| 37 chrome::kMessageWindowClass, |
| 38 data_dir.value().c_str()); |
| 39 if (!message_window) |
| 40 return -1; |
| 41 |
| 42 DWORD browser_pid = -1; |
| 43 GetWindowThreadProcessId(message_window, &browser_pid); |
| 44 |
| 45 return browser_pid; |
| 46 } |
| 47 |
| 48 ChromeProcessList GetRunningChromeProcesses(const FilePath& data_dir) { |
| 49 ChromeProcessList result; |
| 50 |
| 51 base::ProcessId browser_pid = ChromeBrowserProcessId(data_dir); |
| 52 if (browser_pid < 0) |
| 53 return result; |
| 54 |
| 55 ChromeProcessFilter filter(browser_pid); |
| 56 base::NamedProcessIterator it(chrome::kBrowserProcessExecutableName, &filter); |
| 57 |
| 58 const ProcessEntry* process_entry; |
| 59 while (process_entry = it.NextProcessEntry()) |
| 60 result.push_back(process_entry->th32ProcessID); |
| 61 |
| 62 return result; |
| 63 } |
OLD | NEW |