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" |
11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
12 #include "base/profiler/scoped_tracker.h" | 12 #include "base/profiler/scoped_tracker.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
15 #include "net/base/ip_endpoint.h" | 15 #include "net/base/ip_endpoint.h" |
16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 17 #include "net/base/socket_performance_watcher.h" |
17 | 18 |
18 namespace net { | 19 namespace net { |
19 | 20 |
20 TCPClientSocket::TCPClientSocket(const AddressList& addresses, | 21 TCPClientSocket::TCPClientSocket( |
21 net::NetLog* net_log, | 22 const AddressList& addresses, |
22 const net::NetLog::Source& source) | 23 scoped_ptr<SocketPerformanceWatcher> socket_performance_watcher, |
23 : socket_(new TCPSocket(net_log, source)), | 24 net::NetLog* net_log, |
| 25 const net::NetLog::Source& source) |
| 26 : socket_performance_watcher_(socket_performance_watcher.get()), |
| 27 socket_(new TCPSocket(std::move(socket_performance_watcher), |
| 28 net_log, |
| 29 source)), |
24 addresses_(addresses), | 30 addresses_(addresses), |
25 current_address_index_(-1), | 31 current_address_index_(-1), |
26 next_connect_state_(CONNECT_STATE_NONE), | 32 next_connect_state_(CONNECT_STATE_NONE), |
27 previously_disconnected_(false), | 33 previously_disconnected_(false), |
28 total_received_bytes_(0) {} | 34 total_received_bytes_(0) {} |
29 | 35 |
30 TCPClientSocket::TCPClientSocket(scoped_ptr<TCPSocket> connected_socket, | 36 TCPClientSocket::TCPClientSocket(scoped_ptr<TCPSocket> connected_socket, |
31 const IPEndPoint& peer_address) | 37 const IPEndPoint& peer_address) |
32 : socket_(std::move(connected_socket)), | 38 : socket_performance_watcher_(nullptr), |
| 39 socket_(std::move(connected_socket)), |
33 addresses_(AddressList(peer_address)), | 40 addresses_(AddressList(peer_address)), |
34 current_address_index_(0), | 41 current_address_index_(0), |
35 next_connect_state_(CONNECT_STATE_NONE), | 42 next_connect_state_(CONNECT_STATE_NONE), |
36 previously_disconnected_(false), | 43 previously_disconnected_(false), |
37 total_received_bytes_(0) { | 44 total_received_bytes_(0) { |
38 DCHECK(socket_); | 45 DCHECK(socket_); |
39 | 46 |
40 socket_->SetDefaultOptionsForClient(); | 47 socket_->SetDefaultOptionsForClient(); |
41 use_history_.set_was_ever_connected(); | 48 use_history_.set_was_ever_connected(); |
42 } | 49 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 bind_address_.reset(); | 195 bind_address_.reset(); |
189 } | 196 } |
190 | 197 |
191 void TCPClientSocket::DoDisconnect() { | 198 void TCPClientSocket::DoDisconnect() { |
192 total_received_bytes_ = 0; | 199 total_received_bytes_ = 0; |
193 EmitTCPMetricsHistogramsOnDisconnect(); | 200 EmitTCPMetricsHistogramsOnDisconnect(); |
194 // If connecting or already connected, record that the socket has been | 201 // If connecting or already connected, record that the socket has been |
195 // disconnected. | 202 // disconnected. |
196 previously_disconnected_ = socket_->IsValid() && current_address_index_ >= 0; | 203 previously_disconnected_ = socket_->IsValid() && current_address_index_ >= 0; |
197 socket_->Close(); | 204 socket_->Close(); |
| 205 if (socket_performance_watcher_) |
| 206 socket_performance_watcher_->Reset(); |
198 } | 207 } |
199 | 208 |
200 bool TCPClientSocket::IsConnected() const { | 209 bool TCPClientSocket::IsConnected() const { |
201 return socket_->IsConnected(); | 210 return socket_->IsConnected(); |
202 } | 211 } |
203 | 212 |
204 bool TCPClientSocket::IsConnectedAndIdle() const { | 213 bool TCPClientSocket::IsConnectedAndIdle() const { |
205 return socket_->IsConnectedAndIdle(); | 214 return socket_->IsConnectedAndIdle(); |
206 } | 215 } |
207 | 216 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 void TCPClientSocket::EmitTCPMetricsHistogramsOnDisconnect() { | 388 void TCPClientSocket::EmitTCPMetricsHistogramsOnDisconnect() { |
380 base::TimeDelta rtt; | 389 base::TimeDelta rtt; |
381 if (socket_->GetEstimatedRoundTripTime(&rtt)) { | 390 if (socket_->GetEstimatedRoundTripTime(&rtt)) { |
382 UMA_HISTOGRAM_CUSTOM_TIMES("Net.TcpRtt.AtDisconnect", rtt, | 391 UMA_HISTOGRAM_CUSTOM_TIMES("Net.TcpRtt.AtDisconnect", rtt, |
383 base::TimeDelta::FromMilliseconds(1), | 392 base::TimeDelta::FromMilliseconds(1), |
384 base::TimeDelta::FromMinutes(10), 100); | 393 base::TimeDelta::FromMinutes(10), 100); |
385 } | 394 } |
386 } | 395 } |
387 | 396 |
388 } // namespace net | 397 } // namespace net |
OLD | NEW |