Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: net/socket/tcp_client_socket.cc

Issue 1376473003: Notify NQE of TCP RTT values (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed rsleevi comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/net_util.h" 17 #include "net/base/net_util.h"
18 #include "net/base/socket_performance_watcher.h"
18 19
19 namespace net { 20 namespace net {
20 21
21 TCPClientSocket::TCPClientSocket(const AddressList& addresses, 22 TCPClientSocket::TCPClientSocket(
22 net::NetLog* net_log, 23 const AddressList& addresses,
23 const net::NetLog::Source& source) 24 scoped_ptr<SocketPerformanceWatcher> socket_performance_watcher,
24 : socket_(new TCPSocket(net_log, source)), 25 net::NetLog* net_log,
26 const net::NetLog::Source& source)
27 : socket_performance_watcher_(socket_performance_watcher.get()),
28 socket_(new TCPSocket(std::move(socket_performance_watcher),
29 net_log,
30 source)),
25 addresses_(addresses), 31 addresses_(addresses),
26 current_address_index_(-1), 32 current_address_index_(-1),
27 next_connect_state_(CONNECT_STATE_NONE), 33 next_connect_state_(CONNECT_STATE_NONE),
28 previously_disconnected_(false), 34 previously_disconnected_(false),
29 total_received_bytes_(0) {} 35 total_received_bytes_(0) {}
30 36
31 TCPClientSocket::TCPClientSocket(scoped_ptr<TCPSocket> connected_socket, 37 TCPClientSocket::TCPClientSocket(scoped_ptr<TCPSocket> connected_socket,
32 const IPEndPoint& peer_address) 38 const IPEndPoint& peer_address)
33 : socket_(std::move(connected_socket)), 39 : socket_performance_watcher_(nullptr),
40 socket_(std::move(connected_socket)),
34 addresses_(AddressList(peer_address)), 41 addresses_(AddressList(peer_address)),
35 current_address_index_(0), 42 current_address_index_(0),
36 next_connect_state_(CONNECT_STATE_NONE), 43 next_connect_state_(CONNECT_STATE_NONE),
37 previously_disconnected_(false), 44 previously_disconnected_(false),
38 total_received_bytes_(0) { 45 total_received_bytes_(0) {
39 DCHECK(socket_); 46 DCHECK(socket_);
40 47
41 socket_->SetDefaultOptionsForClient(); 48 socket_->SetDefaultOptionsForClient();
42 use_history_.set_was_ever_connected(); 49 use_history_.set_was_ever_connected();
43 } 50 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 bind_address_.reset(); 196 bind_address_.reset();
190 } 197 }
191 198
192 void TCPClientSocket::DoDisconnect() { 199 void TCPClientSocket::DoDisconnect() {
193 total_received_bytes_ = 0; 200 total_received_bytes_ = 0;
194 EmitTCPMetricsHistogramsOnDisconnect(); 201 EmitTCPMetricsHistogramsOnDisconnect();
195 // If connecting or already connected, record that the socket has been 202 // If connecting or already connected, record that the socket has been
196 // disconnected. 203 // disconnected.
197 previously_disconnected_ = socket_->IsValid() && current_address_index_ >= 0; 204 previously_disconnected_ = socket_->IsValid() && current_address_index_ >= 0;
198 socket_->Close(); 205 socket_->Close();
206 if (socket_performance_watcher_)
207 socket_performance_watcher_->Reset();
199 } 208 }
200 209
201 bool TCPClientSocket::IsConnected() const { 210 bool TCPClientSocket::IsConnected() const {
202 return socket_->IsConnected(); 211 return socket_->IsConnected();
203 } 212 }
204 213
205 bool TCPClientSocket::IsConnectedAndIdle() const { 214 bool TCPClientSocket::IsConnectedAndIdle() const {
206 return socket_->IsConnectedAndIdle(); 215 return socket_->IsConnectedAndIdle();
207 } 216 }
208 217
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 void TCPClientSocket::EmitTCPMetricsHistogramsOnDisconnect() { 389 void TCPClientSocket::EmitTCPMetricsHistogramsOnDisconnect() {
381 base::TimeDelta rtt; 390 base::TimeDelta rtt;
382 if (socket_->GetEstimatedRoundTripTime(&rtt)) { 391 if (socket_->GetEstimatedRoundTripTime(&rtt)) {
383 UMA_HISTOGRAM_CUSTOM_TIMES("Net.TcpRtt.AtDisconnect", rtt, 392 UMA_HISTOGRAM_CUSTOM_TIMES("Net.TcpRtt.AtDisconnect", rtt,
384 base::TimeDelta::FromMilliseconds(1), 393 base::TimeDelta::FromMilliseconds(1),
385 base::TimeDelta::FromMinutes(10), 100); 394 base::TimeDelta::FromMinutes(10), 100);
386 } 395 }
387 } 396 }
388 397
389 } // namespace net 398 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698