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

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

Issue 868543002: Move OpenProcessHandle to Process::Open. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 10 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
OLDNEW
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
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);
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
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 }
OLDNEW
« no previous file with comments | « chrome/browser/service_process/service_process_control_browsertest.cc ('k') | chrome/test/perf/perf_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698