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