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" |
11 #include "base/test/test_timeouts.h" | 11 #include "base/test/test_timeouts.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
17 #include "net/base/upload_data.h" | 17 #include "net/base/upload_bytes_element_reader.h" |
| 18 #include "net/base/upload_data_stream.h" |
18 #include "net/http/http_response_headers.h" | 19 #include "net/http/http_response_headers.h" |
19 #include "net/url_request/url_request_test_util.h" | 20 #include "net/url_request/url_request_test_util.h" |
20 | 21 |
21 namespace net { | 22 namespace net { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 GURL GenerateSpawnerCommandURL(const std::string& command, uint16 port) { | 26 GURL GenerateSpawnerCommandURL(const std::string& command, uint16 port) { |
26 // Always performs HTTP request for sending command to the spawner server. | 27 // Always performs HTTP request for sending command to the spawner server. |
27 return GURL(base::StringPrintf("%s:%u/%s", "http://127.0.0.1", port, | 28 return GURL(base::StringPrintf("%s:%u/%s", "http://127.0.0.1", port, |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 SpawnerRequestData* data = new SpawnerRequestData(current_request_id, | 178 SpawnerRequestData* data = new SpawnerRequestData(current_request_id, |
178 result_code, | 179 result_code, |
179 data_received); | 180 data_received); |
180 DCHECK(data); | 181 DCHECK(data); |
181 cur_request_->SetUserData(this, data); | 182 cur_request_->SetUserData(this, data); |
182 | 183 |
183 if (post_data.empty()) { | 184 if (post_data.empty()) { |
184 cur_request_->set_method("GET"); | 185 cur_request_->set_method("GET"); |
185 } else { | 186 } else { |
186 cur_request_->set_method("POST"); | 187 cur_request_->set_method("POST"); |
187 scoped_refptr<UploadData> upload_data(new UploadData()); | 188 scoped_ptr<UploadElementReader> reader( |
188 upload_data->AppendBytes(post_data.c_str(), post_data.size()); | 189 UploadOwnedBytesElementReader::CreateWithString(post_data)); |
189 cur_request_->set_upload(upload_data); | 190 cur_request_->set_upload(make_scoped_ptr( |
| 191 UploadDataStream::CreateWithReader(reader.Pass(), 0))); |
190 net::HttpRequestHeaders headers; | 192 net::HttpRequestHeaders headers; |
191 headers.SetHeader(net::HttpRequestHeaders::kContentType, | 193 headers.SetHeader(net::HttpRequestHeaders::kContentType, |
192 "application/json"); | 194 "application/json"); |
193 cur_request_->SetExtraRequestHeaders(headers); | 195 cur_request_->SetExtraRequestHeaders(headers); |
194 } | 196 } |
195 | 197 |
196 // Post a task to timeout this request if it takes too long. | 198 // Post a task to timeout this request if it takes too long. |
197 MessageLoop::current()->PostDelayedTask( | 199 MessageLoop::current()->PostDelayedTask( |
198 FROM_HERE, | 200 FROM_HERE, |
199 base::Bind(&SpawnerCommunicator::OnTimeout, weak_factory_.GetWeakPtr(), | 201 base::Bind(&SpawnerCommunicator::OnTimeout, weak_factory_.GetWeakPtr(), |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 std::string server_return_data; | 368 std::string server_return_data; |
367 int result_code; | 369 int result_code; |
368 SendCommandAndWaitForResult("kill", "", &result_code, &server_return_data); | 370 SendCommandAndWaitForResult("kill", "", &result_code, &server_return_data); |
369 Shutdown(); | 371 Shutdown(); |
370 if (OK != result_code || server_return_data != "killed") | 372 if (OK != result_code || server_return_data != "killed") |
371 return false; | 373 return false; |
372 return true; | 374 return true; |
373 } | 375 } |
374 | 376 |
375 } // namespace net | 377 } // namespace net |
OLD | NEW |