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/spdy/spdy_proxy_client_socket.h" | 5 #include "net/spdy/spdy_proxy_client_socket.h" |
| 6 | 6 |
| 7 #include <algorithm> // min | 7 #include <algorithm> // min |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 const std::string& user_agent, | 29 const std::string& user_agent, |
| 30 const HostPortPair& endpoint, | 30 const HostPortPair& endpoint, |
| 31 const GURL& url, | 31 const GURL& url, |
| 32 const HostPortPair& proxy_server, | 32 const HostPortPair& proxy_server, |
| 33 const BoundNetLog& source_net_log, | 33 const BoundNetLog& source_net_log, |
| 34 HttpAuthCache* auth_cache, | 34 HttpAuthCache* auth_cache, |
| 35 HttpAuthHandlerFactory* auth_handler_factory) | 35 HttpAuthHandlerFactory* auth_handler_factory) |
| 36 : next_state_(STATE_DISCONNECTED), | 36 : next_state_(STATE_DISCONNECTED), |
| 37 spdy_stream_(spdy_stream), | 37 spdy_stream_(spdy_stream), |
| 38 endpoint_(endpoint), | 38 endpoint_(endpoint), |
| 39 auth_( | 39 auth_(new HttpAuthController(HttpAuth::AUTH_PROXY, |
| 40 new HttpAuthController(HttpAuth::AUTH_PROXY, | 40 GURL("https://" + proxy_server.ToString()), |
| 41 GURL("https://" + proxy_server.ToString()), | 41 auth_cache, |
| 42 auth_cache, | 42 auth_handler_factory)), |
|
wtc
2014/06/13 18:03:50
This change was made by "git cl format". Let me kn
| |
| 43 auth_handler_factory)), | |
| 44 user_buffer_len_(0), | 43 user_buffer_len_(0), |
| 45 write_buffer_len_(0), | 44 write_buffer_len_(0), |
| 46 was_ever_used_(false), | 45 was_ever_used_(false), |
| 47 redirect_has_load_timing_info_(false), | 46 redirect_has_load_timing_info_(false), |
| 48 net_log_(BoundNetLog::Make(spdy_stream->net_log().net_log(), | 47 net_log_(BoundNetLog::Make(spdy_stream->net_log().net_log(), |
| 49 NetLog::SOURCE_PROXY_CLIENT_SOCKET)), | 48 NetLog::SOURCE_PROXY_CLIENT_SOCKET)), |
| 50 weak_factory_(this) { | 49 weak_factory_(this), |
| 50 write_callback_weak_factory_(this) { | |
| 51 request_.method = "CONNECT"; | 51 request_.method = "CONNECT"; |
| 52 request_.url = url; | 52 request_.url = url; |
| 53 if (!user_agent.empty()) | 53 if (!user_agent.empty()) |
| 54 request_.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, | 54 request_.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 55 user_agent); | 55 user_agent); |
| 56 | 56 |
| 57 net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE, | 57 net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE, |
| 58 source_net_log.source().ToEventParametersCallback()); | 58 source_net_log.source().ToEventParametersCallback()); |
| 59 net_log_.AddEvent( | 59 net_log_.AddEvent( |
| 60 NetLog::TYPE_SPDY_PROXY_CLIENT_SESSION, | 60 NetLog::TYPE_SPDY_PROXY_CLIENT_SESSION, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 } | 130 } |
| 131 | 131 |
| 132 void SpdyProxyClientSocket::Disconnect() { | 132 void SpdyProxyClientSocket::Disconnect() { |
| 133 read_buffer_queue_.Clear(); | 133 read_buffer_queue_.Clear(); |
| 134 user_buffer_ = NULL; | 134 user_buffer_ = NULL; |
| 135 user_buffer_len_ = 0; | 135 user_buffer_len_ = 0; |
| 136 read_callback_.Reset(); | 136 read_callback_.Reset(); |
| 137 | 137 |
| 138 write_buffer_len_ = 0; | 138 write_buffer_len_ = 0; |
| 139 write_callback_.Reset(); | 139 write_callback_.Reset(); |
| 140 write_callback_weak_factory_.InvalidateWeakPtrs(); | |
| 140 | 141 |
| 141 next_state_ = STATE_DISCONNECTED; | 142 next_state_ = STATE_DISCONNECTED; |
| 142 | 143 |
| 143 if (spdy_stream_.get()) { | 144 if (spdy_stream_.get()) { |
| 144 // This will cause OnClose to be invoked, which takes care of | 145 // This will cause OnClose to be invoked, which takes care of |
| 145 // cleaning up all the internal state. | 146 // cleaning up all the internal state. |
| 146 spdy_stream_->Cancel(); | 147 spdy_stream_->Cancel(); |
| 147 DCHECK(!spdy_stream_.get()); | 148 DCHECK(!spdy_stream_.get()); |
| 148 } | 149 } |
| 149 } | 150 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 return spdy_stream_->GetLocalAddress(address); | 262 return spdy_stream_->GetLocalAddress(address); |
| 262 } | 263 } |
| 263 | 264 |
| 264 void SpdyProxyClientSocket::LogBlockedTunnelResponse() const { | 265 void SpdyProxyClientSocket::LogBlockedTunnelResponse() const { |
| 265 ProxyClientSocket::LogBlockedTunnelResponse( | 266 ProxyClientSocket::LogBlockedTunnelResponse( |
| 266 response_.headers->response_code(), | 267 response_.headers->response_code(), |
| 267 request_.url, | 268 request_.url, |
| 268 /* is_https_proxy = */ true); | 269 /* is_https_proxy = */ true); |
| 269 } | 270 } |
| 270 | 271 |
| 272 void SpdyProxyClientSocket::RunCallback(const CompletionCallback& callback, | |
| 273 int result) const { | |
| 274 callback.Run(result); | |
| 275 } | |
| 276 | |
| 271 void SpdyProxyClientSocket::OnIOComplete(int result) { | 277 void SpdyProxyClientSocket::OnIOComplete(int result) { |
| 272 DCHECK_NE(STATE_DISCONNECTED, next_state_); | 278 DCHECK_NE(STATE_DISCONNECTED, next_state_); |
| 273 int rv = DoLoop(result); | 279 int rv = DoLoop(result); |
| 274 if (rv != ERR_IO_PENDING) { | 280 if (rv != ERR_IO_PENDING) { |
| 275 CompletionCallback c = read_callback_; | 281 CompletionCallback c = read_callback_; |
| 276 read_callback_.Reset(); | 282 read_callback_.Reset(); |
| 277 c.Run(rv); | 283 c.Run(rv); |
| 278 } | 284 } |
| 279 } | 285 } |
| 280 | 286 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 481 void SpdyProxyClientSocket::OnDataSent() { | 487 void SpdyProxyClientSocket::OnDataSent() { |
| 482 DCHECK(!write_callback_.is_null()); | 488 DCHECK(!write_callback_.is_null()); |
| 483 | 489 |
| 484 int rv = write_buffer_len_; | 490 int rv = write_buffer_len_; |
| 485 write_buffer_len_ = 0; | 491 write_buffer_len_ = 0; |
| 486 | 492 |
| 487 // Proxy write callbacks result in deep callback chains. Post to allow the | 493 // Proxy write callbacks result in deep callback chains. Post to allow the |
| 488 // stream's write callback chain to unwind (see crbug.com/355511). | 494 // stream's write callback chain to unwind (see crbug.com/355511). |
| 489 base::MessageLoop::current()->PostTask( | 495 base::MessageLoop::current()->PostTask( |
| 490 FROM_HERE, | 496 FROM_HERE, |
| 491 base::Bind(ResetAndReturn(&write_callback_), rv)); | 497 base::Bind(&SpdyProxyClientSocket::RunCallback, |
| 498 write_callback_weak_factory_.GetWeakPtr(), | |
| 499 ResetAndReturn(&write_callback_), | |
| 500 rv)); | |
| 492 } | 501 } |
| 493 | 502 |
| 494 void SpdyProxyClientSocket::OnClose(int status) { | 503 void SpdyProxyClientSocket::OnClose(int status) { |
| 495 was_ever_used_ = spdy_stream_->WasEverUsed(); | 504 was_ever_used_ = spdy_stream_->WasEverUsed(); |
| 496 spdy_stream_.reset(); | 505 spdy_stream_.reset(); |
| 497 | 506 |
| 498 bool connecting = next_state_ != STATE_DISCONNECTED && | 507 bool connecting = next_state_ != STATE_DISCONNECTED && |
| 499 next_state_ < STATE_OPEN; | 508 next_state_ < STATE_OPEN; |
| 500 if (next_state_ == STATE_OPEN) | 509 if (next_state_ == STATE_OPEN) |
| 501 next_state_ = STATE_CLOSED; | 510 next_state_ = STATE_CLOSED; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 517 } else if (!read_callback_.is_null()) { | 526 } else if (!read_callback_.is_null()) { |
| 518 // If we have a read_callback_, the we need to make sure we call it back. | 527 // If we have a read_callback_, the we need to make sure we call it back. |
| 519 OnDataReceived(scoped_ptr<SpdyBuffer>()); | 528 OnDataReceived(scoped_ptr<SpdyBuffer>()); |
| 520 } | 529 } |
| 521 // This may have been deleted by read_callback_, so check first. | 530 // This may have been deleted by read_callback_, so check first. |
| 522 if (weak_ptr.get() && !write_callback.is_null()) | 531 if (weak_ptr.get() && !write_callback.is_null()) |
| 523 write_callback.Run(ERR_CONNECTION_CLOSED); | 532 write_callback.Run(ERR_CONNECTION_CLOSED); |
| 524 } | 533 } |
| 525 | 534 |
| 526 } // namespace net | 535 } // namespace net |
| OLD | NEW |