OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/tcp_client_socket.h" | 5 #include "net/socket/tcp_client_socket.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 144 |
145 return rv; | 145 return rv; |
146 } | 146 } |
147 | 147 |
148 int TCPClientSocket::DoConnect() { | 148 int TCPClientSocket::DoConnect() { |
149 DCHECK_GE(current_address_index_, 0); | 149 DCHECK_GE(current_address_index_, 0); |
150 DCHECK_LT(current_address_index_, static_cast<int>(addresses_.size())); | 150 DCHECK_LT(current_address_index_, static_cast<int>(addresses_.size())); |
151 | 151 |
152 const IPEndPoint& endpoint = addresses_[current_address_index_]; | 152 const IPEndPoint& endpoint = addresses_[current_address_index_]; |
153 | 153 |
154 { | 154 if (previously_disconnected_) { |
155 // TODO(ricea): Remove ScopedTracker below once crbug.com/436634 is fixed. | 155 use_history_.Reset(); |
156 tracked_objects::ScopedTracker tracking_profile( | 156 connection_attempts_.clear(); |
157 FROM_HERE_WITH_EXPLICIT_FUNCTION("436634 TCPClientSocket::DoConnect")); | 157 previously_disconnected_ = false; |
| 158 } |
158 | 159 |
159 if (previously_disconnected_) { | 160 next_connect_state_ = CONNECT_STATE_CONNECT_COMPLETE; |
160 use_history_.Reset(); | |
161 connection_attempts_.clear(); | |
162 previously_disconnected_ = false; | |
163 } | |
164 | 161 |
165 next_connect_state_ = CONNECT_STATE_CONNECT_COMPLETE; | 162 if (socket_->IsValid()) { |
| 163 DCHECK(bind_address_); |
| 164 } else { |
| 165 int result = OpenSocket(endpoint.GetFamily()); |
| 166 if (result != OK) |
| 167 return result; |
166 | 168 |
167 if (socket_->IsValid()) { | 169 if (bind_address_) { |
168 DCHECK(bind_address_); | 170 result = socket_->Bind(*bind_address_); |
169 } else { | 171 if (result != OK) { |
170 int result = OpenSocket(endpoint.GetFamily()); | 172 socket_->Close(); |
171 if (result != OK) | |
172 return result; | 173 return result; |
173 | |
174 if (bind_address_) { | |
175 result = socket_->Bind(*bind_address_); | |
176 if (result != OK) { | |
177 socket_->Close(); | |
178 return result; | |
179 } | |
180 } | 174 } |
181 } | 175 } |
182 } | 176 } |
183 | 177 |
184 // Notify |socket_performance_watcher_| only if the |socket_| is reused to | 178 // Notify |socket_performance_watcher_| only if the |socket_| is reused to |
185 // connect to a different IP Address. | 179 // connect to a different IP Address. |
186 if (socket_performance_watcher_ && current_address_index_ != 0) | 180 if (socket_performance_watcher_ && current_address_index_ != 0) |
187 socket_performance_watcher_->OnConnectionChanged(); | 181 socket_performance_watcher_->OnConnectionChanged(); |
188 | 182 |
189 // |socket_| is owned by this class and the callback won't be run once | 183 // |socket_| is owned by this class and the callback won't be run once |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 void TCPClientSocket::EmitTCPMetricsHistogramsOnDisconnect() { | 397 void TCPClientSocket::EmitTCPMetricsHistogramsOnDisconnect() { |
404 base::TimeDelta rtt; | 398 base::TimeDelta rtt; |
405 if (socket_->GetEstimatedRoundTripTime(&rtt)) { | 399 if (socket_->GetEstimatedRoundTripTime(&rtt)) { |
406 UMA_HISTOGRAM_CUSTOM_TIMES("Net.TcpRtt.AtDisconnect", rtt, | 400 UMA_HISTOGRAM_CUSTOM_TIMES("Net.TcpRtt.AtDisconnect", rtt, |
407 base::TimeDelta::FromMilliseconds(1), | 401 base::TimeDelta::FromMilliseconds(1), |
408 base::TimeDelta::FromMinutes(10), 100); | 402 base::TimeDelta::FromMinutes(10), 100); |
409 } | 403 } |
410 } | 404 } |
411 | 405 |
412 } // namespace net | 406 } // namespace net |
OLD | NEW |