| OLD | NEW |
| 1 // Copyright (c) 2011 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/http/http_pipelined_connection_impl.h" | 5 #include "net/http/http_pipelined_connection_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 7 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 8 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 9 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
| 10 #include "net/http/http_pipelined_stream.h" | 12 #include "net/http/http_pipelined_stream.h" |
| 11 #include "net/http/http_request_info.h" | 13 #include "net/http/http_request_info.h" |
| 12 #include "net/http/http_response_body_drainer.h" | 14 #include "net/http/http_response_body_drainer.h" |
| 13 #include "net/http/http_response_headers.h" | 15 #include "net/http/http_response_headers.h" |
| 14 #include "net/http/http_stream_parser.h" | 16 #include "net/http/http_stream_parser.h" |
| 15 #include "net/http/http_version.h" | 17 #include "net/http/http_version.h" |
| 16 #include "net/socket/client_socket_handle.h" | 18 #include "net/socket/client_socket_handle.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 28 connection_(connection), | 30 connection_(connection), |
| 29 used_ssl_config_(used_ssl_config), | 31 used_ssl_config_(used_ssl_config), |
| 30 used_proxy_info_(used_proxy_info), | 32 used_proxy_info_(used_proxy_info), |
| 31 net_log_(net_log), | 33 net_log_(net_log), |
| 32 was_npn_negotiated_(was_npn_negotiated), | 34 was_npn_negotiated_(was_npn_negotiated), |
| 33 read_buf_(new GrowableIOBuffer()), | 35 read_buf_(new GrowableIOBuffer()), |
| 34 next_pipeline_id_(1), | 36 next_pipeline_id_(1), |
| 35 active_(false), | 37 active_(false), |
| 36 usable_(true), | 38 usable_(true), |
| 37 completed_one_request_(false), | 39 completed_one_request_(false), |
| 38 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 40 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 39 send_next_state_(SEND_STATE_NONE), | 41 send_next_state_(SEND_STATE_NONE), |
| 40 send_still_on_call_stack_(false), | 42 send_still_on_call_stack_(false), |
| 41 ALLOW_THIS_IN_INITIALIZER_LIST(send_io_callback_( | |
| 42 this, &HttpPipelinedConnectionImpl::OnSendIOCallback)), | |
| 43 read_next_state_(READ_STATE_NONE), | 43 read_next_state_(READ_STATE_NONE), |
| 44 active_read_id_(0), | 44 active_read_id_(0), |
| 45 read_still_on_call_stack_(false), | 45 read_still_on_call_stack_(false) { |
| 46 ALLOW_THIS_IN_INITIALIZER_LIST(read_io_callback_( | |
| 47 this, &HttpPipelinedConnectionImpl::OnReadIOCallback)) { | |
| 48 CHECK(connection_.get()); | 46 CHECK(connection_.get()); |
| 49 } | 47 } |
| 50 | 48 |
| 51 HttpPipelinedConnectionImpl::~HttpPipelinedConnectionImpl() { | 49 HttpPipelinedConnectionImpl::~HttpPipelinedConnectionImpl() { |
| 52 CHECK_EQ(depth(), 0); | 50 CHECK_EQ(depth(), 0); |
| 53 CHECK(stream_info_map_.empty()); | 51 CHECK(stream_info_map_.empty()); |
| 54 CHECK(pending_send_request_queue_.empty()); | 52 CHECK(pending_send_request_queue_.empty()); |
| 55 CHECK(request_order_.empty()); | 53 CHECK(request_order_.empty()); |
| 56 CHECK_EQ(send_next_state_, SEND_STATE_NONE); | 54 CHECK_EQ(send_next_state_, SEND_STATE_NONE); |
| 57 CHECK_EQ(read_next_state_, READ_STATE_NONE); | 55 CHECK_EQ(read_next_state_, READ_STATE_NONE); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 79 CHECK(!stream_info_map_[pipeline_id].parser.get()); | 77 CHECK(!stream_info_map_[pipeline_id].parser.get()); |
| 80 stream_info_map_[pipeline_id].state = STREAM_BOUND; | 78 stream_info_map_[pipeline_id].state = STREAM_BOUND; |
| 81 stream_info_map_[pipeline_id].parser.reset(new HttpStreamParser( | 79 stream_info_map_[pipeline_id].parser.reset(new HttpStreamParser( |
| 82 connection_.get(), request, read_buf_.get(), net_log)); | 80 connection_.get(), request, read_buf_.get(), net_log)); |
| 83 | 81 |
| 84 // In case our first stream doesn't SendRequest() immediately, we should still | 82 // In case our first stream doesn't SendRequest() immediately, we should still |
| 85 // allow others to use this pipeline. | 83 // allow others to use this pipeline. |
| 86 if (pipeline_id == 1) { | 84 if (pipeline_id == 1) { |
| 87 MessageLoop::current()->PostTask( | 85 MessageLoop::current()->PostTask( |
| 88 FROM_HERE, | 86 FROM_HERE, |
| 89 method_factory_.NewRunnableMethod( | 87 base::Bind(&HttpPipelinedConnectionImpl::ActivatePipeline, |
| 90 &HttpPipelinedConnectionImpl::ActivatePipeline)); | 88 weak_factory_.GetWeakPtr())); |
| 91 } | 89 } |
| 92 } | 90 } |
| 93 | 91 |
| 94 void HttpPipelinedConnectionImpl::ActivatePipeline() { | 92 void HttpPipelinedConnectionImpl::ActivatePipeline() { |
| 95 if (!active_) { | 93 if (!active_) { |
| 96 active_ = true; | 94 active_ = true; |
| 97 delegate_->OnPipelineHasCapacity(this); | 95 delegate_->OnPipelineHasCapacity(this); |
| 98 } | 96 } |
| 99 } | 97 } |
| 100 | 98 |
| 101 void HttpPipelinedConnectionImpl::OnStreamDeleted(int pipeline_id) { | 99 void HttpPipelinedConnectionImpl::OnStreamDeleted(int pipeline_id) { |
| 102 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 100 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 103 Close(pipeline_id, false); | 101 Close(pipeline_id, false); |
| 104 | 102 |
| 105 if (stream_info_map_[pipeline_id].state != STREAM_CREATED && | 103 if (stream_info_map_[pipeline_id].state != STREAM_CREATED && |
| 106 stream_info_map_[pipeline_id].state != STREAM_UNUSED) { | 104 stream_info_map_[pipeline_id].state != STREAM_UNUSED) { |
| 107 CHECK_EQ(stream_info_map_[pipeline_id].state, STREAM_CLOSED); | 105 CHECK_EQ(stream_info_map_[pipeline_id].state, STREAM_CLOSED); |
| 108 CHECK(stream_info_map_[pipeline_id].parser.get()); | 106 CHECK(stream_info_map_[pipeline_id].parser.get()); |
| 109 stream_info_map_[pipeline_id].parser.reset(); | 107 stream_info_map_[pipeline_id].parser.reset(); |
| 110 } | 108 } |
| 111 CHECK(!stream_info_map_[pipeline_id].parser.get()); | 109 CHECK(!stream_info_map_[pipeline_id].parser.get()); |
| 112 stream_info_map_.erase(pipeline_id); | 110 stream_info_map_.erase(pipeline_id); |
| 113 | 111 |
| 114 delegate_->OnPipelineHasCapacity(this); | 112 delegate_->OnPipelineHasCapacity(this); |
| 115 } | 113 } |
| 116 | 114 |
| 117 int HttpPipelinedConnectionImpl::SendRequest(int pipeline_id, | 115 int HttpPipelinedConnectionImpl::SendRequest( |
| 118 const std::string& request_line, | 116 int pipeline_id, const std::string& request_line, |
| 119 const HttpRequestHeaders& headers, | 117 const HttpRequestHeaders& headers, UploadDataStream* request_body, |
| 120 UploadDataStream* request_body, | 118 HttpResponseInfo* response, const CompletionCallback& callback) { |
| 121 HttpResponseInfo* response, | |
| 122 OldCompletionCallback* callback) { | |
| 123 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 119 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 124 CHECK_EQ(stream_info_map_[pipeline_id].state, STREAM_BOUND); | 120 CHECK_EQ(stream_info_map_[pipeline_id].state, STREAM_BOUND); |
| 125 if (!usable_) { | 121 if (!usable_) { |
| 126 return ERR_PIPELINE_EVICTION; | 122 return ERR_PIPELINE_EVICTION; |
| 127 } | 123 } |
| 128 | 124 |
| 129 PendingSendRequest* send_request = new PendingSendRequest; | 125 PendingSendRequest* send_request = new PendingSendRequest; |
| 130 send_request->pipeline_id = pipeline_id; | 126 send_request->pipeline_id = pipeline_id; |
| 131 send_request->request_line = request_line; | 127 send_request->request_line = request_line; |
| 132 send_request->headers = headers; | 128 send_request->headers = headers; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 return OK; | 211 return OK; |
| 216 } | 212 } |
| 217 | 213 |
| 218 int HttpPipelinedConnectionImpl::DoSendActiveRequest(int result) { | 214 int HttpPipelinedConnectionImpl::DoSendActiveRequest(int result) { |
| 219 CHECK(stream_info_map_[active_send_request_->pipeline_id].parser.get()); | 215 CHECK(stream_info_map_[active_send_request_->pipeline_id].parser.get()); |
| 220 int rv = stream_info_map_[active_send_request_->pipeline_id].parser-> | 216 int rv = stream_info_map_[active_send_request_->pipeline_id].parser-> |
| 221 SendRequest(active_send_request_->request_line, | 217 SendRequest(active_send_request_->request_line, |
| 222 active_send_request_->headers, | 218 active_send_request_->headers, |
| 223 active_send_request_->request_body, | 219 active_send_request_->request_body, |
| 224 active_send_request_->response, | 220 active_send_request_->response, |
| 225 &send_io_callback_); | 221 base::Bind(&HttpPipelinedConnectionImpl::OnSendIOCallback, |
| 222 base::Unretained(this))); |
| 226 stream_info_map_[active_send_request_->pipeline_id].state = STREAM_SENDING; | 223 stream_info_map_[active_send_request_->pipeline_id].state = STREAM_SENDING; |
| 227 send_next_state_ = SEND_STATE_COMPLETE; | 224 send_next_state_ = SEND_STATE_COMPLETE; |
| 228 return rv; | 225 return rv; |
| 229 } | 226 } |
| 230 | 227 |
| 231 int HttpPipelinedConnectionImpl::DoSendComplete(int result) { | 228 int HttpPipelinedConnectionImpl::DoSendComplete(int result) { |
| 232 CHECK(active_send_request_.get()); | 229 CHECK(active_send_request_.get()); |
| 233 CHECK_EQ(STREAM_SENDING, | 230 CHECK_EQ(STREAM_SENDING, |
| 234 stream_info_map_[active_send_request_->pipeline_id].state); | 231 stream_info_map_[active_send_request_->pipeline_id].state); |
| 235 | 232 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 262 } | 259 } |
| 263 | 260 |
| 264 return result; | 261 return result; |
| 265 } | 262 } |
| 266 | 263 |
| 267 int HttpPipelinedConnectionImpl::DoEvictPendingSendRequests(int result) { | 264 int HttpPipelinedConnectionImpl::DoEvictPendingSendRequests(int result) { |
| 268 while (!pending_send_request_queue_.empty()) { | 265 while (!pending_send_request_queue_.empty()) { |
| 269 scoped_ptr<PendingSendRequest> evicted_send( | 266 scoped_ptr<PendingSendRequest> evicted_send( |
| 270 pending_send_request_queue_.front()); | 267 pending_send_request_queue_.front()); |
| 271 pending_send_request_queue_.pop(); | 268 pending_send_request_queue_.pop(); |
| 272 if (stream_info_map_[evicted_send->pipeline_id].state != STREAM_CLOSED) { | 269 if (stream_info_map_[evicted_send->pipeline_id].state != STREAM_CLOSED) |
| 273 evicted_send->callback->Run(ERR_PIPELINE_EVICTION); | 270 evicted_send->callback.Run(ERR_PIPELINE_EVICTION); |
| 274 } | |
| 275 } | 271 } |
| 276 send_next_state_ = SEND_STATE_NONE; | 272 send_next_state_ = SEND_STATE_NONE; |
| 277 return result; | 273 return result; |
| 278 } | 274 } |
| 279 | 275 |
| 280 int HttpPipelinedConnectionImpl::ReadResponseHeaders( | 276 int HttpPipelinedConnectionImpl::ReadResponseHeaders( |
| 281 int pipeline_id, | 277 int pipeline_id, const CompletionCallback& callback) { |
| 282 OldCompletionCallback* callback) { | |
| 283 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 278 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 284 CHECK_EQ(STREAM_SENT, stream_info_map_[pipeline_id].state); | 279 CHECK_EQ(STREAM_SENT, stream_info_map_[pipeline_id].state); |
| 285 CHECK(!stream_info_map_[pipeline_id].read_headers_callback); | 280 CHECK(stream_info_map_[pipeline_id].read_headers_callback.is_null()); |
| 286 | 281 |
| 287 if (!usable_) { | 282 if (!usable_) |
| 288 return ERR_PIPELINE_EVICTION; | 283 return ERR_PIPELINE_EVICTION; |
| 289 } | |
| 290 | 284 |
| 291 stream_info_map_[pipeline_id].state = STREAM_READ_PENDING; | 285 stream_info_map_[pipeline_id].state = STREAM_READ_PENDING; |
| 292 stream_info_map_[pipeline_id].read_headers_callback = callback; | 286 stream_info_map_[pipeline_id].read_headers_callback = callback; |
| 293 if (read_next_state_ == READ_STATE_NONE && | 287 if (read_next_state_ == READ_STATE_NONE && |
| 294 pipeline_id == request_order_.front()) { | 288 pipeline_id == request_order_.front()) { |
| 295 read_next_state_ = READ_STATE_START_IMMEDIATELY; | 289 read_next_state_ = READ_STATE_START_IMMEDIATELY; |
| 296 return DoReadHeadersLoop(OK); | 290 return DoReadHeadersLoop(OK); |
| 297 } | 291 } |
| 298 return ERR_IO_PENDING; | 292 return ERR_IO_PENDING; |
| 299 } | 293 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 | 395 |
| 402 return OK; | 396 return OK; |
| 403 } | 397 } |
| 404 | 398 |
| 405 int HttpPipelinedConnectionImpl::DoReadHeaders(int result) { | 399 int HttpPipelinedConnectionImpl::DoReadHeaders(int result) { |
| 406 CHECK(active_read_id_); | 400 CHECK(active_read_id_); |
| 407 CHECK(ContainsKey(stream_info_map_, active_read_id_)); | 401 CHECK(ContainsKey(stream_info_map_, active_read_id_)); |
| 408 CHECK_EQ(STREAM_READ_PENDING, stream_info_map_[active_read_id_].state); | 402 CHECK_EQ(STREAM_READ_PENDING, stream_info_map_[active_read_id_].state); |
| 409 stream_info_map_[active_read_id_].state = STREAM_ACTIVE; | 403 stream_info_map_[active_read_id_].state = STREAM_ACTIVE; |
| 410 int rv = stream_info_map_[active_read_id_].parser->ReadResponseHeaders( | 404 int rv = stream_info_map_[active_read_id_].parser->ReadResponseHeaders( |
| 411 &read_io_callback_); | 405 base::Bind(&HttpPipelinedConnectionImpl::OnReadIOCallback, |
| 406 base::Unretained(this))); |
| 412 read_next_state_ = READ_STATE_READ_HEADERS_COMPLETE; | 407 read_next_state_ = READ_STATE_READ_HEADERS_COMPLETE; |
| 413 return rv; | 408 return rv; |
| 414 } | 409 } |
| 415 | 410 |
| 416 int HttpPipelinedConnectionImpl::DoReadHeadersComplete(int result) { | 411 int HttpPipelinedConnectionImpl::DoReadHeadersComplete(int result) { |
| 417 CHECK(active_read_id_); | 412 CHECK(active_read_id_); |
| 418 CHECK(ContainsKey(stream_info_map_, active_read_id_)); | 413 CHECK(ContainsKey(stream_info_map_, active_read_id_)); |
| 419 CHECK_EQ(STREAM_ACTIVE, stream_info_map_[active_read_id_].state); | 414 CHECK_EQ(STREAM_ACTIVE, stream_info_map_[active_read_id_].state); |
| 420 | 415 |
| 421 read_next_state_ = READ_STATE_WAITING_FOR_CLOSE; | 416 read_next_state_ = READ_STATE_WAITING_FOR_CLOSE; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 448 CHECK_EQ(stream_info_map_[active_read_id_].state, STREAM_CLOSED); | 443 CHECK_EQ(stream_info_map_[active_read_id_].state, STREAM_CLOSED); |
| 449 active_read_id_ = 0; | 444 active_read_id_ = 0; |
| 450 if (!usable_) { | 445 if (!usable_) { |
| 451 // TODO(simonjam): Don't wait this long to evict. | 446 // TODO(simonjam): Don't wait this long to evict. |
| 452 read_next_state_ = READ_STATE_EVICT_PENDING_READS; | 447 read_next_state_ = READ_STATE_EVICT_PENDING_READS; |
| 453 return OK; | 448 return OK; |
| 454 } | 449 } |
| 455 completed_one_request_ = true; | 450 completed_one_request_ = true; |
| 456 MessageLoop::current()->PostTask( | 451 MessageLoop::current()->PostTask( |
| 457 FROM_HERE, | 452 FROM_HERE, |
| 458 method_factory_.NewRunnableMethod( | 453 base::Bind(&HttpPipelinedConnectionImpl::StartNextDeferredRead, |
| 459 &HttpPipelinedConnectionImpl::StartNextDeferredRead)); | 454 weak_factory_.GetWeakPtr())); |
| 460 read_next_state_ = READ_STATE_NONE; | 455 read_next_state_ = READ_STATE_NONE; |
| 461 return OK; | 456 return OK; |
| 462 } | 457 } |
| 463 | 458 |
| 464 int HttpPipelinedConnectionImpl::DoEvictPendingReadHeaders(int result) { | 459 int HttpPipelinedConnectionImpl::DoEvictPendingReadHeaders(int result) { |
| 465 while (!request_order_.empty()) { | 460 while (!request_order_.empty()) { |
| 466 int evicted_id = request_order_.front(); | 461 int evicted_id = request_order_.front(); |
| 467 request_order_.pop(); | 462 request_order_.pop(); |
| 468 if (!ContainsKey(stream_info_map_, evicted_id)) { | 463 if (!ContainsKey(stream_info_map_, evicted_id)) { |
| 469 continue; | 464 continue; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 // TODO(simonjam): Why is Close() sometimes called twice? | 525 // TODO(simonjam): Why is Close() sometimes called twice? |
| 531 break; | 526 break; |
| 532 | 527 |
| 533 default: | 528 default: |
| 534 CHECK(false); | 529 CHECK(false); |
| 535 break; | 530 break; |
| 536 } | 531 } |
| 537 } | 532 } |
| 538 | 533 |
| 539 int HttpPipelinedConnectionImpl::ReadResponseBody( | 534 int HttpPipelinedConnectionImpl::ReadResponseBody( |
| 540 int pipeline_id, | 535 int pipeline_id, IOBuffer* buf, int buf_len, |
| 541 IOBuffer* buf, | 536 const CompletionCallback& callback) { |
| 542 int buf_len, | |
| 543 OldCompletionCallback* callback) { | |
| 544 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 537 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 545 CHECK_EQ(active_read_id_, pipeline_id); | 538 CHECK_EQ(active_read_id_, pipeline_id); |
| 546 CHECK(stream_info_map_[pipeline_id].parser.get()); | 539 CHECK(stream_info_map_[pipeline_id].parser.get()); |
| 547 return stream_info_map_[pipeline_id].parser->ReadResponseBody( | 540 return stream_info_map_[pipeline_id].parser->ReadResponseBody( |
| 548 buf, buf_len, callback); | 541 buf, buf_len, callback); |
| 549 } | 542 } |
| 550 | 543 |
| 551 uint64 HttpPipelinedConnectionImpl::GetUploadProgress(int pipeline_id) const { | 544 uint64 HttpPipelinedConnectionImpl::GetUploadProgress(int pipeline_id) const { |
| 552 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 545 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 553 CHECK(stream_info_map_.find(pipeline_id)->second.parser.get()); | 546 CHECK(stream_info_map_.find(pipeline_id)->second.parser.get()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 | 586 |
| 594 void HttpPipelinedConnectionImpl::SetConnectionReused(int pipeline_id) { | 587 void HttpPipelinedConnectionImpl::SetConnectionReused(int pipeline_id) { |
| 595 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 588 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 596 connection_->set_is_reused(true); | 589 connection_->set_is_reused(true); |
| 597 } | 590 } |
| 598 | 591 |
| 599 void HttpPipelinedConnectionImpl::GetSSLInfo(int pipeline_id, | 592 void HttpPipelinedConnectionImpl::GetSSLInfo(int pipeline_id, |
| 600 SSLInfo* ssl_info) { | 593 SSLInfo* ssl_info) { |
| 601 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 594 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 602 CHECK(stream_info_map_[pipeline_id].parser.get()); | 595 CHECK(stream_info_map_[pipeline_id].parser.get()); |
| 603 return stream_info_map_[pipeline_id].parser->GetSSLInfo(ssl_info); | 596 stream_info_map_[pipeline_id].parser->GetSSLInfo(ssl_info); |
| 604 } | 597 } |
| 605 | 598 |
| 606 void HttpPipelinedConnectionImpl::GetSSLCertRequestInfo( | 599 void HttpPipelinedConnectionImpl::GetSSLCertRequestInfo( |
| 607 int pipeline_id, | 600 int pipeline_id, |
| 608 SSLCertRequestInfo* cert_request_info) { | 601 SSLCertRequestInfo* cert_request_info) { |
| 609 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 602 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 610 CHECK(stream_info_map_[pipeline_id].parser.get()); | 603 CHECK(stream_info_map_[pipeline_id].parser.get()); |
| 611 return stream_info_map_[pipeline_id].parser->GetSSLCertRequestInfo( | 604 stream_info_map_[pipeline_id].parser->GetSSLCertRequestInfo( |
| 612 cert_request_info); | 605 cert_request_info); |
| 613 } | 606 } |
| 614 | 607 |
| 615 void HttpPipelinedConnectionImpl::Drain(HttpPipelinedStream* stream, | 608 void HttpPipelinedConnectionImpl::Drain(HttpPipelinedStream* stream, |
| 616 HttpNetworkSession* session) { | 609 HttpNetworkSession* session) { |
| 617 HttpResponseHeaders* headers = stream->GetResponseInfo()->headers; | 610 HttpResponseHeaders* headers = stream->GetResponseInfo()->headers; |
| 618 if (!stream->CanFindEndOfResponse() || headers->IsChunkEncoded() || | 611 if (!stream->CanFindEndOfResponse() || headers->IsChunkEncoded() || |
| 619 !usable_) { | 612 !usable_) { |
| 620 // TODO(simonjam): Drain chunk-encoded responses if they're relatively | 613 // TODO(simonjam): Drain chunk-encoded responses if they're relatively |
| 621 // common. | 614 // common. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 if (!info->headers->IsKeepAlive() || !CanFindEndOfResponse(pipeline_id)) { | 647 if (!info->headers->IsKeepAlive() || !CanFindEndOfResponse(pipeline_id)) { |
| 655 usable_ = false; | 648 usable_ = false; |
| 656 delegate_->OnPipelineFeedback(this, MUST_CLOSE_CONNECTION); | 649 delegate_->OnPipelineFeedback(this, MUST_CLOSE_CONNECTION); |
| 657 return; | 650 return; |
| 658 } | 651 } |
| 659 // TODO(simonjam): We should also check for, and work around, authentication. | 652 // TODO(simonjam): We should also check for, and work around, authentication. |
| 660 delegate_->OnPipelineFeedback(this, OK); | 653 delegate_->OnPipelineFeedback(this, OK); |
| 661 } | 654 } |
| 662 | 655 |
| 663 void HttpPipelinedConnectionImpl::QueueUserCallback( | 656 void HttpPipelinedConnectionImpl::QueueUserCallback( |
| 664 int pipeline_id, | 657 int pipeline_id, const CompletionCallback& callback, int rv, |
| 665 OldCompletionCallback* callback, | |
| 666 int rv, | |
| 667 const tracked_objects::Location& from_here) { | 658 const tracked_objects::Location& from_here) { |
| 668 CHECK(!stream_info_map_[pipeline_id].pending_user_callback); | 659 CHECK(stream_info_map_[pipeline_id].pending_user_callback.is_null()); |
| 669 stream_info_map_[pipeline_id].pending_user_callback = callback; | 660 stream_info_map_[pipeline_id].pending_user_callback = callback; |
| 670 MessageLoop::current()->PostTask( | 661 MessageLoop::current()->PostTask( |
| 671 from_here, | 662 from_here, |
| 672 method_factory_.NewRunnableMethod( | 663 base::Bind(&HttpPipelinedConnectionImpl::FireUserCallback, |
| 673 &HttpPipelinedConnectionImpl::FireUserCallback, | 664 weak_factory_.GetWeakPtr(), pipeline_id, rv)); |
| 674 pipeline_id, | |
| 675 rv)); | |
| 676 } | 665 } |
| 677 | 666 |
| 678 void HttpPipelinedConnectionImpl::FireUserCallback(int pipeline_id, | 667 void HttpPipelinedConnectionImpl::FireUserCallback(int pipeline_id, |
| 679 int result) { | 668 int result) { |
| 680 if (ContainsKey(stream_info_map_, pipeline_id)) { | 669 if (ContainsKey(stream_info_map_, pipeline_id)) { |
| 681 CHECK(stream_info_map_[pipeline_id].pending_user_callback); | 670 CHECK(!stream_info_map_[pipeline_id].pending_user_callback.is_null()); |
| 682 OldCompletionCallback* callback = | 671 CompletionCallback callback = |
| 683 stream_info_map_[pipeline_id].pending_user_callback; | 672 stream_info_map_[pipeline_id].pending_user_callback; |
| 684 stream_info_map_[pipeline_id].pending_user_callback = NULL; | 673 stream_info_map_[pipeline_id].pending_user_callback.Reset(); |
| 685 callback->Run(result); | 674 callback.Run(result); |
| 686 } | 675 } |
| 687 } | 676 } |
| 688 | 677 |
| 689 int HttpPipelinedConnectionImpl::depth() const { | 678 int HttpPipelinedConnectionImpl::depth() const { |
| 690 return stream_info_map_.size(); | 679 return stream_info_map_.size(); |
| 691 } | 680 } |
| 692 | 681 |
| 693 bool HttpPipelinedConnectionImpl::usable() const { | 682 bool HttpPipelinedConnectionImpl::usable() const { |
| 694 return usable_; | 683 return usable_; |
| 695 } | 684 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 714 return was_npn_negotiated_; | 703 return was_npn_negotiated_; |
| 715 } | 704 } |
| 716 | 705 |
| 717 HttpPipelinedConnectionImpl::PendingSendRequest::PendingSendRequest() { | 706 HttpPipelinedConnectionImpl::PendingSendRequest::PendingSendRequest() { |
| 718 } | 707 } |
| 719 | 708 |
| 720 HttpPipelinedConnectionImpl::PendingSendRequest::~PendingSendRequest() { | 709 HttpPipelinedConnectionImpl::PendingSendRequest::~PendingSendRequest() { |
| 721 } | 710 } |
| 722 | 711 |
| 723 HttpPipelinedConnectionImpl::StreamInfo::StreamInfo() | 712 HttpPipelinedConnectionImpl::StreamInfo::StreamInfo() |
| 724 : read_headers_callback(NULL), | 713 : state(STREAM_CREATED) { |
| 725 pending_user_callback(NULL), | |
| 726 state(STREAM_CREATED) { | |
| 727 } | 714 } |
| 728 | 715 |
| 729 HttpPipelinedConnectionImpl::StreamInfo::~StreamInfo() { | 716 HttpPipelinedConnectionImpl::StreamInfo::~StreamInfo() { |
| 730 } | 717 } |
| 731 | 718 |
| 732 } // namespace net | 719 } // namespace net |
| OLD | NEW |