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

Side by Side Diff: net/base/socket_performance_watcher.cc

Issue 1831383002: Add SocketWatcherFactory as a helper class to NQE (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased, removed cyclic dependency between SPWF and SPW 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/base/socket_performance_watcher.h" 5 #include "net/base/socket_performance_watcher.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace net { 9 namespace net {
10 10
11 SocketPerformanceWatcher::SocketPerformanceWatcher( 11 SocketPerformanceWatcher::SocketPerformanceWatcher(
12 const SocketPerformanceWatcherFactory::Protocol protocol, 12 SocketPerformanceWatcherFactory::Protocol protocol,
13 SocketPerformanceWatcherFactory* socket_performance_watcher_factory) 13 const RTTCallback& rtt_callback,
14 const ResetCallback& reset_callback)
14 : protocol_(protocol), 15 : protocol_(protocol),
15 socket_performance_watcher_factory_(socket_performance_watcher_factory) { 16 rtt_notification_received_count_(0),
16 DCHECK(socket_performance_watcher_factory_); 17 rtt_callback_(rtt_callback),
17 18 reset_callback_(reset_callback) {
18 switch (protocol) { 19 switch (protocol) {
19 case SocketPerformanceWatcherFactory::PROTOCOL_TCP: 20 case SocketPerformanceWatcherFactory::PROTOCOL_TCP:
20 case SocketPerformanceWatcherFactory::PROTOCOL_QUIC: 21 case SocketPerformanceWatcherFactory::PROTOCOL_QUIC:
21 return; 22 return;
22 default: 23 default:
23 NOTREACHED(); 24 NOTREACHED();
24 } 25 }
25 } 26 }
26 27
27 SocketPerformanceWatcher::~SocketPerformanceWatcher() {} 28 SocketPerformanceWatcher::~SocketPerformanceWatcher() {}
28 29
29 void SocketPerformanceWatcher::OnUpdatedRTTAvailable( 30 void SocketPerformanceWatcher::OnUpdatedRTTAvailable(
30 const base::TimeDelta& rtt) const { 31 const base::TimeDelta& rtt) {
31 socket_performance_watcher_factory_->OnUpdatedRTTAvailable(protocol_, rtt); 32 DCHECK(thread_checker_.CalledOnValidThread());
33
34 rtt_notification_received_count_++;
35 rtt_callback_.Run(protocol_, rtt);
36 }
37
38 bool SocketPerformanceWatcher::ShouldNotifyUpdatedRTT() const {
39 DCHECK(thread_checker_.CalledOnValidThread());
40
41 // Currently using a small value until crbug.com/590300 is fixed.
42 return rtt_notification_received_count_ < 1;
43 }
44
45 void SocketPerformanceWatcher::Reset() {
46 DCHECK(thread_checker_.CalledOnValidThread());
47
48 rtt_notification_received_count_ = 0;
49 reset_callback_.Run();
32 } 50 }
33 51
34 } // namespace net 52 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698