| 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), | |
| 21 layered_pool_(NULL), | |
| 22 is_reused_(false), | 20 is_reused_(false), |
| 23 ALLOW_THIS_IN_INITIALIZER_LIST(callback_( | 21 ALLOW_THIS_IN_INITIALIZER_LIST(callback_( |
| 24 base::Bind(&ClientSocketHandle::OnIOComplete, | 22 base::Bind(&ClientSocketHandle::OnIOComplete, |
| 25 base::Unretained(this)))), | 23 base::Unretained(this)))), |
| 26 is_ssl_error_(false) {} | 24 is_ssl_error_(false) {} |
| 27 | 25 |
| 28 ClientSocketHandle::~ClientSocketHandle() { | 26 ClientSocketHandle::~ClientSocketHandle() { |
| 29 Reset(); | 27 Reset(); |
| 30 } | 28 } |
| 31 | 29 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 47 pool_->ReleaseSocket(group_name_, release_socket(), pool_id_); | 45 pool_->ReleaseSocket(group_name_, release_socket(), pool_id_); |
| 48 } else if (cancel) { | 46 } else if (cancel) { |
| 49 // If we did not get initialized yet, we've got a socket request pending. | 47 // If we did not get initialized yet, we've got a socket request pending. |
| 50 // Cancel it. | 48 // Cancel it. |
| 51 pool_->CancelRequest(group_name_, this); | 49 pool_->CancelRequest(group_name_, this); |
| 52 } | 50 } |
| 53 is_initialized_ = false; | 51 is_initialized_ = false; |
| 54 group_name_.clear(); | 52 group_name_.clear(); |
| 55 is_reused_ = false; | 53 is_reused_ = false; |
| 56 user_callback_.Reset(); | 54 user_callback_.Reset(); |
| 57 if (layered_pool_) { | |
| 58 pool_->RemoveLayeredPool(layered_pool_); | |
| 59 layered_pool_ = NULL; | |
| 60 } | |
| 61 pool_ = NULL; | 55 pool_ = NULL; |
| 62 idle_time_ = base::TimeDelta(); | 56 idle_time_ = base::TimeDelta(); |
| 63 init_time_ = base::TimeTicks(); | 57 init_time_ = base::TimeTicks(); |
| 64 setup_time_ = base::TimeDelta(); | 58 setup_time_ = base::TimeDelta(); |
| 65 pool_id_ = -1; | 59 pool_id_ = -1; |
| 66 } | 60 } |
| 67 | 61 |
| 68 void ClientSocketHandle::ResetErrorState() { | 62 void ClientSocketHandle::ResetErrorState() { |
| 69 is_ssl_error_ = false; | 63 is_ssl_error_ = false; |
| 70 ssl_error_response_info_ = HttpResponseInfo(); | 64 ssl_error_response_info_ = HttpResponseInfo(); |
| 71 pending_http_proxy_connection_.reset(); | 65 pending_http_proxy_connection_.reset(); |
| 72 } | 66 } |
| 73 | 67 |
| 74 LoadState ClientSocketHandle::GetLoadState() const { | 68 LoadState ClientSocketHandle::GetLoadState() const { |
| 75 CHECK(!is_initialized()); | 69 CHECK(!is_initialized()); |
| 76 CHECK(!group_name_.empty()); | 70 CHECK(!group_name_.empty()); |
| 77 // Because of http://crbug.com/37810 we may not have a pool, but have | 71 // Because of http://crbug.com/37810 we may not have a pool, but have |
| 78 // just a raw socket. | 72 // just a raw socket. |
| 79 if (!pool_) | 73 if (!pool_) |
| 80 return LOAD_STATE_IDLE; | 74 return LOAD_STATE_IDLE; |
| 81 return pool_->GetLoadState(group_name_, this); | 75 return pool_->GetLoadState(group_name_, this); |
| 82 } | 76 } |
| 83 | 77 |
| 84 bool ClientSocketHandle::IsPoolStalled() const { | |
| 85 return pool_->IsStalled(); | |
| 86 } | |
| 87 | |
| 88 void ClientSocketHandle::AddLayeredPool(LayeredPool* layered_pool) { | |
| 89 CHECK(layered_pool); | |
| 90 CHECK(!layered_pool_); | |
| 91 if (pool_) { | |
| 92 pool_->AddLayeredPool(layered_pool); | |
| 93 layered_pool_ = layered_pool; | |
| 94 } | |
| 95 } | |
| 96 | |
| 97 void ClientSocketHandle::OnIOComplete(int result) { | 78 void ClientSocketHandle::OnIOComplete(int result) { |
| 98 CompletionCallback callback = user_callback_; | 79 CompletionCallback callback = user_callback_; |
| 99 user_callback_.Reset(); | 80 user_callback_.Reset(); |
| 100 HandleInitCompletion(result); | 81 HandleInitCompletion(result); |
| 101 callback.Run(result); | 82 callback.Run(result); |
| 102 } | 83 } |
| 103 | 84 |
| 104 void ClientSocketHandle::HandleInitCompletion(int result) { | 85 void ClientSocketHandle::HandleInitCompletion(int result) { |
| 105 CHECK_NE(ERR_IO_PENDING, result); | 86 CHECK_NE(ERR_IO_PENDING, result); |
| 106 if (result != OK) { | 87 if (result != OK) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 136 // release() socket. It ends up working though, since those methods are being | 117 // release() socket. It ends up working though, since those methods are being |
| 137 // used to layer sockets (and the destination sources are the same). | 118 // used to layer sockets (and the destination sources are the same). |
| 138 DCHECK(socket_.get()); | 119 DCHECK(socket_.get()); |
| 139 socket_->NetLog().BeginEvent( | 120 socket_->NetLog().BeginEvent( |
| 140 NetLog::TYPE_SOCKET_IN_USE, | 121 NetLog::TYPE_SOCKET_IN_USE, |
| 141 make_scoped_refptr(new NetLogSourceParameter( | 122 make_scoped_refptr(new NetLogSourceParameter( |
| 142 "source_dependency", requesting_source_))); | 123 "source_dependency", requesting_source_))); |
| 143 } | 124 } |
| 144 | 125 |
| 145 } // namespace net | 126 } // namespace net |
| OLD | NEW |