| 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.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
| 13 #include "net/http/http_pipelined_stream.h" | 13 #include "net/http/http_pipelined_stream.h" |
| 14 #include "net/http/http_request_info.h" | 14 #include "net/http/http_request_info.h" |
| 15 #include "net/http/http_response_body_drainer.h" | 15 #include "net/http/http_response_body_drainer.h" |
| 16 #include "net/http/http_response_headers.h" | 16 #include "net/http/http_response_headers.h" |
| 17 #include "net/http/http_stream_parser.h" | 17 #include "net/http/http_stream_parser.h" |
| 18 #include "net/http/http_version.h" | 18 #include "net/http/http_version.h" |
| 19 #include "net/socket/client_socket_handle.h" | 19 #include "net/socket/client_socket_handle.h" |
| 20 | 20 |
| 21 using base::DictionaryValue; | 21 using base::DictionaryValue; |
| 22 using base::Value; | 22 using base::Value; |
| 23 | 23 |
| 24 namespace net { | 24 namespace net { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 class ReceivedHeadersParameters : public NetLog::EventParameters { | 28 Value* NetLogReceivedHeadersCallback(const NetLog::Source& source, |
| 29 public: | 29 const std::string* feedback, |
| 30 ReceivedHeadersParameters(const NetLog::Source& source, | 30 NetLog::LogLevel /* log_level */) { |
| 31 const std::string& feedback) | 31 DictionaryValue* dict = new DictionaryValue; |
| 32 : source_(source), feedback_(feedback) {} | 32 source.AddToEventParameters(dict); |
| 33 dict->SetString("feedback", *feedback); |
| 34 return dict; |
| 35 } |
| 33 | 36 |
| 34 virtual Value* ToValue() const OVERRIDE { | 37 Value* NetLogStreamClosedCallback(const NetLog::Source& source, |
| 35 DictionaryValue* dict = new DictionaryValue; | 38 bool not_reusable, |
| 36 dict->Set("source_dependency", source_.ToValue()); | 39 NetLog::LogLevel /* log_level */) { |
| 37 dict->SetString("feedback", feedback_); | 40 DictionaryValue* dict = new DictionaryValue; |
| 38 return dict; | 41 source.AddToEventParameters(dict); |
| 39 } | 42 dict->SetBoolean("not_reusable", not_reusable); |
| 43 return dict; |
| 44 } |
| 40 | 45 |
| 41 protected: | 46 Value* NetLogHostPortPairCallback(const HostPortPair* host_port_pair, |
| 42 virtual ~ReceivedHeadersParameters() {} | 47 NetLog::LogLevel /* log_level */) { |
| 43 | 48 DictionaryValue* dict = new DictionaryValue; |
| 44 private: | 49 dict->SetString("host_and_port", host_port_pair->ToString()); |
| 45 const NetLog::Source source_; | 50 return dict; |
| 46 const std::string feedback_; | 51 } |
| 47 }; | |
| 48 | |
| 49 class StreamClosedParameters : public NetLog::EventParameters { | |
| 50 public: | |
| 51 StreamClosedParameters(const NetLog::Source& source, bool not_reusable) | |
| 52 : source_(source), not_reusable_(not_reusable) {} | |
| 53 | |
| 54 virtual Value* ToValue() const OVERRIDE { | |
| 55 DictionaryValue* dict = new DictionaryValue; | |
| 56 dict->Set("source_dependency", source_.ToValue()); | |
| 57 dict->SetBoolean("not_reusable", not_reusable_); | |
| 58 return dict; | |
| 59 } | |
| 60 | |
| 61 protected: | |
| 62 virtual ~StreamClosedParameters() {} | |
| 63 | |
| 64 private: | |
| 65 const NetLog::Source source_; | |
| 66 const bool not_reusable_; | |
| 67 }; | |
| 68 | 52 |
| 69 } // anonymous namespace | 53 } // anonymous namespace |
| 70 | 54 |
| 71 HttpPipelinedConnectionImpl::HttpPipelinedConnectionImpl( | 55 HttpPipelinedConnectionImpl::HttpPipelinedConnectionImpl( |
| 72 ClientSocketHandle* connection, | 56 ClientSocketHandle* connection, |
| 73 HttpPipelinedConnection::Delegate* delegate, | 57 HttpPipelinedConnection::Delegate* delegate, |
| 74 const HostPortPair& origin, | 58 const HostPortPair& origin, |
| 75 const SSLConfig& used_ssl_config, | 59 const SSLConfig& used_ssl_config, |
| 76 const ProxyInfo& used_proxy_info, | 60 const ProxyInfo& used_proxy_info, |
| 77 const BoundNetLog& net_log, | 61 const BoundNetLog& net_log, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 92 completed_one_request_(false), | 76 completed_one_request_(false), |
| 93 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 77 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 94 send_next_state_(SEND_STATE_NONE), | 78 send_next_state_(SEND_STATE_NONE), |
| 95 send_still_on_call_stack_(false), | 79 send_still_on_call_stack_(false), |
| 96 read_next_state_(READ_STATE_NONE), | 80 read_next_state_(READ_STATE_NONE), |
| 97 active_read_id_(0), | 81 active_read_id_(0), |
| 98 read_still_on_call_stack_(false) { | 82 read_still_on_call_stack_(false) { |
| 99 CHECK(connection_.get()); | 83 CHECK(connection_.get()); |
| 100 net_log_.BeginEvent( | 84 net_log_.BeginEvent( |
| 101 NetLog::TYPE_HTTP_PIPELINED_CONNECTION, | 85 NetLog::TYPE_HTTP_PIPELINED_CONNECTION, |
| 102 make_scoped_refptr(new NetLogStringParameter( | 86 base::Bind(&NetLogHostPortPairCallback, &origin)); |
| 103 "host_and_port", origin.ToString()))); | |
| 104 } | 87 } |
| 105 | 88 |
| 106 HttpPipelinedConnectionImpl::~HttpPipelinedConnectionImpl() { | 89 HttpPipelinedConnectionImpl::~HttpPipelinedConnectionImpl() { |
| 107 CHECK_EQ(depth(), 0); | 90 CHECK_EQ(depth(), 0); |
| 108 CHECK(stream_info_map_.empty()); | 91 CHECK(stream_info_map_.empty()); |
| 109 CHECK(pending_send_request_queue_.empty()); | 92 CHECK(pending_send_request_queue_.empty()); |
| 110 CHECK(request_order_.empty()); | 93 CHECK(request_order_.empty()); |
| 111 CHECK_EQ(send_next_state_, SEND_STATE_NONE); | 94 CHECK_EQ(send_next_state_, SEND_STATE_NONE); |
| 112 CHECK_EQ(read_next_state_, READ_STATE_NONE); | 95 CHECK_EQ(read_next_state_, READ_STATE_NONE); |
| 113 CHECK(!active_send_request_.get()); | 96 CHECK(!active_send_request_.get()); |
| 114 CHECK(!active_read_id_); | 97 CHECK(!active_read_id_); |
| 115 if (!usable_) { | 98 if (!usable_) { |
| 116 connection_->socket()->Disconnect(); | 99 connection_->socket()->Disconnect(); |
| 117 } | 100 } |
| 118 connection_->Reset(); | 101 connection_->Reset(); |
| 119 net_log_.EndEvent(NetLog::TYPE_HTTP_PIPELINED_CONNECTION, NULL); | 102 net_log_.EndEvent(NetLog::TYPE_HTTP_PIPELINED_CONNECTION); |
| 120 } | 103 } |
| 121 | 104 |
| 122 HttpPipelinedStream* HttpPipelinedConnectionImpl::CreateNewStream() { | 105 HttpPipelinedStream* HttpPipelinedConnectionImpl::CreateNewStream() { |
| 123 int pipeline_id = next_pipeline_id_++; | 106 int pipeline_id = next_pipeline_id_++; |
| 124 CHECK(pipeline_id); | 107 CHECK(pipeline_id); |
| 125 HttpPipelinedStream* stream = new HttpPipelinedStream(this, pipeline_id); | 108 HttpPipelinedStream* stream = new HttpPipelinedStream(this, pipeline_id); |
| 126 stream_info_map_.insert(std::make_pair(pipeline_id, StreamInfo())); | 109 stream_info_map_.insert(std::make_pair(pipeline_id, StreamInfo())); |
| 127 return stream; | 110 return stream; |
| 128 } | 111 } |
| 129 | 112 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 | 269 |
| 287 int HttpPipelinedConnectionImpl::DoSendComplete(int result) { | 270 int HttpPipelinedConnectionImpl::DoSendComplete(int result) { |
| 288 CHECK(active_send_request_.get()); | 271 CHECK(active_send_request_.get()); |
| 289 CHECK_EQ(STREAM_SENDING, | 272 CHECK_EQ(STREAM_SENDING, |
| 290 stream_info_map_[active_send_request_->pipeline_id].state); | 273 stream_info_map_[active_send_request_->pipeline_id].state); |
| 291 | 274 |
| 292 request_order_.push(active_send_request_->pipeline_id); | 275 request_order_.push(active_send_request_->pipeline_id); |
| 293 stream_info_map_[active_send_request_->pipeline_id].state = STREAM_SENT; | 276 stream_info_map_[active_send_request_->pipeline_id].state = STREAM_SENT; |
| 294 net_log_.AddEvent( | 277 net_log_.AddEvent( |
| 295 NetLog::TYPE_HTTP_PIPELINED_CONNECTION_SENT_REQUEST, | 278 NetLog::TYPE_HTTP_PIPELINED_CONNECTION_SENT_REQUEST, |
| 296 make_scoped_refptr(new NetLogSourceParameter( | 279 stream_info_map_[active_send_request_->pipeline_id].source. |
| 297 "source_dependency", | 280 ToEventParametersCallback()); |
| 298 stream_info_map_[active_send_request_->pipeline_id].source))); | |
| 299 | 281 |
| 300 if (result == ERR_SOCKET_NOT_CONNECTED && completed_one_request_) { | 282 if (result == ERR_SOCKET_NOT_CONNECTED && completed_one_request_) { |
| 301 result = ERR_PIPELINE_EVICTION; | 283 result = ERR_PIPELINE_EVICTION; |
| 302 } | 284 } |
| 303 if (result < OK) { | 285 if (result < OK) { |
| 304 usable_ = false; | 286 usable_ = false; |
| 305 } | 287 } |
| 306 | 288 |
| 307 if (!send_still_on_call_stack_) { | 289 if (!send_still_on_call_stack_) { |
| 308 QueueUserCallback(active_send_request_->pipeline_id, | 290 QueueUserCallback(active_send_request_->pipeline_id, |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 } | 524 } |
| 543 read_next_state_ = READ_STATE_NONE; | 525 read_next_state_ = READ_STATE_NONE; |
| 544 return result; | 526 return result; |
| 545 } | 527 } |
| 546 | 528 |
| 547 void HttpPipelinedConnectionImpl::Close(int pipeline_id, | 529 void HttpPipelinedConnectionImpl::Close(int pipeline_id, |
| 548 bool not_reusable) { | 530 bool not_reusable) { |
| 549 CHECK(ContainsKey(stream_info_map_, pipeline_id)); | 531 CHECK(ContainsKey(stream_info_map_, pipeline_id)); |
| 550 net_log_.AddEvent( | 532 net_log_.AddEvent( |
| 551 NetLog::TYPE_HTTP_PIPELINED_CONNECTION_STREAM_CLOSED, | 533 NetLog::TYPE_HTTP_PIPELINED_CONNECTION_STREAM_CLOSED, |
| 552 make_scoped_refptr(new StreamClosedParameters( | 534 base::Bind(&NetLogStreamClosedCallback, |
| 553 stream_info_map_[pipeline_id].source, not_reusable))); | 535 stream_info_map_[pipeline_id].source, not_reusable)); |
| 554 switch (stream_info_map_[pipeline_id].state) { | 536 switch (stream_info_map_[pipeline_id].state) { |
| 555 case STREAM_CREATED: | 537 case STREAM_CREATED: |
| 556 stream_info_map_[pipeline_id].state = STREAM_UNUSED; | 538 stream_info_map_[pipeline_id].state = STREAM_UNUSED; |
| 557 break; | 539 break; |
| 558 | 540 |
| 559 case STREAM_BOUND: | 541 case STREAM_BOUND: |
| 560 stream_info_map_[pipeline_id].state = STREAM_CLOSED; | 542 stream_info_map_[pipeline_id].state = STREAM_CLOSED; |
| 561 break; | 543 break; |
| 562 | 544 |
| 563 case STREAM_SENDING: | 545 case STREAM_SENDING: |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 feedback_str = "AUTHENTICATION_REQUIRED"; | 737 feedback_str = "AUTHENTICATION_REQUIRED"; |
| 756 break; | 738 break; |
| 757 | 739 |
| 758 default: | 740 default: |
| 759 NOTREACHED(); | 741 NOTREACHED(); |
| 760 feedback_str = "UNKNOWN"; | 742 feedback_str = "UNKNOWN"; |
| 761 break; | 743 break; |
| 762 } | 744 } |
| 763 net_log_.AddEvent( | 745 net_log_.AddEvent( |
| 764 NetLog::TYPE_HTTP_PIPELINED_CONNECTION_RECEIVED_HEADERS, | 746 NetLog::TYPE_HTTP_PIPELINED_CONNECTION_RECEIVED_HEADERS, |
| 765 make_scoped_refptr(new ReceivedHeadersParameters( | 747 base::Bind(&NetLogReceivedHeadersCallback, |
| 766 stream_info_map_[pipeline_id].source, feedback_str))); | 748 stream_info_map_[pipeline_id].source, &feedback_str)); |
| 767 delegate_->OnPipelineFeedback(this, feedback); | 749 delegate_->OnPipelineFeedback(this, feedback); |
| 768 } | 750 } |
| 769 | 751 |
| 770 void HttpPipelinedConnectionImpl::QueueUserCallback( | 752 void HttpPipelinedConnectionImpl::QueueUserCallback( |
| 771 int pipeline_id, const CompletionCallback& callback, int rv, | 753 int pipeline_id, const CompletionCallback& callback, int rv, |
| 772 const tracked_objects::Location& from_here) { | 754 const tracked_objects::Location& from_here) { |
| 773 CHECK(stream_info_map_[pipeline_id].pending_user_callback.is_null()); | 755 CHECK(stream_info_map_[pipeline_id].pending_user_callback.is_null()); |
| 774 stream_info_map_[pipeline_id].pending_user_callback = callback; | 756 stream_info_map_[pipeline_id].pending_user_callback = callback; |
| 775 MessageLoop::current()->PostTask( | 757 MessageLoop::current()->PostTask( |
| 776 from_here, | 758 from_here, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 } | 814 } |
| 833 | 815 |
| 834 HttpPipelinedConnectionImpl::StreamInfo::StreamInfo() | 816 HttpPipelinedConnectionImpl::StreamInfo::StreamInfo() |
| 835 : state(STREAM_CREATED) { | 817 : state(STREAM_CREATED) { |
| 836 } | 818 } |
| 837 | 819 |
| 838 HttpPipelinedConnectionImpl::StreamInfo::~StreamInfo() { | 820 HttpPipelinedConnectionImpl::StreamInfo::~StreamInfo() { |
| 839 } | 821 } |
| 840 | 822 |
| 841 } // namespace net | 823 } // namespace net |
| OLD | NEW |