Chromium Code Reviews| 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.h" | |
| 13 #include "base/process/process_iterator.h" | 14 #include "base/process/process_iterator.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "chrome/common/chrome_constants.h" | 16 #include "chrome/common/chrome_constants.h" |
| 16 #include "chrome/test/base/test_switches.h" | 17 #include "chrome/test/base/test_switches.h" |
| 17 #include "content/public/common/result_codes.h" | 18 #include "content/public/common/result_codes.h" |
| 18 | 19 |
| 19 using base::TimeDelta; | 20 using base::TimeDelta; |
| 20 using base::TimeTicks; | 21 using base::TimeTicks; |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 42 #endif | 43 #endif |
| 43 | 44 |
| 44 return names; | 45 return names; |
| 45 } | 46 } |
| 46 | 47 |
| 47 } // namespace | 48 } // namespace |
| 48 | 49 |
| 49 void TerminateAllChromeProcesses(const ChromeProcessList& process_pids) { | 50 void TerminateAllChromeProcesses(const ChromeProcessList& process_pids) { |
| 50 ChromeProcessList::const_iterator it; | 51 ChromeProcessList::const_iterator it; |
| 51 for (it = process_pids.begin(); it != process_pids.end(); ++it) { | 52 for (it = process_pids.begin(); it != process_pids.end(); ++it) { |
| 52 base::ProcessHandle handle; | 53 base::Process process = base::Process::Open(*it); |
| 53 if (!base::OpenProcessHandle(*it, &handle)) { | 54 if (process.IsValid()) { |
| 54 // Ignore processes for which we can't open the handle. We don't | 55 // Ignore processes for which we can't open the handle. We don't |
| 55 // guarantee that all processes will terminate, only try to do so. | 56 // guarantee that all processes will terminate, only try to do so. |
| 56 continue; | 57 base::KillProcess(process.Handle(), content::RESULT_CODE_KILLED, true); |
|
sky
2015/02/04 17:14:52
Seems like it would be nice to do process.Kill(...
rvargas (doing something else)
2015/02/04 18:19:51
Yes, that's part of the plan (remove the utility f
| |
| 57 } | 58 } |
| 58 | |
| 59 base::KillProcess(handle, content::RESULT_CODE_KILLED, true); | |
| 60 base::CloseProcessHandle(handle); | |
| 61 } | 59 } |
| 62 } | 60 } |
| 63 | 61 |
| 64 class ChildProcessFilter : public base::ProcessFilter { | 62 class ChildProcessFilter : public base::ProcessFilter { |
| 65 public: | 63 public: |
| 66 explicit ChildProcessFilter(base::ProcessId parent_pid) | 64 explicit ChildProcessFilter(base::ProcessId parent_pid) |
| 67 : parent_pids_(&parent_pid, (&parent_pid) + 1) {} | 65 : parent_pids_(&parent_pid, (&parent_pid) + 1) {} |
| 68 | 66 |
| 69 explicit ChildProcessFilter(const std::vector<base::ProcessId>& parent_pids) | 67 explicit ChildProcessFilter(const std::vector<base::ProcessId>& parent_pids) |
| 70 : parent_pids_(parent_pids.begin(), parent_pids.end()) {} | 68 : parent_pids_(parent_pids.begin(), parent_pids.end()) {} |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 base::ProcessHandle process) { | 142 base::ProcessHandle process) { |
| 145 #if !defined(OS_MACOSX) | 143 #if !defined(OS_MACOSX) |
| 146 process_metrics_.reset( | 144 process_metrics_.reset( |
| 147 base::ProcessMetrics::CreateProcessMetrics(process)); | 145 base::ProcessMetrics::CreateProcessMetrics(process)); |
| 148 #else | 146 #else |
| 149 process_metrics_.reset( | 147 process_metrics_.reset( |
| 150 base::ProcessMetrics::CreateProcessMetrics(process, NULL)); | 148 base::ProcessMetrics::CreateProcessMetrics(process, NULL)); |
| 151 #endif | 149 #endif |
| 152 process_handle_ = process; | 150 process_handle_ = process; |
| 153 } | 151 } |
| OLD | NEW |