| 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/socket/client_socket_handle.h" | 5 #include "net/socket/client_socket_handle.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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 13 #include "net/socket/client_socket_pool.h" | 13 #include "net/socket/client_socket_pool.h" |
| 14 #include "net/socket/client_socket_pool_histograms.h" | 14 #include "net/socket/client_socket_pool_histograms.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 ClientSocketHandle::ClientSocketHandle() | 18 ClientSocketHandle::ClientSocketHandle() |
| 19 : is_initialized_(false), | 19 : is_initialized_(false), |
| 20 pool_(NULL), | 20 pool_(NULL), |
| 21 layered_pool_(NULL), | 21 higher_pool_(NULL), |
| 22 is_reused_(false), | 22 is_reused_(false), |
| 23 callback_(base::Bind(&ClientSocketHandle::OnIOComplete, | 23 callback_(base::Bind(&ClientSocketHandle::OnIOComplete, |
| 24 base::Unretained(this))), | 24 base::Unretained(this))), |
| 25 is_ssl_error_(false) {} | 25 is_ssl_error_(false) {} |
| 26 | 26 |
| 27 ClientSocketHandle::~ClientSocketHandle() { | 27 ClientSocketHandle::~ClientSocketHandle() { |
| 28 Reset(); | 28 Reset(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void ClientSocketHandle::Reset() { | 31 void ClientSocketHandle::Reset() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 46 pool_->ReleaseSocket(group_name_, PassSocket(), pool_id_); | 46 pool_->ReleaseSocket(group_name_, PassSocket(), pool_id_); |
| 47 } else if (cancel) { | 47 } else if (cancel) { |
| 48 // If we did not get initialized yet, we've got a socket request pending. | 48 // If we did not get initialized yet, we've got a socket request pending. |
| 49 // Cancel it. | 49 // Cancel it. |
| 50 pool_->CancelRequest(group_name_, this); | 50 pool_->CancelRequest(group_name_, this); |
| 51 } | 51 } |
| 52 is_initialized_ = false; | 52 is_initialized_ = false; |
| 53 group_name_.clear(); | 53 group_name_.clear(); |
| 54 is_reused_ = false; | 54 is_reused_ = false; |
| 55 user_callback_.Reset(); | 55 user_callback_.Reset(); |
| 56 if (layered_pool_) { | 56 if (higher_pool_) |
| 57 pool_->RemoveLayeredPool(layered_pool_); | 57 RemoveHigherLayeredPool(higher_pool_); |
| 58 layered_pool_ = NULL; | |
| 59 } | |
| 60 pool_ = NULL; | 58 pool_ = NULL; |
| 61 idle_time_ = base::TimeDelta(); | 59 idle_time_ = base::TimeDelta(); |
| 62 init_time_ = base::TimeTicks(); | 60 init_time_ = base::TimeTicks(); |
| 63 setup_time_ = base::TimeDelta(); | 61 setup_time_ = base::TimeDelta(); |
| 64 connect_timing_ = LoadTimingInfo::ConnectTiming(); | 62 connect_timing_ = LoadTimingInfo::ConnectTiming(); |
| 65 pool_id_ = -1; | 63 pool_id_ = -1; |
| 66 } | 64 } |
| 67 | 65 |
| 68 void ClientSocketHandle::ResetErrorState() { | 66 void ClientSocketHandle::ResetErrorState() { |
| 69 is_ssl_error_ = false; | 67 is_ssl_error_ = false; |
| 70 ssl_error_response_info_ = HttpResponseInfo(); | 68 ssl_error_response_info_ = HttpResponseInfo(); |
| 71 pending_http_proxy_connection_.reset(); | 69 pending_http_proxy_connection_.reset(); |
| 72 } | 70 } |
| 73 | 71 |
| 74 LoadState ClientSocketHandle::GetLoadState() const { | 72 LoadState ClientSocketHandle::GetLoadState() const { |
| 75 CHECK(!is_initialized()); | 73 CHECK(!is_initialized()); |
| 76 CHECK(!group_name_.empty()); | 74 CHECK(!group_name_.empty()); |
| 77 // Because of http://crbug.com/37810 we may not have a pool, but have | 75 // Because of http://crbug.com/37810 we may not have a pool, but have |
| 78 // just a raw socket. | 76 // just a raw socket. |
| 79 if (!pool_) | 77 if (!pool_) |
| 80 return LOAD_STATE_IDLE; | 78 return LOAD_STATE_IDLE; |
| 81 return pool_->GetLoadState(group_name_, this); | 79 return pool_->GetLoadState(group_name_, this); |
| 82 } | 80 } |
| 83 | 81 |
| 84 bool ClientSocketHandle::IsPoolStalled() const { | 82 bool ClientSocketHandle::IsPoolStalled() const { |
| 83 if (!pool_) |
| 84 return false; |
| 85 return pool_->IsStalled(); | 85 return pool_->IsStalled(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void ClientSocketHandle::AddLayeredPool(LayeredPool* layered_pool) { | 88 void ClientSocketHandle::AddHigherLayeredPool(HigherLayeredPool* higher_pool) { |
| 89 CHECK(layered_pool); | 89 CHECK(higher_pool); |
| 90 CHECK(!layered_pool_); | 90 CHECK(!higher_pool_); |
| 91 // TODO(mmenke): |pool_| should only be NULL in tests. Maybe stop doing that |
| 92 // so this be be made into a DCHECK, and the same can be done in |
| 93 // RemoveHigherLayeredPool? |
| 91 if (pool_) { | 94 if (pool_) { |
| 92 pool_->AddLayeredPool(layered_pool); | 95 pool_->AddHigherLayeredPool(higher_pool); |
| 93 layered_pool_ = layered_pool; | 96 higher_pool_ = higher_pool; |
| 94 } | 97 } |
| 95 } | 98 } |
| 96 | 99 |
| 97 void ClientSocketHandle::RemoveLayeredPool(LayeredPool* layered_pool) { | 100 void ClientSocketHandle::RemoveHigherLayeredPool( |
| 98 CHECK(layered_pool); | 101 HigherLayeredPool* higher_pool) { |
| 99 CHECK(layered_pool_); | 102 CHECK(higher_pool_); |
| 103 CHECK_EQ(higher_pool_, higher_pool); |
| 100 if (pool_) { | 104 if (pool_) { |
| 101 pool_->RemoveLayeredPool(layered_pool); | 105 pool_->RemoveHigherLayeredPool(higher_pool); |
| 102 layered_pool_ = NULL; | 106 higher_pool_ = NULL; |
| 103 } | 107 } |
| 104 } | 108 } |
| 105 | 109 |
| 106 bool ClientSocketHandle::GetLoadTimingInfo( | 110 bool ClientSocketHandle::GetLoadTimingInfo( |
| 107 bool is_reused, | 111 bool is_reused, |
| 108 LoadTimingInfo* load_timing_info) const { | 112 LoadTimingInfo* load_timing_info) const { |
| 109 // Only return load timing information when there's a socket. | 113 // Only return load timing information when there's a socket. |
| 110 if (!socket_) | 114 if (!socket_) |
| 111 return false; | 115 return false; |
| 112 | 116 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 // TODO(eroman): This logging is not complete, in particular set_socket() and | 175 // TODO(eroman): This logging is not complete, in particular set_socket() and |
| 172 // release() socket. It ends up working though, since those methods are being | 176 // release() socket. It ends up working though, since those methods are being |
| 173 // used to layer sockets (and the destination sources are the same). | 177 // used to layer sockets (and the destination sources are the same). |
| 174 DCHECK(socket_.get()); | 178 DCHECK(socket_.get()); |
| 175 socket_->NetLog().BeginEvent( | 179 socket_->NetLog().BeginEvent( |
| 176 NetLog::TYPE_SOCKET_IN_USE, | 180 NetLog::TYPE_SOCKET_IN_USE, |
| 177 requesting_source_.ToEventParametersCallback()); | 181 requesting_source_.ToEventParametersCallback()); |
| 178 } | 182 } |
| 179 | 183 |
| 180 } // namespace net | 184 } // namespace net |
| OLD | NEW |