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

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: Added throttle on TCP socket notifications (with tests) Created 4 years, 8 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/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),
Ryan Sleevi 2016/04/11 22:06:55 This is an intrinsically dangerous pattern (the .g
tbansal1 2016/04/12 16:14:33 I agree. I am not sure what's the best approach he
Ryan Sleevi 2016/04/12 21:08:31 Friending is almost always the wrong decision. Cer
tbansal1 2016/04/12 22:39:19 Acknowledged.
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),
35 notify_reset_socket_performance_watcher_(false) {}
29 36
30 TCPClientSocket::TCPClientSocket(scoped_ptr<TCPSocket> connected_socket, 37 TCPClientSocket::TCPClientSocket(scoped_ptr<TCPSocket> connected_socket,
31 const IPEndPoint& peer_address) 38 const IPEndPoint& peer_address)
32 : socket_(std::move(connected_socket)), 39 : socket_performance_watcher_(nullptr),
40 socket_(std::move(connected_socket)),
33 addresses_(AddressList(peer_address)), 41 addresses_(AddressList(peer_address)),
34 current_address_index_(0), 42 current_address_index_(0),
35 next_connect_state_(CONNECT_STATE_NONE), 43 next_connect_state_(CONNECT_STATE_NONE),
36 previously_disconnected_(false), 44 previously_disconnected_(false),
37 total_received_bytes_(0) { 45 total_received_bytes_(0),
46 notify_reset_socket_performance_watcher_(false) {
Ryan Sleevi 2016/04/11 22:06:56 This is really just is_first_connection_ isn't it
tbansal1 2016/04/12 16:14:33 Removed the variable.
38 DCHECK(socket_); 47 DCHECK(socket_);
39 48
40 socket_->SetDefaultOptionsForClient(); 49 socket_->SetDefaultOptionsForClient();
41 use_history_.set_was_ever_connected(); 50 use_history_.set_was_ever_connected();
42 } 51 }
43 52
44 TCPClientSocket::~TCPClientSocket() { 53 TCPClientSocket::~TCPClientSocket() {
45 Disconnect(); 54 Disconnect();
46 } 55 }
47 56
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 if (bind_address_) { 154 if (bind_address_) {
146 result = socket_->Bind(*bind_address_); 155 result = socket_->Bind(*bind_address_);
147 if (result != OK) { 156 if (result != OK) {
148 socket_->Close(); 157 socket_->Close();
149 return result; 158 return result;
150 } 159 }
151 } 160 }
152 } 161 }
153 } 162 }
154 163
164 if (socket_performance_watcher_ && notify_reset_socket_performance_watcher_)
165 socket_performance_watcher_->OnConnectionChanged();
166
155 // |socket_| is owned by this class and the callback won't be run once 167 // |socket_| is owned by this class and the callback won't be run once
156 // |socket_| is gone. Therefore, it is safe to use base::Unretained() here. 168 // |socket_| is gone. Therefore, it is safe to use base::Unretained() here.
157 return socket_->Connect(endpoint, 169 return socket_->Connect(endpoint,
158 base::Bind(&TCPClientSocket::DidCompleteConnect, 170 base::Bind(&TCPClientSocket::DidCompleteConnect,
159 base::Unretained(this))); 171 base::Unretained(this)));
160 } 172 }
161 173
162 int TCPClientSocket::DoConnectComplete(int result) { 174 int TCPClientSocket::DoConnectComplete(int result) {
163 if (result == OK) { 175 if (result == OK) {
164 use_history_.set_was_ever_connected(); 176 use_history_.set_was_ever_connected();
(...skipping 23 matching lines...) Expand all
188 bind_address_.reset(); 200 bind_address_.reset();
189 } 201 }
190 202
191 void TCPClientSocket::DoDisconnect() { 203 void TCPClientSocket::DoDisconnect() {
192 total_received_bytes_ = 0; 204 total_received_bytes_ = 0;
193 EmitTCPMetricsHistogramsOnDisconnect(); 205 EmitTCPMetricsHistogramsOnDisconnect();
194 // If connecting or already connected, record that the socket has been 206 // If connecting or already connected, record that the socket has been
195 // disconnected. 207 // disconnected.
196 previously_disconnected_ = socket_->IsValid() && current_address_index_ >= 0; 208 previously_disconnected_ = socket_->IsValid() && current_address_index_ >= 0;
197 socket_->Close(); 209 socket_->Close();
210 notify_reset_socket_performance_watcher_ = true;
198 } 211 }
199 212
200 bool TCPClientSocket::IsConnected() const { 213 bool TCPClientSocket::IsConnected() const {
201 return socket_->IsConnected(); 214 return socket_->IsConnected();
202 } 215 }
203 216
204 bool TCPClientSocket::IsConnectedAndIdle() const { 217 bool TCPClientSocket::IsConnectedAndIdle() const {
205 return socket_->IsConnectedAndIdle(); 218 return socket_->IsConnectedAndIdle();
206 } 219 }
207 220
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 void TCPClientSocket::EmitTCPMetricsHistogramsOnDisconnect() { 388 void TCPClientSocket::EmitTCPMetricsHistogramsOnDisconnect() {
376 base::TimeDelta rtt; 389 base::TimeDelta rtt;
377 if (socket_->GetEstimatedRoundTripTime(&rtt)) { 390 if (socket_->GetEstimatedRoundTripTime(&rtt)) {
378 UMA_HISTOGRAM_CUSTOM_TIMES("Net.TcpRtt.AtDisconnect", rtt, 391 UMA_HISTOGRAM_CUSTOM_TIMES("Net.TcpRtt.AtDisconnect", rtt,
379 base::TimeDelta::FromMilliseconds(1), 392 base::TimeDelta::FromMilliseconds(1),
380 base::TimeDelta::FromMinutes(10), 100); 393 base::TimeDelta::FromMinutes(10), 100);
381 } 394 }
382 } 395 }
383 396
384 } // namespace net 397 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698