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

Side by Side Diff: base/test/test_process_killer_win.cc

Issue 93903011: Remove 'using base::string16;' from base/strings/string16.h and remove temporary (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: asdf Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « base/strings/string16.h ('k') | base/test/test_reg_util_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "base/test/test_process_killer_win.h" 5 #include "base/test/test_process_killer_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <winternl.h> 8 #include <winternl.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 20 matching lines...) Expand all
31 static NtQueryInformationProcess* qip_func = 31 static NtQueryInformationProcess* qip_func =
32 reinterpret_cast<NtQueryInformationProcess*>( 32 reinterpret_cast<NtQueryInformationProcess*>(
33 GetProcAddress(GetModuleHandle(L"ntdll.dll"), 33 GetProcAddress(GetModuleHandle(L"ntdll.dll"),
34 "NtQueryInformationProcess")); 34 "NtQueryInformationProcess"));
35 DCHECK(qip_func) << "Could not get pointer to NtQueryInformationProcess."; 35 DCHECK(qip_func) << "Could not get pointer to NtQueryInformationProcess.";
36 *qip_func_ptr = qip_func; 36 *qip_func_ptr = qip_func;
37 return qip_func != NULL; 37 return qip_func != NULL;
38 } 38 }
39 39
40 // Get the command line of a process 40 // Get the command line of a process
41 bool GetCommandLineForProcess(uint32 process_id, string16* cmd_line) { 41 bool GetCommandLineForProcess(uint32 process_id, base::string16* cmd_line) {
42 DCHECK(process_id != 0); 42 DCHECK(process_id != 0);
43 DCHECK(cmd_line); 43 DCHECK(cmd_line);
44 44
45 // Open the process 45 // Open the process
46 base::win::ScopedHandle process_handle(::OpenProcess( 46 base::win::ScopedHandle process_handle(::OpenProcess(
47 PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 47 PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
48 false, 48 false,
49 process_id)); 49 process_id));
50 if (!process_handle) { 50 if (!process_handle) {
51 DLOG(ERROR) << "Failed to open process " << process_id << ", last error = " 51 DLOG(ERROR) << "Failed to open process " << process_id << ", last error = "
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 sizeof(process_params_address), 86 sizeof(process_params_address),
87 &bytes_read)) { 87 &bytes_read)) {
88 DLOG(ERROR) << "Failed to read process params address, last error = " 88 DLOG(ERROR) << "Failed to read process params address, last error = "
89 << GetLastError(); 89 << GetLastError();
90 } 90 }
91 } 91 }
92 } 92 }
93 93
94 // Copy all the process parameters into a buffer. 94 // Copy all the process parameters into a buffer.
95 bool success = false; 95 bool success = false;
96 string16 buffer; 96 base::string16 buffer;
97 if (process_params_address) { 97 if (process_params_address) {
98 SIZE_T bytes_read; 98 SIZE_T bytes_read;
99 RTL_USER_PROCESS_PARAMETERS params = { 0 }; 99 RTL_USER_PROCESS_PARAMETERS params = { 0 };
100 if (!::ReadProcessMemory(process_handle.Get(), 100 if (!::ReadProcessMemory(process_handle.Get(),
101 reinterpret_cast<void*>(process_params_address), 101 reinterpret_cast<void*>(process_params_address),
102 &params, 102 &params,
103 sizeof(params), 103 sizeof(params),
104 &bytes_read)) { 104 &bytes_read)) {
105 DLOG(ERROR) << "Failed to read RTL_USER_PROCESS_PARAMETERS, " 105 DLOG(ERROR) << "Failed to read RTL_USER_PROCESS_PARAMETERS, "
106 << "last error = " << GetLastError(); 106 << "last error = " << GetLastError();
(...skipping 16 matching lines...) Expand all
123 } 123 }
124 } 124 }
125 } 125 }
126 126
127 return success; 127 return success;
128 } 128 }
129 129
130 // Used to filter processes by process ID. 130 // Used to filter processes by process ID.
131 class ArgumentFilter : public base::ProcessFilter { 131 class ArgumentFilter : public base::ProcessFilter {
132 public: 132 public:
133 explicit ArgumentFilter(const string16& argument) 133 explicit ArgumentFilter(const base::string16& argument)
134 : argument_to_find_(argument) {} 134 : argument_to_find_(argument) {}
135 135
136 // Returns true to indicate set-inclusion and false otherwise. This method 136 // Returns true to indicate set-inclusion and false otherwise. This method
137 // should not have side-effects and should be idempotent. 137 // should not have side-effects and should be idempotent.
138 virtual bool Includes(const base::ProcessEntry& entry) const { 138 virtual bool Includes(const base::ProcessEntry& entry) const {
139 bool found = false; 139 bool found = false;
140 string16 command_line; 140 base::string16 command_line;
141 if (GetCommandLineForProcess(entry.pid(), &command_line)) { 141 if (GetCommandLineForProcess(entry.pid(), &command_line)) {
142 string16::const_iterator it = 142 base::string16::const_iterator it =
143 std::search(command_line.begin(), 143 std::search(command_line.begin(),
144 command_line.end(), 144 command_line.end(),
145 argument_to_find_.begin(), 145 argument_to_find_.begin(),
146 argument_to_find_.end(), 146 argument_to_find_.end(),
147 base::CaseInsensitiveCompareASCII<wchar_t>()); 147 base::CaseInsensitiveCompareASCII<wchar_t>());
148 found = (it != command_line.end()); 148 found = (it != command_line.end());
149 } 149 }
150 return found; 150 return found;
151 } 151 }
152 152
153 protected: 153 protected:
154 string16 argument_to_find_; 154 base::string16 argument_to_find_;
155 }; 155 };
156 156
157 } // namespace 157 } // namespace
158 158
159 namespace base { 159 namespace base {
160 160
161 bool KillAllNamedProcessesWithArgument(const string16& process_name, 161 bool KillAllNamedProcessesWithArgument(const string16& process_name,
162 const string16& argument) { 162 const string16& argument) {
163 ArgumentFilter argument_filter(argument); 163 ArgumentFilter argument_filter(argument);
164 return base::KillProcesses(process_name, 0, &argument_filter); 164 return base::KillProcesses(process_name, 0, &argument_filter);
165 } 165 }
166 166
167 } // namespace base 167 } // namespace base
OLDNEW
« no previous file with comments | « base/strings/string16.h ('k') | base/test/test_reg_util_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698