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

Side by Side Diff: net/nqe/socket_watcher.cc

Issue 2690113004: Throttle Socket watcher RTT notifications from QUIC (Closed)
Patch Set: ps Created 3 years, 10 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/nqe/socket_watcher.h" 5 #include "net/nqe/socket_watcher.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/time/default_tick_clock.h"
10 #include "base/time/time.h" 11 #include "base/time/time.h"
11 12
12 namespace net { 13 namespace net {
13 14
14 namespace nqe { 15 namespace nqe {
15 16
16 namespace internal { 17 namespace internal {
17 18
18 SocketWatcher::SocketWatcher( 19 SocketWatcher::SocketWatcher(
19 SocketPerformanceWatcherFactory::Protocol protocol, 20 SocketPerformanceWatcherFactory::Protocol protocol,
21 base::TimeDelta min_notification_interval,
20 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 22 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
21 OnUpdatedRTTAvailableCallback updated_rtt_observation_callback) 23 OnUpdatedRTTAvailableCallback updated_rtt_observation_callback)
22 : protocol_(protocol), 24 : protocol_(protocol),
23 task_runner_(std::move(task_runner)), 25 task_runner_(std::move(task_runner)),
24 updated_rtt_observation_callback_(updated_rtt_observation_callback) {} 26 updated_rtt_observation_callback_(updated_rtt_observation_callback),
27 rtt_notifications_minimum_interval_(min_notification_interval),
28 tick_clock_(new base::DefaultTickClock()) {}
25 29
26 SocketWatcher::~SocketWatcher() {} 30 SocketWatcher::~SocketWatcher() {}
27 31
28 bool SocketWatcher::ShouldNotifyUpdatedRTT() const { 32 bool SocketWatcher::ShouldNotifyUpdatedRTT() const {
29 DCHECK(thread_checker_.CalledOnValidThread()); 33 DCHECK(thread_checker_.CalledOnValidThread());
30 34
31 return true; 35 // Do not allow incoming notifications if the last notification was recent
RyanSturm 2017/02/15 17:42:08 nit:s/was recent than/was more recent than/
tbansal1 2017/02/15 20:37:42 Done.
36 // than |rtt_notifications_minimum_interval_| ago. This helps in reducing the
37 // overhead of obtaining the RTT values.
38 return tick_clock_->NowTicks() - last_rtt_notification_ >=
39 rtt_notifications_minimum_interval_;
32 } 40 }
33 41
34 void SocketWatcher::OnUpdatedRTTAvailable(const base::TimeDelta& rtt) { 42 void SocketWatcher::OnUpdatedRTTAvailable(const base::TimeDelta& rtt) {
35 DCHECK(thread_checker_.CalledOnValidThread()); 43 DCHECK(thread_checker_.CalledOnValidThread());
36 44
45 last_rtt_notification_ = tick_clock_->NowTicks();
37 task_runner_->PostTask( 46 task_runner_->PostTask(
38 FROM_HERE, base::Bind(updated_rtt_observation_callback_, protocol_, rtt)); 47 FROM_HERE, base::Bind(updated_rtt_observation_callback_, protocol_, rtt));
39 } 48 }
40 49
41 void SocketWatcher::OnConnectionChanged() { 50 void SocketWatcher::OnConnectionChanged() {
42 DCHECK(thread_checker_.CalledOnValidThread()); 51 DCHECK(thread_checker_.CalledOnValidThread());
43 } 52 }
44 53
54 void SocketWatcher::SetTickClockForTesting(
55 std::unique_ptr<base::TickClock> tick_clock) {
56 DCHECK(thread_checker_.CalledOnValidThread());
57
58 tick_clock_ = std::move(tick_clock);
59 }
60
45 } // namespace internal 61 } // namespace internal
46 62
47 } // namespace nqe 63 } // namespace nqe
48 64
49 } // namespace net 65 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698