| OLD | NEW |
| 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/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, |
| 24 base::TickClock* tick_clock) |
| 22 : protocol_(protocol), | 25 : protocol_(protocol), |
| 23 task_runner_(std::move(task_runner)), | 26 task_runner_(std::move(task_runner)), |
| 24 updated_rtt_observation_callback_(updated_rtt_observation_callback) {} | 27 updated_rtt_observation_callback_(updated_rtt_observation_callback), |
| 28 rtt_notifications_minimum_interval_(min_notification_interval), |
| 29 tick_clock_(tick_clock) { |
| 30 DCHECK(tick_clock_); |
| 31 } |
| 25 | 32 |
| 26 SocketWatcher::~SocketWatcher() {} | 33 SocketWatcher::~SocketWatcher() {} |
| 27 | 34 |
| 28 bool SocketWatcher::ShouldNotifyUpdatedRTT() const { | 35 bool SocketWatcher::ShouldNotifyUpdatedRTT() const { |
| 29 DCHECK(thread_checker_.CalledOnValidThread()); | 36 DCHECK(thread_checker_.CalledOnValidThread()); |
| 30 | 37 |
| 31 return true; | 38 // Do not allow incoming notifications if the last notification was more |
| 39 // recent than |rtt_notifications_minimum_interval_| ago. This helps in |
| 40 // reducing the overhead of obtaining the RTT values. |
| 41 return tick_clock_->NowTicks() - last_rtt_notification_ >= |
| 42 rtt_notifications_minimum_interval_; |
| 32 } | 43 } |
| 33 | 44 |
| 34 void SocketWatcher::OnUpdatedRTTAvailable(const base::TimeDelta& rtt) { | 45 void SocketWatcher::OnUpdatedRTTAvailable(const base::TimeDelta& rtt) { |
| 35 DCHECK(thread_checker_.CalledOnValidThread()); | 46 DCHECK(thread_checker_.CalledOnValidThread()); |
| 36 | 47 |
| 48 last_rtt_notification_ = tick_clock_->NowTicks(); |
| 37 task_runner_->PostTask( | 49 task_runner_->PostTask( |
| 38 FROM_HERE, base::Bind(updated_rtt_observation_callback_, protocol_, rtt)); | 50 FROM_HERE, base::Bind(updated_rtt_observation_callback_, protocol_, rtt)); |
| 39 } | 51 } |
| 40 | 52 |
| 41 void SocketWatcher::OnConnectionChanged() { | 53 void SocketWatcher::OnConnectionChanged() { |
| 42 DCHECK(thread_checker_.CalledOnValidThread()); | 54 DCHECK(thread_checker_.CalledOnValidThread()); |
| 43 } | 55 } |
| 44 | 56 |
| 45 } // namespace internal | 57 } // namespace internal |
| 46 | 58 |
| 47 } // namespace nqe | 59 } // namespace nqe |
| 48 | 60 |
| 49 } // namespace net | 61 } // namespace net |
| OLD | NEW |