Chromium Code Reviews| 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 "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram_macros.h" | |
| 9 #include "base/profiler/scoped_tracker.h" | 10 #include "base/profiler/scoped_tracker.h" |
| 11 #include "base/time/time.h" | |
| 10 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
| 11 #include "net/base/ip_endpoint.h" | 13 #include "net/base/ip_endpoint.h" |
| 12 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 13 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
| 14 | 16 |
| 15 namespace net { | 17 namespace net { |
| 16 | 18 |
| 17 TCPClientSocket::TCPClientSocket(const AddressList& addresses, | 19 TCPClientSocket::TCPClientSocket(const AddressList& addresses, |
| 18 net::NetLog* net_log, | 20 net::NetLog* net_log, |
| 19 const net::NetLog::Source& source) | 21 const net::NetLog::Source& source) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 31 current_address_index_(0), | 33 current_address_index_(0), |
| 32 next_connect_state_(CONNECT_STATE_NONE), | 34 next_connect_state_(CONNECT_STATE_NONE), |
| 33 previously_disconnected_(false) { | 35 previously_disconnected_(false) { |
| 34 DCHECK(socket_); | 36 DCHECK(socket_); |
| 35 | 37 |
| 36 socket_->SetDefaultOptionsForClient(); | 38 socket_->SetDefaultOptionsForClient(); |
| 37 use_history_.set_was_ever_connected(); | 39 use_history_.set_was_ever_connected(); |
| 38 } | 40 } |
| 39 | 41 |
| 40 TCPClientSocket::~TCPClientSocket() { | 42 TCPClientSocket::~TCPClientSocket() { |
| 43 EmitTCPMetricsHistogramsOnSocketClose(); | |
| 41 } | 44 } |
| 42 | 45 |
| 43 int TCPClientSocket::Bind(const IPEndPoint& address) { | 46 int TCPClientSocket::Bind(const IPEndPoint& address) { |
| 44 if (current_address_index_ >= 0 || bind_address_) { | 47 if (current_address_index_ >= 0 || bind_address_) { |
| 45 // Cannot bind the socket if we are already connected or connecting. | 48 // Cannot bind the socket if we are already connected or connecting. |
| 46 NOTREACHED(); | 49 NOTREACHED(); |
| 47 return ERR_UNEXPECTED; | 50 return ERR_UNEXPECTED; |
| 48 } | 51 } |
| 49 | 52 |
| 50 int result = OK; | 53 int result = OK; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 next_connect_state_ = CONNECT_STATE_CONNECT; | 174 next_connect_state_ = CONNECT_STATE_CONNECT; |
| 172 ++current_address_index_; | 175 ++current_address_index_; |
| 173 return OK; | 176 return OK; |
| 174 } | 177 } |
| 175 | 178 |
| 176 // Otherwise there is nothing to fall back to, so give up. | 179 // Otherwise there is nothing to fall back to, so give up. |
| 177 return result; | 180 return result; |
| 178 } | 181 } |
| 179 | 182 |
| 180 void TCPClientSocket::Disconnect() { | 183 void TCPClientSocket::Disconnect() { |
| 184 EmitTCPMetricsHistogramsOnSocketClose(); | |
|
mmenke
2015/07/07 19:53:49
Suggest a couple things:
1) Rename this to EmitTC
Bryan McQuade
2015/07/07 21:03:32
I changed to EmitTCPMetricsHistogramsOnDisconnect.
| |
| 181 DoDisconnect(); | 185 DoDisconnect(); |
| 182 current_address_index_ = -1; | 186 current_address_index_ = -1; |
| 183 bind_address_.reset(); | 187 bind_address_.reset(); |
| 184 } | 188 } |
| 185 | 189 |
| 186 void TCPClientSocket::DoDisconnect() { | 190 void TCPClientSocket::DoDisconnect() { |
| 187 // If connecting or already connected, record that the socket has been | 191 // If connecting or already connected, record that the socket has been |
| 188 // disconnected. | 192 // disconnected. |
| 189 previously_disconnected_ = socket_->IsValid() && current_address_index_ >= 0; | 193 previously_disconnected_ = socket_->IsValid() && current_address_index_ >= 0; |
| 190 socket_->Close(); | 194 socket_->Close(); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 | 347 |
| 344 int result = socket_->Open(family); | 348 int result = socket_->Open(family); |
| 345 if (result != OK) | 349 if (result != OK) |
| 346 return result; | 350 return result; |
| 347 | 351 |
| 348 socket_->SetDefaultOptionsForClient(); | 352 socket_->SetDefaultOptionsForClient(); |
| 349 | 353 |
| 350 return OK; | 354 return OK; |
| 351 } | 355 } |
| 352 | 356 |
| 357 void TCPClientSocket::EmitTCPMetricsHistogramsOnSocketClose() { | |
| 358 if (previously_disconnected_) { | |
|
Alexei Svitkine (slow)
2015/07/07 18:50:56
Nit: No {}'s for 1-line bodies.
Bryan McQuade
2015/07/07 19:35:13
Done.
mmenke
2015/07/07 19:53:49
Is this needed? Seems weird to exclude the second
Bryan McQuade
2015/07/07 21:03:32
Removed.
| |
| 359 return; | |
| 360 } | |
| 361 base::TimeDelta rtt; | |
| 362 if (socket_ && socket_->GetEstimatedRoundTripTime(&rtt)) { | |
|
mmenke
2015/07/07 19:53:49
socket_ can't be NULL (It's set to a non-NULL valu
Bryan McQuade
2015/07/07 21:03:32
Done.
| |
| 363 UMA_HISTOGRAM_CUSTOM_TIMES("Net.TcpRttAtSocketClose", rtt, | |
|
Alexei Svitkine (slow)
2015/07/07 18:50:56
Nit: Optional suggestion:
Rename to Net.TcpRtt.At
Bryan McQuade
2015/07/07 19:35:13
Great suggestion, thanks! Done.
| |
| 364 base::TimeDelta::FromMilliseconds(1), | |
| 365 base::TimeDelta::FromMinutes(10), 100); | |
|
Alexei Svitkine (slow)
2015/07/07 18:50:56
Nit: Why do you need 100 buckets instead of the us
Bryan McQuade
2015/07/07 19:35:13
I chose this bucketing strategy to match the simil
| |
| 366 } | |
| 367 } | |
| 368 | |
| 353 } // namespace net | 369 } // namespace net |
| OLD | NEW |