OLD | NEW |
1 // Copyright (c) 2010 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 "net/test/test_server.h" | 5 #include "net/test/test_server.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <wincrypt.h> | 8 #include <wincrypt.h> |
9 | 9 |
10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/test/test_timeouts.h" | 17 #include "base/test/test_timeouts.h" |
18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "base/win/scoped_handle.h" |
20 | 21 |
21 #pragma comment(lib, "crypt32.lib") | 22 #pragma comment(lib, "crypt32.lib") |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 bool LaunchTestServerAsJob(const CommandLine& cmdline, | 26 bool LaunchTestServerAsJob(const CommandLine& cmdline, |
26 bool start_hidden, | 27 bool start_hidden, |
27 base::ProcessHandle* process_handle, | 28 base::ProcessHandle* process_handle, |
28 ScopedHandle* job_handle) { | 29 base::win::ScopedHandle* job_handle) { |
29 // Launch test server process. | 30 // Launch test server process. |
30 STARTUPINFO startup_info = {0}; | 31 STARTUPINFO startup_info = {0}; |
31 startup_info.cb = sizeof(startup_info); | 32 startup_info.cb = sizeof(startup_info); |
32 startup_info.dwFlags = STARTF_USESHOWWINDOW; | 33 startup_info.dwFlags = STARTF_USESHOWWINDOW; |
33 startup_info.wShowWindow = start_hidden ? SW_HIDE : SW_SHOW; | 34 startup_info.wShowWindow = start_hidden ? SW_HIDE : SW_SHOW; |
34 PROCESS_INFORMATION process_info; | 35 PROCESS_INFORMATION process_info; |
35 | 36 |
36 // If this code is run under a debugger, the test server process is | 37 // If this code is run under a debugger, the test server process is |
37 // automatically associated with a job object created by the debugger. | 38 // automatically associated with a job object created by the debugger. |
38 // The CREATE_BREAKAWAY_FROM_JOB flag is used to prevent this. | 39 // The CREATE_BREAKAWAY_FROM_JOB flag is used to prevent this. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 &process_handle_, | 185 &process_handle_, |
185 &job_handle_)) { | 186 &job_handle_)) { |
186 LOG(ERROR) << "Failed to launch " << python_command.command_line_string(); | 187 LOG(ERROR) << "Failed to launch " << python_command.command_line_string(); |
187 return false; | 188 return false; |
188 } | 189 } |
189 | 190 |
190 return true; | 191 return true; |
191 } | 192 } |
192 | 193 |
193 bool TestServer::WaitToStart() { | 194 bool TestServer::WaitToStart() { |
194 ScopedHandle read_fd(child_read_fd_.Take()); | 195 base::win::ScopedHandle read_fd(child_read_fd_.Take()); |
195 ScopedHandle write_fd(child_write_fd_.Take()); | 196 base::win::ScopedHandle write_fd(child_write_fd_.Take()); |
196 | 197 |
197 uint32 server_data_len = 0; | 198 uint32 server_data_len = 0; |
198 if (!ReadData(read_fd.Get(), write_fd.Get(), sizeof(server_data_len), | 199 if (!ReadData(read_fd.Get(), write_fd.Get(), sizeof(server_data_len), |
199 reinterpret_cast<uint8*>(&server_data_len))) { | 200 reinterpret_cast<uint8*>(&server_data_len))) { |
200 LOG(ERROR) << "Could not read server_data_len"; | 201 LOG(ERROR) << "Could not read server_data_len"; |
201 return false; | 202 return false; |
202 } | 203 } |
203 std::string server_data(server_data_len, '\0'); | 204 std::string server_data(server_data_len, '\0'); |
204 if (!ReadData(read_fd.Get(), write_fd.Get(), server_data_len, | 205 if (!ReadData(read_fd.Get(), write_fd.Get(), server_data_len, |
205 reinterpret_cast<uint8*>(&server_data[0]))) { | 206 reinterpret_cast<uint8*>(&server_data[0]))) { |
206 LOG(ERROR) << "Could not read server_data (" << server_data_len | 207 LOG(ERROR) << "Could not read server_data (" << server_data_len |
207 << " bytes)"; | 208 << " bytes)"; |
208 return false; | 209 return false; |
209 } | 210 } |
210 | 211 |
211 if (!ParseServerData(server_data)) { | 212 if (!ParseServerData(server_data)) { |
212 LOG(ERROR) << "Could not parse server_data: " << server_data; | 213 LOG(ERROR) << "Could not parse server_data: " << server_data; |
213 return false; | 214 return false; |
214 } | 215 } |
215 | 216 |
216 return true; | 217 return true; |
217 } | 218 } |
218 | 219 |
219 } // namespace net | 220 } // namespace net |
OLD | NEW |