| Index: net/nqe/socket_watcher.cc
|
| diff --git a/net/nqe/socket_watcher.cc b/net/nqe/socket_watcher.cc
|
| index d03b98ecf8193a91fefb449d766b7fa352e4b61b..174c388a216c27512673eaec45c32b5eb28d7716 100644
|
| --- a/net/nqe/socket_watcher.cc
|
| +++ b/net/nqe/socket_watcher.cc
|
| @@ -7,6 +7,7 @@
|
| #include "base/bind.h"
|
| #include "base/location.h"
|
| #include "base/single_thread_task_runner.h"
|
| +#include "base/time/tick_clock.h"
|
| #include "base/time/time.h"
|
|
|
| namespace net {
|
| @@ -17,23 +18,34 @@ namespace internal {
|
|
|
| SocketWatcher::SocketWatcher(
|
| SocketPerformanceWatcherFactory::Protocol protocol,
|
| + base::TimeDelta min_notification_interval,
|
| scoped_refptr<base::SingleThreadTaskRunner> task_runner,
|
| - OnUpdatedRTTAvailableCallback updated_rtt_observation_callback)
|
| + OnUpdatedRTTAvailableCallback updated_rtt_observation_callback,
|
| + base::TickClock* tick_clock)
|
| : protocol_(protocol),
|
| task_runner_(std::move(task_runner)),
|
| - updated_rtt_observation_callback_(updated_rtt_observation_callback) {}
|
| + updated_rtt_observation_callback_(updated_rtt_observation_callback),
|
| + rtt_notifications_minimum_interval_(min_notification_interval),
|
| + tick_clock_(tick_clock) {
|
| + DCHECK(tick_clock_);
|
| +}
|
|
|
| SocketWatcher::~SocketWatcher() {}
|
|
|
| bool SocketWatcher::ShouldNotifyUpdatedRTT() const {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| - return true;
|
| + // Do not allow incoming notifications if the last notification was more
|
| + // recent than |rtt_notifications_minimum_interval_| ago. This helps in
|
| + // reducing the overhead of obtaining the RTT values.
|
| + return tick_clock_->NowTicks() - last_rtt_notification_ >=
|
| + rtt_notifications_minimum_interval_;
|
| }
|
|
|
| void SocketWatcher::OnUpdatedRTTAvailable(const base::TimeDelta& rtt) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| + last_rtt_notification_ = tick_clock_->NowTicks();
|
| task_runner_->PostTask(
|
| FROM_HERE, base::Bind(updated_rtt_observation_callback_, protocol_, rtt));
|
| }
|
|
|