Chromium Code Reviews| 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_stream_factory_impl_job.h" | 5 #include "net/http/http_stream_factory_impl_job.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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 #include "net/socket/client_socket_pool_manager.h" | 33 #include "net/socket/client_socket_pool_manager.h" |
| 34 #include "net/socket/socks_client_socket_pool.h" | 34 #include "net/socket/socks_client_socket_pool.h" |
| 35 #include "net/socket/ssl_client_socket.h" | 35 #include "net/socket/ssl_client_socket.h" |
| 36 #include "net/socket/ssl_client_socket_pool.h" | 36 #include "net/socket/ssl_client_socket_pool.h" |
| 37 #include "net/spdy/spdy_http_stream.h" | 37 #include "net/spdy/spdy_http_stream.h" |
| 38 #include "net/spdy/spdy_session.h" | 38 #include "net/spdy/spdy_session.h" |
| 39 #include "net/spdy/spdy_session_pool.h" | 39 #include "net/spdy/spdy_session_pool.h" |
| 40 | 40 |
| 41 namespace net { | 41 namespace net { |
| 42 | 42 |
| 43 // Parameters associated with the start of a HTTP stream job. | 43 // Returns parameters associated with the start of a HTTP stream job. |
| 44 class HttpStreamJobParameters : public NetLog::EventParameters { | 44 Value* NetLogHttpStreamJobCallback(const GURL* original_url, |
| 45 public: | 45 const GURL* url, |
| 46 static scoped_refptr<HttpStreamJobParameters> Create( | 46 NetLog::LogLevel /* log_level */) { |
| 47 const GURL& original_url, | |
| 48 const GURL& url) { | |
| 49 return make_scoped_refptr(new HttpStreamJobParameters(original_url, url)); | |
| 50 } | |
| 51 | |
| 52 virtual Value* ToValue() const; | |
| 53 | |
| 54 protected: | |
| 55 virtual ~HttpStreamJobParameters() {} | |
| 56 | |
| 57 private: | |
| 58 HttpStreamJobParameters(const GURL& original_url, const GURL& url) | |
| 59 : original_url_(original_url.GetOrigin().spec()), | |
| 60 url_(url.GetOrigin().spec()) { | |
| 61 } | |
| 62 | |
| 63 const std::string original_url_; | |
| 64 const std::string url_; | |
| 65 }; | |
| 66 | |
| 67 Value* HttpStreamJobParameters::ToValue() const { | |
| 68 DictionaryValue* dict = new DictionaryValue(); | 47 DictionaryValue* dict = new DictionaryValue(); |
| 69 dict->SetString("original_url", original_url_); | 48 dict->SetString("original_url", original_url->spec()); |
|
eroman
2012/06/13 18:44:06
This is different, is that intentional?
Before it
mmenke
2012/06/13 19:06:36
Fixed.
| |
| 70 dict->SetString("url", url_); | 49 dict->SetString("url", url->spec()); |
|
eroman
2012/06/13 18:44:06
ditto.
mmenke
2012/06/13 19:06:36
Fixed.
| |
| 71 return dict; | 50 return dict; |
| 72 } | 51 } |
| 73 | 52 |
| 74 // Parameters associated with the Proto (with NPN negotiation) of a HTTP stream. | 53 // Returns parameters associated with the Proto (with NPN negotiation) of a HTTP |
| 75 class HttpStreamProtoParameters : public NetLog::EventParameters { | 54 // stream. |
| 76 public: | 55 Value* NetLogHttpStreamProtoCallback( |
| 77 static scoped_refptr<HttpStreamProtoParameters> Create( | 56 const SSLClientSocket::NextProtoStatus status, |
| 78 const SSLClientSocket::NextProtoStatus status, | 57 const std::string* proto, |
| 79 const std::string& proto, | 58 const std::string* server_protos, |
| 80 const std::string& server_protos) { | 59 NetLog::LogLevel /* log_level */) { |
| 81 return make_scoped_refptr(new HttpStreamProtoParameters( | |
| 82 status, proto, server_protos)); | |
| 83 } | |
| 84 | |
| 85 virtual Value* ToValue() const; | |
| 86 | |
| 87 protected: | |
| 88 virtual ~HttpStreamProtoParameters() {} | |
| 89 | |
| 90 private: | |
| 91 HttpStreamProtoParameters(const SSLClientSocket::NextProtoStatus status, | |
| 92 const std::string& proto, | |
| 93 const std::string& server_protos) | |
| 94 : status_(status), | |
| 95 proto_(proto), | |
| 96 server_protos_(server_protos) { | |
| 97 } | |
| 98 | |
| 99 const SSLClientSocket::NextProtoStatus status_; | |
| 100 const std::string proto_; | |
| 101 const std::string server_protos_; | |
| 102 }; | |
| 103 | |
| 104 Value* HttpStreamProtoParameters::ToValue() const { | |
| 105 DictionaryValue* dict = new DictionaryValue(); | 60 DictionaryValue* dict = new DictionaryValue(); |
| 106 | 61 |
| 107 dict->SetString("next_proto_status", | 62 dict->SetString("next_proto_status", |
| 108 SSLClientSocket::NextProtoStatusToString(status_)); | 63 SSLClientSocket::NextProtoStatusToString(status)); |
| 109 dict->SetString("proto", proto_); | 64 dict->SetString("proto", *proto); |
| 110 dict->SetString("server_protos", | 65 dict->SetString("server_protos", |
| 111 SSLClientSocket::ServerProtosToString(server_protos_)); | 66 SSLClientSocket::ServerProtosToString(*server_protos)); |
| 112 return dict; | 67 return dict; |
| 113 } | 68 } |
| 114 | 69 |
| 115 HttpStreamFactoryImpl::Job::Job(HttpStreamFactoryImpl* stream_factory, | 70 HttpStreamFactoryImpl::Job::Job(HttpStreamFactoryImpl* stream_factory, |
| 116 HttpNetworkSession* session, | 71 HttpNetworkSession* session, |
| 117 const HttpRequestInfo& request_info, | 72 const HttpRequestInfo& request_info, |
| 118 const SSLConfig& server_ssl_config, | 73 const SSLConfig& server_ssl_config, |
| 119 const SSLConfig& proxy_ssl_config, | 74 const SSLConfig& proxy_ssl_config, |
| 120 NetLog* net_log) | 75 NetLog* net_log) |
| 121 : request_(NULL), | 76 : request_(NULL), |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 142 protocol_negotiated_(kProtoUnknown), | 97 protocol_negotiated_(kProtoUnknown), |
| 143 num_streams_(0), | 98 num_streams_(0), |
| 144 spdy_session_direct_(false), | 99 spdy_session_direct_(false), |
| 145 existing_available_pipeline_(false), | 100 existing_available_pipeline_(false), |
| 146 ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) { | 101 ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) { |
| 147 DCHECK(stream_factory); | 102 DCHECK(stream_factory); |
| 148 DCHECK(session); | 103 DCHECK(session); |
| 149 } | 104 } |
| 150 | 105 |
| 151 HttpStreamFactoryImpl::Job::~Job() { | 106 HttpStreamFactoryImpl::Job::~Job() { |
| 152 net_log_.EndEvent(NetLog::TYPE_HTTP_STREAM_JOB, NULL); | 107 net_log_.EndEvent(NetLog::TYPE_HTTP_STREAM_JOB); |
| 153 | 108 |
| 154 // When we're in a partially constructed state, waiting for the user to | 109 // When we're in a partially constructed state, waiting for the user to |
| 155 // provide certificate handling information or authentication, we can't reuse | 110 // provide certificate handling information or authentication, we can't reuse |
| 156 // this stream at all. | 111 // this stream at all. |
| 157 if (next_state_ == STATE_WAITING_USER_ACTION) { | 112 if (next_state_ == STATE_WAITING_USER_ACTION) { |
| 158 connection_->socket()->Disconnect(); | 113 connection_->socket()->Disconnect(); |
| 159 connection_.reset(); | 114 connection_.reset(); |
| 160 } | 115 } |
| 161 | 116 |
| 162 if (pac_request_) | 117 if (pac_request_) |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 } | 545 } |
| 591 | 546 |
| 592 int HttpStreamFactoryImpl::Job::DoStart() { | 547 int HttpStreamFactoryImpl::Job::DoStart() { |
| 593 int port = request_info_.url.EffectiveIntPort(); | 548 int port = request_info_.url.EffectiveIntPort(); |
| 594 origin_ = HostPortPair(request_info_.url.HostNoBrackets(), port); | 549 origin_ = HostPortPair(request_info_.url.HostNoBrackets(), port); |
| 595 origin_url_ = HttpStreamFactory::ApplyHostMappingRules( | 550 origin_url_ = HttpStreamFactory::ApplyHostMappingRules( |
| 596 request_info_.url, &origin_); | 551 request_info_.url, &origin_); |
| 597 http_pipelining_key_.reset(new HttpPipelinedHost::Key(origin_)); | 552 http_pipelining_key_.reset(new HttpPipelinedHost::Key(origin_)); |
| 598 | 553 |
| 599 net_log_.BeginEvent(NetLog::TYPE_HTTP_STREAM_JOB, | 554 net_log_.BeginEvent(NetLog::TYPE_HTTP_STREAM_JOB, |
| 600 HttpStreamJobParameters::Create(request_info_.url, | 555 base::Bind(&NetLogHttpStreamJobCallback, |
| 601 origin_url_)); | 556 &request_info_.url, &origin_url_)); |
| 602 | 557 |
| 603 // Don't connect to restricted ports. | 558 // Don't connect to restricted ports. |
| 604 if (!IsPortAllowedByDefault(port) && !IsPortAllowedByOverride(port)) { | 559 if (!IsPortAllowedByDefault(port) && !IsPortAllowedByOverride(port)) { |
| 605 if (waiting_job_) { | 560 if (waiting_job_) { |
| 606 waiting_job_->Resume(this); | 561 waiting_job_->Resume(this); |
| 607 waiting_job_ = NULL; | 562 waiting_job_ = NULL; |
| 608 } | 563 } |
| 609 return ERR_UNSAFE_PORT; | 564 return ERR_UNSAFE_PORT; |
| 610 } | 565 } |
| 611 | 566 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 833 was_npn_negotiated_ = true; | 788 was_npn_negotiated_ = true; |
| 834 std::string proto; | 789 std::string proto; |
| 835 std::string server_protos; | 790 std::string server_protos; |
| 836 SSLClientSocket::NextProtoStatus status = | 791 SSLClientSocket::NextProtoStatus status = |
| 837 ssl_socket->GetNextProto(&proto, &server_protos); | 792 ssl_socket->GetNextProto(&proto, &server_protos); |
| 838 NextProto protocol_negotiated = | 793 NextProto protocol_negotiated = |
| 839 SSLClientSocket::NextProtoFromString(proto); | 794 SSLClientSocket::NextProtoFromString(proto); |
| 840 protocol_negotiated_ = protocol_negotiated; | 795 protocol_negotiated_ = protocol_negotiated; |
| 841 net_log_.AddEvent( | 796 net_log_.AddEvent( |
| 842 NetLog::TYPE_HTTP_STREAM_REQUEST_PROTO, | 797 NetLog::TYPE_HTTP_STREAM_REQUEST_PROTO, |
| 843 HttpStreamProtoParameters::Create(status, proto, server_protos)); | 798 base::Bind(&NetLogHttpStreamProtoCallback, |
| 799 status, &proto, &server_protos)); | |
| 844 if (ssl_socket->was_spdy_negotiated()) | 800 if (ssl_socket->was_spdy_negotiated()) |
| 845 SwitchToSpdyMode(); | 801 SwitchToSpdyMode(); |
| 846 } | 802 } |
| 847 if (ShouldForceSpdySSL()) | 803 if (ShouldForceSpdySSL()) |
| 848 SwitchToSpdyMode(); | 804 SwitchToSpdyMode(); |
| 849 } else if (proxy_info_.is_https() && connection_->socket() && | 805 } else if (proxy_info_.is_https() && connection_->socket() && |
| 850 result == OK) { | 806 result == OK) { |
| 851 ProxyClientSocket* proxy_socket = | 807 ProxyClientSocket* proxy_socket = |
| 852 static_cast<ProxyClientSocket*>(connection_->socket()); | 808 static_cast<ProxyClientSocket*>(connection_->socket()); |
| 853 if (proxy_socket->IsUsingSpdy()) { | 809 if (proxy_socket->IsUsingSpdy()) { |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1309 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | | 1265 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | |
| 1310 net::LOAD_IS_DOWNLOAD)) { | 1266 net::LOAD_IS_DOWNLOAD)) { |
| 1311 // Avoid pipelining resources that may be streamed for a long time. | 1267 // Avoid pipelining resources that may be streamed for a long time. |
| 1312 return false; | 1268 return false; |
| 1313 } | 1269 } |
| 1314 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( | 1270 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( |
| 1315 *http_pipelining_key_.get()); | 1271 *http_pipelining_key_.get()); |
| 1316 } | 1272 } |
| 1317 | 1273 |
| 1318 } // namespace net | 1274 } // namespace net |
| OLD | NEW |