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 if (pool_) { | 91 if (pool_) { |
92 pool_->AddLayeredPool(layered_pool); | 92 pool_->AddHigherLayeredPool(higher_pool); |
93 layered_pool_ = layered_pool; | 93 higher_pool_ = higher_pool; |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 void ClientSocketHandle::RemoveLayeredPool(LayeredPool* layered_pool) { | 97 void ClientSocketHandle::RemoveHigherLayeredPool( |
98 CHECK(layered_pool); | 98 HigherLayeredPool* higher_pool) { |
99 CHECK(layered_pool_); | 99 CHECK(higher_pool_); |
| 100 CHECK_EQ(higher_pool_, higher_pool); |
100 if (pool_) { | 101 if (pool_) { |
101 pool_->RemoveLayeredPool(layered_pool); | 102 pool_->RemoveHigherLayeredPool(higher_pool); |
102 layered_pool_ = NULL; | 103 higher_pool_ = NULL; |
103 } | 104 } |
104 } | 105 } |
105 | 106 |
106 bool ClientSocketHandle::GetLoadTimingInfo( | 107 bool ClientSocketHandle::GetLoadTimingInfo( |
107 bool is_reused, | 108 bool is_reused, |
108 LoadTimingInfo* load_timing_info) const { | 109 LoadTimingInfo* load_timing_info) const { |
109 // Only return load timing information when there's a socket. | 110 // Only return load timing information when there's a socket. |
110 if (!socket_) | 111 if (!socket_) |
111 return false; | 112 return false; |
112 | 113 |
(...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 | 172 // 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 | 173 // release() socket. It ends up working though, since those methods are being |
173 // used to layer sockets (and the destination sources are the same). | 174 // used to layer sockets (and the destination sources are the same). |
174 DCHECK(socket_.get()); | 175 DCHECK(socket_.get()); |
175 socket_->NetLog().BeginEvent( | 176 socket_->NetLog().BeginEvent( |
176 NetLog::TYPE_SOCKET_IN_USE, | 177 NetLog::TYPE_SOCKET_IN_USE, |
177 requesting_source_.ToEventParametersCallback()); | 178 requesting_source_.ToEventParametersCallback()); |
178 } | 179 } |
179 | 180 |
180 } // namespace net | 181 } // namespace net |
OLD | NEW |