OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/spdy/spdy_http_stream.h" | 5 #include "net/spdy/spdy_http_stream.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 } | 255 } |
256 | 256 |
257 int SpdyHttpStream::SendRequest(const std::string& /*headers_string*/, | 257 int SpdyHttpStream::SendRequest(const std::string& /*headers_string*/, |
258 UploadDataStream* request_body, | 258 UploadDataStream* request_body, |
259 HttpResponseInfo* response, | 259 HttpResponseInfo* response, |
260 CompletionCallback* callback) { | 260 CompletionCallback* callback) { |
261 base::Time request_time = base::Time::Now(); | 261 base::Time request_time = base::Time::Now(); |
262 CHECK(stream_.get()); | 262 CHECK(stream_.get()); |
263 | 263 |
264 stream_->SetDelegate(this); | 264 stream_->SetDelegate(this); |
| 265 |
265 linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock); | 266 linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock); |
266 CreateSpdyHeadersFromHttpRequest(*request_info_, headers.get()); | 267 CreateSpdyHeadersFromHttpRequest(*request_info_, headers.get()); |
267 stream_->set_spdy_headers(headers); | 268 stream_->set_spdy_headers(headers); |
268 | 269 |
269 stream_->SetRequestTime(request_time); | 270 stream_->SetRequestTime(request_time); |
270 // This should only get called in the case of a request occurring | 271 // This should only get called in the case of a request occurring |
271 // during server push that has already begun but hasn't finished, | 272 // during server push that has already begun but hasn't finished, |
272 // so we set the response's request time to be the actual one | 273 // so we set the response's request time to be the actual one |
273 if (response_info_) | 274 if (response_info_) |
274 response_info_->request_time = request_time; | 275 response_info_->request_time = request_time; |
275 | 276 |
276 CHECK(!request_body_stream_.get()); | 277 CHECK(!request_body_stream_.get()); |
277 if (request_body) { | 278 if (request_body) { |
278 if (request_body->size()) | 279 if (request_body->size()) |
279 request_body_stream_.reset(request_body); | 280 request_body_stream_.reset(request_body); |
280 else | 281 else |
281 delete request_body; | 282 delete request_body; |
282 } | 283 } |
283 | 284 |
284 CHECK(callback); | 285 CHECK(callback); |
285 CHECK(!stream_->cancelled()); | 286 CHECK(!stream_->cancelled()); |
286 CHECK(response); | 287 CHECK(response); |
287 | 288 |
288 if (stream_->response_complete()) { | 289 if (!stream_->pushed() && stream_->response_complete()) { |
289 if (stream_->response_status() == OK) | 290 if (stream_->response_status() == OK) |
290 return ERR_FAILED; | 291 return ERR_FAILED; |
291 else | 292 else |
292 return stream_->response_status(); | 293 return stream_->response_status(); |
293 } | 294 } |
294 | 295 |
295 // SendRequest can be called in two cases. | 296 // SendRequest can be called in two cases. |
296 // | 297 // |
297 // a) A client initiated request. In this case, |response_info_| should be | 298 // a) A client initiated request. In this case, |response_info_| should be |
298 // NULL to start with. | 299 // NULL to start with. |
299 // b) A client request which matches a response that the server has already | 300 // b) A client request which matches a response that the server has already |
300 // pushed. In this case, the value of |*push_response_info_| is copied | 301 // pushed. |
301 // over to the new response object |*response|. |push_response_info_| is | |
302 // deleted, and |response_info_| is reset |response|. | |
303 if (push_response_info_.get()) { | 302 if (push_response_info_.get()) { |
304 *response = *push_response_info_; | 303 *response = *(push_response_info_.get()); |
305 push_response_info_.reset(); | 304 push_response_info_.reset(); |
306 response_info_ = NULL; | |
307 } | 305 } |
| 306 else |
| 307 DCHECK_EQ(static_cast<HttpResponseInfo*>(NULL), response_info_); |
308 | 308 |
309 DCHECK_EQ(static_cast<HttpResponseInfo*>(NULL), response_info_); | |
310 response_info_ = response; | 309 response_info_ = response; |
311 | 310 |
312 bool has_upload_data = request_body_stream_.get() != NULL; | 311 bool has_upload_data = request_body_stream_.get() != NULL; |
313 int result = stream_->DoSendRequest(has_upload_data); | 312 int result = stream_->DoSendRequest(has_upload_data); |
314 if (result == ERR_IO_PENDING) { | 313 if (result == ERR_IO_PENDING) { |
315 CHECK(!user_callback_); | 314 CHECK(!user_callback_); |
316 user_callback_ = callback; | 315 user_callback_ = callback; |
317 } | 316 } |
318 return result; | 317 return result; |
319 } | 318 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 CHECK_NE(rv, ERR_IO_PENDING); | 476 CHECK_NE(rv, ERR_IO_PENDING); |
478 CHECK(user_callback_); | 477 CHECK(user_callback_); |
479 | 478 |
480 // Since Run may result in being called back, clear user_callback_ in advance. | 479 // Since Run may result in being called back, clear user_callback_ in advance. |
481 CompletionCallback* c = user_callback_; | 480 CompletionCallback* c = user_callback_; |
482 user_callback_ = NULL; | 481 user_callback_ = NULL; |
483 c->Run(rv); | 482 c->Run(rv); |
484 } | 483 } |
485 | 484 |
486 } // namespace net | 485 } // namespace net |
OLD | NEW |