| 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/http/http_pipelined_connection_impl.h" | 5 #include "net/http/http_pipelined_connection_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 HttpPipelinedConnection* | 52 HttpPipelinedConnection* |
| 53 HttpPipelinedConnectionImpl::Factory::CreateNewPipeline( | 53 HttpPipelinedConnectionImpl::Factory::CreateNewPipeline( |
| 54 ClientSocketHandle* connection, | 54 ClientSocketHandle* connection, |
| 55 HttpPipelinedConnection::Delegate* delegate, | 55 HttpPipelinedConnection::Delegate* delegate, |
| 56 const HostPortPair& origin, | 56 const HostPortPair& origin, |
| 57 const SSLConfig& used_ssl_config, | 57 const SSLConfig& used_ssl_config, |
| 58 const ProxyInfo& used_proxy_info, | 58 const ProxyInfo& used_proxy_info, |
| 59 const BoundNetLog& net_log, | 59 const BoundNetLog& net_log, |
| 60 bool was_npn_negotiated, | 60 bool was_npn_negotiated, |
| 61 NextProto protocol_negotiated) { | 61 NextProto protocol_negotiated) { |
| 62 return new HttpPipelinedConnectionImpl(connection, delegate, origin, | 62 return new HttpPipelinedConnectionImpl(connection, |
| 63 used_ssl_config, used_proxy_info, | 63 delegate, |
| 64 net_log, was_npn_negotiated, | 64 origin, |
| 65 used_ssl_config, |
| 66 used_proxy_info, |
| 67 net_log, |
| 68 was_npn_negotiated, |
| 65 protocol_negotiated); | 69 protocol_negotiated); |
| 66 } | 70 } |
| 67 | 71 |
| 68 HttpPipelinedConnectionImpl::HttpPipelinedConnectionImpl( | 72 HttpPipelinedConnectionImpl::HttpPipelinedConnectionImpl( |
| 69 ClientSocketHandle* connection, | 73 ClientSocketHandle* connection, |
| 70 HttpPipelinedConnection::Delegate* delegate, | 74 HttpPipelinedConnection::Delegate* delegate, |
| 71 const HostPortPair& origin, | 75 const HostPortPair& origin, |
| 72 const SSLConfig& used_ssl_config, | 76 const SSLConfig& used_ssl_config, |
| 73 const ProxyInfo& used_proxy_info, | 77 const ProxyInfo& used_proxy_info, |
| 74 const BoundNetLog& net_log, | 78 const BoundNetLog& net_log, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 87 active_(false), | 91 active_(false), |
| 88 usable_(true), | 92 usable_(true), |
| 89 completed_one_request_(false), | 93 completed_one_request_(false), |
| 90 weak_factory_(this), | 94 weak_factory_(this), |
| 91 send_next_state_(SEND_STATE_NONE), | 95 send_next_state_(SEND_STATE_NONE), |
| 92 send_still_on_call_stack_(false), | 96 send_still_on_call_stack_(false), |
| 93 read_next_state_(READ_STATE_NONE), | 97 read_next_state_(READ_STATE_NONE), |
| 94 active_read_id_(0), | 98 active_read_id_(0), |
| 95 read_still_on_call_stack_(false) { | 99 read_still_on_call_stack_(false) { |
| 96 CHECK(connection_.get()); | 100 CHECK(connection_.get()); |
| 97 net_log_.BeginEvent( | 101 net_log_.BeginEvent(NetLog::TYPE_HTTP_PIPELINED_CONNECTION, |
| 98 NetLog::TYPE_HTTP_PIPELINED_CONNECTION, | 102 base::Bind(&NetLogHostPortPairCallback, &origin)); |
| 99 base::Bind(&NetLogHostPortPairCallback, &origin)); | |
| 100 } | 103 } |
| 101 | 104 |
| 102 HttpPipelinedConnectionImpl::~HttpPipelinedConnectionImpl() { | 105 HttpPipelinedConnectionImpl::~HttpPipelinedConnectionImpl() { |
| 103 CHECK_EQ(depth(), 0); | 106 CHECK_EQ(depth(), 0); |
| 104 CHECK(stream_info_map_.empty()); | 107 CHECK(stream_info_map_.empty()); |
| 105 CHECK(pending_send_request_queue_.empty()); | 108 CHECK(pending_send_request_queue_.empty()); |
| 106 CHECK(request_order_.empty()); | 109 CHECK(request_order_.empty()); |
| 107 CHECK_EQ(send_next_state_, SEND_STATE_NONE); | 110 CHECK_EQ(send_next_state_, SEND_STATE_NONE); |
| 108 CHECK_EQ(read_next_state_, READ_STATE_NONE); | 111 CHECK_EQ(read_next_state_, READ_STATE_NONE); |
| 109 CHECK(!active_send_request_.get()); | 112 CHECK(!active_send_request_.get()); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 return OK; | 265 return OK; |
| 263 } | 266 } |
| 264 } | 267 } |
| 265 | 268 |
| 266 send_next_state_ = SEND_STATE_NONE; | 269 send_next_state_ = SEND_STATE_NONE; |
| 267 return OK; | 270 return OK; |
| 268 } | 271 } |
| 269 | 272 |
| 270 int HttpPipelinedConnectionImpl::DoSendActiveRequest(int result) { | 273 int HttpPipelinedConnectionImpl::DoSendActiveRequest(int result) { |
| 271 CHECK(stream_info_map_[active_send_request_->pipeline_id].parser.get()); | 274 CHECK(stream_info_map_[active_send_request_->pipeline_id].parser.get()); |
| 272 int rv = stream_info_map_[active_send_request_->pipeline_id].parser-> | 275 int rv = |
| 273 SendRequest(active_send_request_->request_line, | 276 stream_info_map_[active_send_request_->pipeline_id].parser->SendRequest( |
| 274 active_send_request_->headers, | 277 active_send_request_->request_line, |
| 275 active_send_request_->response, | 278 active_send_request_->headers, |
| 276 base::Bind(&HttpPipelinedConnectionImpl::OnSendIOCallback, | 279 active_send_request_->response, |
| 277 base::Unretained(this))); | 280 base::Bind(&HttpPipelinedConnectionImpl::OnSendIOCallback, |
| 281 base::Unretained(this))); |
| 278 stream_info_map_[active_send_request_->pipeline_id].state = STREAM_SENDING; | 282 stream_info_map_[active_send_request_->pipeline_id].state = STREAM_SENDING; |
| 279 send_next_state_ = SEND_STATE_COMPLETE; | 283 send_next_state_ = SEND_STATE_COMPLETE; |
| 280 return rv; | 284 return rv; |
| 281 } | 285 } |
| 282 | 286 |
| 283 int HttpPipelinedConnectionImpl::DoSendComplete(int result) { | 287 int HttpPipelinedConnectionImpl::DoSendComplete(int result) { |
| 284 CHECK(active_send_request_.get()); | 288 CHECK(active_send_request_.get()); |
| 285 CHECK_EQ(STREAM_SENDING, | 289 CHECK_EQ(STREAM_SENDING, |
| 286 stream_info_map_[active_send_request_->pipeline_id].state); | 290 stream_info_map_[active_send_request_->pipeline_id].state); |
| 287 | 291 |
| 288 request_order_.push(active_send_request_->pipeline_id); | 292 request_order_.push(active_send_request_->pipeline_id); |
| 289 stream_info_map_[active_send_request_->pipeline_id].state = STREAM_SENT; | 293 stream_info_map_[active_send_request_->pipeline_id].state = STREAM_SENT; |
| 290 net_log_.AddEvent( | 294 net_log_.AddEvent(NetLog::TYPE_HTTP_PIPELINED_CONNECTION_SENT_REQUEST, |
| 291 NetLog::TYPE_HTTP_PIPELINED_CONNECTION_SENT_REQUEST, | 295 stream_info_map_[active_send_request_->pipeline_id] |
| 292 stream_info_map_[active_send_request_->pipeline_id].source. | 296 .source.ToEventParametersCallback()); |
| 293 ToEventParametersCallback()); | |
| 294 | 297 |
| 295 if (result == ERR_SOCKET_NOT_CONNECTED && completed_one_request_) { | 298 if (result == ERR_SOCKET_NOT_CONNECTED && completed_one_request_) { |
| 296 result = ERR_PIPELINE_EVICTION; | 299 result = ERR_PIPELINE_EVICTION; |
| 297 } | 300 } |
| 298 if (result < OK) { | 301 if (result < OK) { |
| 299 usable_ = false; | 302 usable_ = false; |
| 300 } | 303 } |
| 301 | 304 |
| 302 if (!send_still_on_call_stack_) { | 305 if (!send_still_on_call_stack_) { |
| 303 QueueUserCallback(active_send_request_->pipeline_id, | 306 QueueUserCallback(active_send_request_->pipeline_id, |
| 304 active_send_request_->callback, result, FROM_HERE); | 307 active_send_request_->callback, |
| 308 result, |
| 309 FROM_HERE); |
| 305 } | 310 } |
| 306 | 311 |
| 307 active_send_request_.reset(); | 312 active_send_request_.reset(); |
| 308 | 313 |
| 309 if (send_still_on_call_stack_) { | 314 if (send_still_on_call_stack_) { |
| 310 // It should be impossible for another request to appear on the queue while | 315 // It should be impossible for another request to appear on the queue while |
| 311 // this send was on the call stack. | 316 // this send was on the call stack. |
| 312 CHECK(pending_send_request_queue_.empty()); | 317 CHECK(pending_send_request_queue_.empty()); |
| 313 send_next_state_ = SEND_STATE_NONE; | 318 send_next_state_ = SEND_STATE_NONE; |
| 314 } else if (!usable_) { | 319 } else if (!usable_) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 328 if (ContainsKey(stream_info_map_, evicted_send->pipeline_id) && | 333 if (ContainsKey(stream_info_map_, evicted_send->pipeline_id) && |
| 329 stream_info_map_[evicted_send->pipeline_id].state != STREAM_CLOSED) { | 334 stream_info_map_[evicted_send->pipeline_id].state != STREAM_CLOSED) { |
| 330 evicted_send->callback.Run(ERR_PIPELINE_EVICTION); | 335 evicted_send->callback.Run(ERR_PIPELINE_EVICTION); |
| 331 } | 336 } |
| 332 } | 337 } |
| 333 send_next_state_ = SEND_STATE_NONE; | 338 send_next_state_ = SEND_STATE_NONE; |
| 334 return result; | 339 return result; |
| 335 } | 340 } |
| 336 | 341 |
| 337 int HttpPipelinedConnectionImpl::ReadResponseHeaders( | 342 int HttpPipelinedConnectionImpl::ReadResponseHeaders( |
| 338 int pipeline_id, const CompletionCallback& callback) { | 343 int pipeline_id, |
| 344 const CompletionCallback& callback) { |
| 339 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 345 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 340 CHECK_EQ(STREAM_SENT, stream_info_map_[pipeline_id].state); | 346 CHECK_EQ(STREAM_SENT, stream_info_map_[pipeline_id].state); |
| 341 CHECK(stream_info_map_[pipeline_id].read_headers_callback.is_null()); | 347 CHECK(stream_info_map_[pipeline_id].read_headers_callback.is_null()); |
| 342 | 348 |
| 343 if (!usable_) | 349 if (!usable_) |
| 344 return ERR_PIPELINE_EVICTION; | 350 return ERR_PIPELINE_EVICTION; |
| 345 | 351 |
| 346 stream_info_map_[pipeline_id].state = STREAM_READ_PENDING; | 352 stream_info_map_[pipeline_id].state = STREAM_READ_PENDING; |
| 347 stream_info_map_[pipeline_id].read_headers_callback = callback; | 353 stream_info_map_[pipeline_id].read_headers_callback = callback; |
| 348 if (read_next_state_ == READ_STATE_NONE && | 354 if (read_next_state_ == READ_STATE_NONE && |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 } | 476 } |
| 471 | 477 |
| 472 int HttpPipelinedConnectionImpl::DoReadHeadersComplete(int result) { | 478 int HttpPipelinedConnectionImpl::DoReadHeadersComplete(int result) { |
| 473 CHECK(active_read_id_); | 479 CHECK(active_read_id_); |
| 474 CHECK(ContainsKey(stream_info_map_, active_read_id_)); | 480 CHECK(ContainsKey(stream_info_map_, active_read_id_)); |
| 475 CHECK_EQ(STREAM_ACTIVE, stream_info_map_[active_read_id_].state); | 481 CHECK_EQ(STREAM_ACTIVE, stream_info_map_[active_read_id_].state); |
| 476 | 482 |
| 477 read_next_state_ = READ_STATE_WAITING_FOR_CLOSE; | 483 read_next_state_ = READ_STATE_WAITING_FOR_CLOSE; |
| 478 if (result < OK) { | 484 if (result < OK) { |
| 479 if (completed_one_request_ && | 485 if (completed_one_request_ && |
| 480 (result == ERR_CONNECTION_CLOSED || | 486 (result == ERR_CONNECTION_CLOSED || result == ERR_EMPTY_RESPONSE || |
| 481 result == ERR_EMPTY_RESPONSE || | |
| 482 result == ERR_SOCKET_NOT_CONNECTED)) { | 487 result == ERR_SOCKET_NOT_CONNECTED)) { |
| 483 // These usually indicate that pipelining failed on the server side. In | 488 // These usually indicate that pipelining failed on the server side. In |
| 484 // that case, we should retry without pipelining. | 489 // that case, we should retry without pipelining. |
| 485 result = ERR_PIPELINE_EVICTION; | 490 result = ERR_PIPELINE_EVICTION; |
| 486 } | 491 } |
| 487 usable_ = false; | 492 usable_ = false; |
| 488 } | 493 } |
| 489 | 494 |
| 490 CheckHeadersForPipelineCompatibility(active_read_id_, result); | 495 CheckHeadersForPipelineCompatibility(active_read_id_, result); |
| 491 | 496 |
| 492 if (!read_still_on_call_stack_) { | 497 if (!read_still_on_call_stack_) { |
| 493 QueueUserCallback(active_read_id_, | 498 QueueUserCallback(active_read_id_, |
| 494 stream_info_map_[active_read_id_].read_headers_callback, | 499 stream_info_map_[active_read_id_].read_headers_callback, |
| 495 result, FROM_HERE); | 500 result, |
| 501 FROM_HERE); |
| 496 } | 502 } |
| 497 | 503 |
| 498 return result; | 504 return result; |
| 499 } | 505 } |
| 500 | 506 |
| 501 int HttpPipelinedConnectionImpl::DoReadWaitForClose(int result) { | 507 int HttpPipelinedConnectionImpl::DoReadWaitForClose(int result) { |
| 502 read_next_state_ = READ_STATE_WAITING_FOR_CLOSE; | 508 read_next_state_ = READ_STATE_WAITING_FOR_CLOSE; |
| 503 return result; | 509 return result; |
| 504 } | 510 } |
| 505 | 511 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 532 if (stream_info_map_[evicted_id].state == STREAM_READ_PENDING) { | 538 if (stream_info_map_[evicted_id].state == STREAM_READ_PENDING) { |
| 533 stream_info_map_[evicted_id].state = STREAM_READ_EVICTED; | 539 stream_info_map_[evicted_id].state = STREAM_READ_EVICTED; |
| 534 stream_info_map_[evicted_id].read_headers_callback.Run( | 540 stream_info_map_[evicted_id].read_headers_callback.Run( |
| 535 ERR_PIPELINE_EVICTION); | 541 ERR_PIPELINE_EVICTION); |
| 536 } | 542 } |
| 537 } | 543 } |
| 538 read_next_state_ = READ_STATE_NONE; | 544 read_next_state_ = READ_STATE_NONE; |
| 539 return result; | 545 return result; |
| 540 } | 546 } |
| 541 | 547 |
| 542 void HttpPipelinedConnectionImpl::Close(int pipeline_id, | 548 void HttpPipelinedConnectionImpl::Close(int pipeline_id, bool not_reusable) { |
| 543 bool not_reusable) { | |
| 544 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 549 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 545 net_log_.AddEvent( | 550 net_log_.AddEvent(NetLog::TYPE_HTTP_PIPELINED_CONNECTION_STREAM_CLOSED, |
| 546 NetLog::TYPE_HTTP_PIPELINED_CONNECTION_STREAM_CLOSED, | 551 base::Bind(&NetLogStreamClosedCallback, |
| 547 base::Bind(&NetLogStreamClosedCallback, | 552 stream_info_map_[pipeline_id].source, |
| 548 stream_info_map_[pipeline_id].source, not_reusable)); | 553 not_reusable)); |
| 549 switch (stream_info_map_[pipeline_id].state) { | 554 switch (stream_info_map_[pipeline_id].state) { |
| 550 case STREAM_CREATED: | 555 case STREAM_CREATED: |
| 551 stream_info_map_[pipeline_id].state = STREAM_UNUSED; | 556 stream_info_map_[pipeline_id].state = STREAM_UNUSED; |
| 552 break; | 557 break; |
| 553 | 558 |
| 554 case STREAM_BOUND: | 559 case STREAM_BOUND: |
| 555 stream_info_map_[pipeline_id].state = STREAM_CLOSED; | 560 stream_info_map_[pipeline_id].state = STREAM_CLOSED; |
| 556 break; | 561 break; |
| 557 | 562 |
| 558 case STREAM_SENDING: | 563 case STREAM_SENDING: |
| 559 usable_ = false; | 564 usable_ = false; |
| 560 stream_info_map_[pipeline_id].state = STREAM_CLOSED; | 565 stream_info_map_[pipeline_id].state = STREAM_CLOSED; |
| 561 active_send_request_.reset(); | 566 active_send_request_.reset(); |
| 562 send_next_state_ = SEND_STATE_EVICT_PENDING_REQUESTS; | 567 send_next_state_ = SEND_STATE_EVICT_PENDING_REQUESTS; |
| 563 DoSendRequestLoop(OK); | 568 DoSendRequestLoop(OK); |
| 564 break; | 569 break; |
| 565 | 570 |
| 566 case STREAM_SENT: | 571 case STREAM_SENT: |
| 567 case STREAM_READ_PENDING: | 572 case STREAM_READ_PENDING: |
| 568 usable_ = false; | 573 usable_ = false; |
| 569 stream_info_map_[pipeline_id].state = STREAM_CLOSED; | 574 stream_info_map_[pipeline_id].state = STREAM_CLOSED; |
| 570 if (!request_order_.empty() && | 575 if (!request_order_.empty() && pipeline_id == request_order_.front() && |
| 571 pipeline_id == request_order_.front() && | |
| 572 read_next_state_ == READ_STATE_NONE) { | 576 read_next_state_ == READ_STATE_NONE) { |
| 573 read_next_state_ = READ_STATE_EVICT_PENDING_READS; | 577 read_next_state_ = READ_STATE_EVICT_PENDING_READS; |
| 574 DoReadHeadersLoop(OK); | 578 DoReadHeadersLoop(OK); |
| 575 } | 579 } |
| 576 break; | 580 break; |
| 577 | 581 |
| 578 case STREAM_ACTIVE: | 582 case STREAM_ACTIVE: |
| 579 stream_info_map_[pipeline_id].state = STREAM_CLOSED; | 583 stream_info_map_[pipeline_id].state = STREAM_CLOSED; |
| 580 if (not_reusable) { | 584 if (not_reusable) { |
| 581 usable_ = false; | 585 usable_ = false; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 593 // TODO(simonjam): Why is Close() sometimes called twice? | 597 // TODO(simonjam): Why is Close() sometimes called twice? |
| 594 break; | 598 break; |
| 595 | 599 |
| 596 default: | 600 default: |
| 597 CHECK(false); | 601 CHECK(false); |
| 598 break; | 602 break; |
| 599 } | 603 } |
| 600 } | 604 } |
| 601 | 605 |
| 602 int HttpPipelinedConnectionImpl::ReadResponseBody( | 606 int HttpPipelinedConnectionImpl::ReadResponseBody( |
| 603 int pipeline_id, IOBuffer* buf, int buf_len, | 607 int pipeline_id, |
| 608 IOBuffer* buf, |
| 609 int buf_len, |
| 604 const CompletionCallback& callback) { | 610 const CompletionCallback& callback) { |
| 605 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 611 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 606 CHECK_EQ(active_read_id_, pipeline_id); | 612 CHECK_EQ(active_read_id_, pipeline_id); |
| 607 CHECK(stream_info_map_[pipeline_id].parser.get()); | 613 CHECK(stream_info_map_[pipeline_id].parser.get()); |
| 608 return stream_info_map_[pipeline_id].parser->ReadResponseBody( | 614 return stream_info_map_[pipeline_id].parser->ReadResponseBody( |
| 609 buf, buf_len, callback); | 615 buf, buf_len, callback); |
| 610 } | 616 } |
| 611 | 617 |
| 612 UploadProgress HttpPipelinedConnectionImpl::GetUploadProgress( | 618 UploadProgress HttpPipelinedConnectionImpl::GetUploadProgress( |
| 613 int pipeline_id) const { | 619 int pipeline_id) const { |
| 614 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 620 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 615 CHECK(stream_info_map_.find(pipeline_id)->second.parser.get()); | 621 CHECK(stream_info_map_.find(pipeline_id)->second.parser.get()); |
| 616 return stream_info_map_.find(pipeline_id)->second.parser->GetUploadProgress(); | 622 return stream_info_map_.find(pipeline_id)->second.parser->GetUploadProgress(); |
| 617 } | 623 } |
| 618 | 624 |
| 619 HttpResponseInfo* HttpPipelinedConnectionImpl::GetResponseInfo( | 625 HttpResponseInfo* HttpPipelinedConnectionImpl::GetResponseInfo( |
| 620 int pipeline_id) { | 626 int pipeline_id) { |
| 621 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 627 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 622 CHECK(stream_info_map_.find(pipeline_id)->second.parser.get()); | 628 CHECK(stream_info_map_.find(pipeline_id)->second.parser.get()); |
| 623 return stream_info_map_.find(pipeline_id)->second.parser->GetResponseInfo(); | 629 return stream_info_map_.find(pipeline_id)->second.parser->GetResponseInfo(); |
| 624 } | 630 } |
| 625 | 631 |
| 626 bool HttpPipelinedConnectionImpl::IsResponseBodyComplete( | 632 bool HttpPipelinedConnectionImpl::IsResponseBodyComplete( |
| 627 int pipeline_id) const { | 633 int pipeline_id) const { |
| 628 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 634 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 629 CHECK(stream_info_map_.find(pipeline_id)->second.parser.get()); | 635 CHECK(stream_info_map_.find(pipeline_id)->second.parser.get()); |
| 630 return stream_info_map_.find(pipeline_id)->second.parser-> | 636 return stream_info_map_.find(pipeline_id) |
| 631 IsResponseBodyComplete(); | 637 ->second.parser->IsResponseBodyComplete(); |
| 632 } | 638 } |
| 633 | 639 |
| 634 bool HttpPipelinedConnectionImpl::CanFindEndOfResponse(int pipeline_id) const { | 640 bool HttpPipelinedConnectionImpl::CanFindEndOfResponse(int pipeline_id) const { |
| 635 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 641 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 636 CHECK(stream_info_map_.find(pipeline_id)->second.parser.get()); | 642 CHECK(stream_info_map_.find(pipeline_id)->second.parser.get()); |
| 637 return stream_info_map_.find(pipeline_id)->second.parser-> | 643 return stream_info_map_.find(pipeline_id) |
| 638 CanFindEndOfResponse(); | 644 ->second.parser->CanFindEndOfResponse(); |
| 639 } | 645 } |
| 640 | 646 |
| 641 bool HttpPipelinedConnectionImpl::IsConnectionReused(int pipeline_id) const { | 647 bool HttpPipelinedConnectionImpl::IsConnectionReused(int pipeline_id) const { |
| 642 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 648 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 643 if (pipeline_id > 1) { | 649 if (pipeline_id > 1) { |
| 644 return true; | 650 return true; |
| 645 } | 651 } |
| 646 ClientSocketHandle::SocketReuseType reuse_type = connection_->reuse_type(); | 652 ClientSocketHandle::SocketReuseType reuse_type = connection_->reuse_type(); |
| 647 return connection_->is_reused() || | 653 return connection_->is_reused() || |
| 648 reuse_type == ClientSocketHandle::UNUSED_IDLE; | 654 reuse_type == ClientSocketHandle::UNUSED_IDLE; |
| 649 } | 655 } |
| 650 | 656 |
| 651 void HttpPipelinedConnectionImpl::SetConnectionReused(int pipeline_id) { | 657 void HttpPipelinedConnectionImpl::SetConnectionReused(int pipeline_id) { |
| 652 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 658 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 653 connection_->set_reuse_type(ClientSocketHandle::REUSED_IDLE); | 659 connection_->set_reuse_type(ClientSocketHandle::REUSED_IDLE); |
| 654 } | 660 } |
| 655 | 661 |
| 656 int64 HttpPipelinedConnectionImpl::GetTotalReceivedBytes( | 662 int64 HttpPipelinedConnectionImpl::GetTotalReceivedBytes( |
| 657 int pipeline_id) const { | 663 int pipeline_id) const { |
| 658 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 664 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 659 if (stream_info_map_.find(pipeline_id)->second.parser.get()) | 665 if (stream_info_map_.find(pipeline_id)->second.parser.get()) |
| 660 return stream_info_map_.find(pipeline_id)->second.parser->received_bytes(); | 666 return stream_info_map_.find(pipeline_id)->second.parser->received_bytes(); |
| 661 return 0; | 667 return 0; |
| 662 } | 668 } |
| 663 | 669 |
| 664 bool HttpPipelinedConnectionImpl::GetLoadTimingInfo( | 670 bool HttpPipelinedConnectionImpl::GetLoadTimingInfo( |
| 665 int pipeline_id, LoadTimingInfo* load_timing_info) const { | 671 int pipeline_id, |
| 672 LoadTimingInfo* load_timing_info) const { |
| 666 return connection_->GetLoadTimingInfo(IsConnectionReused(pipeline_id), | 673 return connection_->GetLoadTimingInfo(IsConnectionReused(pipeline_id), |
| 667 load_timing_info); | 674 load_timing_info); |
| 668 } | 675 } |
| 669 | 676 |
| 670 void HttpPipelinedConnectionImpl::GetSSLInfo(int pipeline_id, | 677 void HttpPipelinedConnectionImpl::GetSSLInfo(int pipeline_id, |
| 671 SSLInfo* ssl_info) { | 678 SSLInfo* ssl_info) { |
| 672 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 679 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 673 CHECK(stream_info_map_[pipeline_id].parser.get()); | 680 CHECK(stream_info_map_[pipeline_id].parser.get()); |
| 674 stream_info_map_[pipeline_id].parser->GetSSLInfo(ssl_info); | 681 stream_info_map_[pipeline_id].parser->GetSSLInfo(ssl_info); |
| 675 } | 682 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 if (info->headers->GetParsedHttpVersion() < required_version) { | 730 if (info->headers->GetParsedHttpVersion() < required_version) { |
| 724 ReportPipelineFeedback(pipeline_id, OLD_HTTP_VERSION); | 731 ReportPipelineFeedback(pipeline_id, OLD_HTTP_VERSION); |
| 725 return; | 732 return; |
| 726 } | 733 } |
| 727 if (!info->headers->IsKeepAlive() || !CanFindEndOfResponse(pipeline_id)) { | 734 if (!info->headers->IsKeepAlive() || !CanFindEndOfResponse(pipeline_id)) { |
| 728 usable_ = false; | 735 usable_ = false; |
| 729 ReportPipelineFeedback(pipeline_id, MUST_CLOSE_CONNECTION); | 736 ReportPipelineFeedback(pipeline_id, MUST_CLOSE_CONNECTION); |
| 730 return; | 737 return; |
| 731 } | 738 } |
| 732 if (info->headers->HasHeader( | 739 if (info->headers->HasHeader( |
| 733 HttpAuth::GetChallengeHeaderName(HttpAuth::AUTH_SERVER))) { | 740 HttpAuth::GetChallengeHeaderName(HttpAuth::AUTH_SERVER))) { |
| 734 ReportPipelineFeedback(pipeline_id, AUTHENTICATION_REQUIRED); | 741 ReportPipelineFeedback(pipeline_id, AUTHENTICATION_REQUIRED); |
| 735 return; | 742 return; |
| 736 } | 743 } |
| 737 ReportPipelineFeedback(pipeline_id, OK); | 744 ReportPipelineFeedback(pipeline_id, OK); |
| 738 } | 745 } |
| 739 | 746 |
| 740 void HttpPipelinedConnectionImpl::ReportPipelineFeedback(int pipeline_id, | 747 void HttpPipelinedConnectionImpl::ReportPipelineFeedback(int pipeline_id, |
| 741 Feedback feedback) { | 748 Feedback feedback) { |
| 742 std::string feedback_str; | 749 std::string feedback_str; |
| 743 switch (feedback) { | 750 switch (feedback) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 759 | 766 |
| 760 case AUTHENTICATION_REQUIRED: | 767 case AUTHENTICATION_REQUIRED: |
| 761 feedback_str = "AUTHENTICATION_REQUIRED"; | 768 feedback_str = "AUTHENTICATION_REQUIRED"; |
| 762 break; | 769 break; |
| 763 | 770 |
| 764 default: | 771 default: |
| 765 NOTREACHED(); | 772 NOTREACHED(); |
| 766 feedback_str = "UNKNOWN"; | 773 feedback_str = "UNKNOWN"; |
| 767 break; | 774 break; |
| 768 } | 775 } |
| 769 net_log_.AddEvent( | 776 net_log_.AddEvent(NetLog::TYPE_HTTP_PIPELINED_CONNECTION_RECEIVED_HEADERS, |
| 770 NetLog::TYPE_HTTP_PIPELINED_CONNECTION_RECEIVED_HEADERS, | 777 base::Bind(&NetLogReceivedHeadersCallback, |
| 771 base::Bind(&NetLogReceivedHeadersCallback, | 778 stream_info_map_[pipeline_id].source, |
| 772 stream_info_map_[pipeline_id].source, &feedback_str)); | 779 &feedback_str)); |
| 773 delegate_->OnPipelineFeedback(this, feedback); | 780 delegate_->OnPipelineFeedback(this, feedback); |
| 774 } | 781 } |
| 775 | 782 |
| 776 void HttpPipelinedConnectionImpl::QueueUserCallback( | 783 void HttpPipelinedConnectionImpl::QueueUserCallback( |
| 777 int pipeline_id, const CompletionCallback& callback, int rv, | 784 int pipeline_id, |
| 785 const CompletionCallback& callback, |
| 786 int rv, |
| 778 const tracked_objects::Location& from_here) { | 787 const tracked_objects::Location& from_here) { |
| 779 CHECK(stream_info_map_[pipeline_id].pending_user_callback.is_null()); | 788 CHECK(stream_info_map_[pipeline_id].pending_user_callback.is_null()); |
| 780 stream_info_map_[pipeline_id].pending_user_callback = callback; | 789 stream_info_map_[pipeline_id].pending_user_callback = callback; |
| 781 base::MessageLoop::current()->PostTask( | 790 base::MessageLoop::current()->PostTask( |
| 782 from_here, | 791 from_here, |
| 783 base::Bind(&HttpPipelinedConnectionImpl::FireUserCallback, | 792 base::Bind(&HttpPipelinedConnectionImpl::FireUserCallback, |
| 784 weak_factory_.GetWeakPtr(), pipeline_id, rv)); | 793 weak_factory_.GetWeakPtr(), |
| 794 pipeline_id, |
| 795 rv)); |
| 785 } | 796 } |
| 786 | 797 |
| 787 void HttpPipelinedConnectionImpl::FireUserCallback(int pipeline_id, | 798 void HttpPipelinedConnectionImpl::FireUserCallback(int pipeline_id, |
| 788 int result) { | 799 int result) { |
| 789 if (ContainsKey(stream_info_map_, pipeline_id)) { | 800 if (ContainsKey(stream_info_map_, pipeline_id)) { |
| 790 CHECK(!stream_info_map_[pipeline_id].pending_user_callback.is_null()); | 801 CHECK(!stream_info_map_[pipeline_id].pending_user_callback.is_null()); |
| 791 CompletionCallback callback = | 802 CompletionCallback callback = |
| 792 stream_info_map_[pipeline_id].pending_user_callback; | 803 stream_info_map_[pipeline_id].pending_user_callback; |
| 793 stream_info_map_[pipeline_id].pending_user_callback.Reset(); | 804 stream_info_map_[pipeline_id].pending_user_callback.Reset(); |
| 794 callback.Run(result); | 805 callback.Run(result); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 816 } | 827 } |
| 817 | 828 |
| 818 const BoundNetLog& HttpPipelinedConnectionImpl::net_log() const { | 829 const BoundNetLog& HttpPipelinedConnectionImpl::net_log() const { |
| 819 return net_log_; | 830 return net_log_; |
| 820 } | 831 } |
| 821 | 832 |
| 822 bool HttpPipelinedConnectionImpl::was_npn_negotiated() const { | 833 bool HttpPipelinedConnectionImpl::was_npn_negotiated() const { |
| 823 return was_npn_negotiated_; | 834 return was_npn_negotiated_; |
| 824 } | 835 } |
| 825 | 836 |
| 826 NextProto HttpPipelinedConnectionImpl::protocol_negotiated() | 837 NextProto HttpPipelinedConnectionImpl::protocol_negotiated() const { |
| 827 const { | |
| 828 return protocol_negotiated_; | 838 return protocol_negotiated_; |
| 829 } | 839 } |
| 830 | 840 |
| 831 HttpPipelinedConnectionImpl::PendingSendRequest::PendingSendRequest() | 841 HttpPipelinedConnectionImpl::PendingSendRequest::PendingSendRequest() |
| 832 : pipeline_id(0), | 842 : pipeline_id(0), response(NULL) { |
| 833 response(NULL) { | |
| 834 } | 843 } |
| 835 | 844 |
| 836 HttpPipelinedConnectionImpl::PendingSendRequest::~PendingSendRequest() { | 845 HttpPipelinedConnectionImpl::PendingSendRequest::~PendingSendRequest() { |
| 837 } | 846 } |
| 838 | 847 |
| 839 HttpPipelinedConnectionImpl::StreamInfo::StreamInfo() | 848 HttpPipelinedConnectionImpl::StreamInfo::StreamInfo() : state(STREAM_CREATED) { |
| 840 : state(STREAM_CREATED) { | |
| 841 } | 849 } |
| 842 | 850 |
| 843 HttpPipelinedConnectionImpl::StreamInfo::~StreamInfo() { | 851 HttpPipelinedConnectionImpl::StreamInfo::~StreamInfo() { |
| 844 } | 852 } |
| 845 | 853 |
| 846 } // namespace net | 854 } // namespace net |
| OLD | NEW |