OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/spawner_communicator.h" | 5 #include "net/test/spawner_communicator.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/supports_user_data.h" | 10 #include "base/supports_user_data.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 const std::string& command, | 158 const std::string& command, |
159 const std::string& post_data, | 159 const std::string& post_data, |
160 int* result_code, | 160 int* result_code, |
161 std::string* data_received) { | 161 std::string* data_received) { |
162 MessageLoop* loop = io_thread_.message_loop(); | 162 MessageLoop* loop = io_thread_.message_loop(); |
163 DCHECK(loop); | 163 DCHECK(loop); |
164 DCHECK_EQ(MessageLoop::current(), loop); | 164 DCHECK_EQ(MessageLoop::current(), loop); |
165 | 165 |
166 // Prepare the URLRequest for sending the command. | 166 // Prepare the URLRequest for sending the command. |
167 DCHECK(!cur_request_.get()); | 167 DCHECK(!cur_request_.get()); |
| 168 context_.reset(new TestURLRequestContext); |
168 cur_request_.reset(new URLRequest(GenerateSpawnerCommandURL(command, port_), | 169 cur_request_.reset(new URLRequest(GenerateSpawnerCommandURL(command, port_), |
169 this)); | 170 this, |
| 171 context_.get())); |
170 DCHECK(cur_request_.get()); | 172 DCHECK(cur_request_.get()); |
171 int current_request_id = ++next_id_; | 173 int current_request_id = ++next_id_; |
172 SpawnerRequestData* data = new SpawnerRequestData(current_request_id, | 174 SpawnerRequestData* data = new SpawnerRequestData(current_request_id, |
173 result_code, | 175 result_code, |
174 data_received); | 176 data_received); |
175 DCHECK(data); | 177 DCHECK(data); |
176 cur_request_->SetUserData(this, data); | 178 cur_request_->SetUserData(this, data); |
177 | 179 |
178 // Build the URLRequest. | |
179 context_.reset(new TestURLRequestContext); | |
180 cur_request_->set_context(context_.get()); | |
181 if (post_data.empty()) { | 180 if (post_data.empty()) { |
182 cur_request_->set_method("GET"); | 181 cur_request_->set_method("GET"); |
183 } else { | 182 } else { |
184 cur_request_->set_method("POST"); | 183 cur_request_->set_method("POST"); |
185 cur_request_->AppendBytesToUpload(post_data.c_str(), post_data.size()); | 184 cur_request_->AppendBytesToUpload(post_data.c_str(), post_data.size()); |
186 net::HttpRequestHeaders headers; | 185 net::HttpRequestHeaders headers; |
187 headers.SetHeader(net::HttpRequestHeaders::kContentType, | 186 headers.SetHeader(net::HttpRequestHeaders::kContentType, |
188 "application/json"); | 187 "application/json"); |
189 cur_request_->SetExtraRequestHeaders(headers); | 188 cur_request_->SetExtraRequestHeaders(headers); |
190 } | 189 } |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 std::string server_return_data; | 361 std::string server_return_data; |
363 int result_code; | 362 int result_code; |
364 SendCommandAndWaitForResult("kill", "", &result_code, &server_return_data); | 363 SendCommandAndWaitForResult("kill", "", &result_code, &server_return_data); |
365 if (OK != result_code || server_return_data != "killed") | 364 if (OK != result_code || server_return_data != "killed") |
366 return false; | 365 return false; |
367 Shutdown(); | 366 Shutdown(); |
368 return true; | 367 return true; |
369 } | 368 } |
370 | 369 |
371 } // namespace net | 370 } // namespace net |
OLD | NEW |