| Index: net/base/socket_performance_watcher.cc
|
| diff --git a/net/base/socket_performance_watcher.cc b/net/base/socket_performance_watcher.cc
|
| index aa0dab3b03c9476a8d099bde13e15e9b65668850..81bf4e8cc66b5c679e5057e64e6165a2f299fa38 100644
|
| --- a/net/base/socket_performance_watcher.cc
|
| +++ b/net/base/socket_performance_watcher.cc
|
| @@ -4,16 +4,24 @@
|
|
|
| #include "net/base/socket_performance_watcher.h"
|
|
|
| +#include "base/bind.h"
|
| +#include "base/location.h"
|
| #include "base/logging.h"
|
| +#include "base/single_thread_task_runner.h"
|
|
|
| namespace net {
|
|
|
| SocketPerformanceWatcher::SocketPerformanceWatcher(
|
| const SocketPerformanceWatcherFactory::Protocol protocol,
|
| - SocketPerformanceWatcherFactory* socket_performance_watcher_factory)
|
| + const base::WeakPtr<SocketPerformanceWatcherFactory>&
|
| + socket_performance_watcher_factory,
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
|
| : protocol_(protocol),
|
| - socket_performance_watcher_factory_(socket_performance_watcher_factory) {
|
| - DCHECK(socket_performance_watcher_factory_);
|
| + rtt_notification_received_count_(0),
|
| + socket_performance_watcher_factory_(socket_performance_watcher_factory),
|
| + task_runner_(task_runner),
|
| + weak_ptr_factory_(this) {
|
| + DCHECK(task_runner_);
|
|
|
| switch (protocol) {
|
| case SocketPerformanceWatcherFactory::PROTOCOL_TCP:
|
| @@ -27,8 +35,42 @@ SocketPerformanceWatcher::SocketPerformanceWatcher(
|
| SocketPerformanceWatcher::~SocketPerformanceWatcher() {}
|
|
|
| void SocketPerformanceWatcher::OnUpdatedRTTAvailable(
|
| - const base::TimeDelta& rtt) const {
|
| - socket_performance_watcher_factory_->OnUpdatedRTTAvailable(protocol_, rtt);
|
| + const base::TimeDelta& rtt) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| +
|
| + rtt_notification_received_count_++;
|
| +
|
| + task_runner_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&SocketPerformanceWatcherFactory::OnUpdatedRTTAvailable,
|
| + socket_performance_watcher_factory_, protocol_, rtt));
|
| +}
|
| +
|
| +bool SocketPerformanceWatcher::ShouldNotifyUpdatedRTT() const {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| +
|
| + // Currently using a small value until crbug.com/590300 is fixed. TCP/QUIC
|
| + // start with a hard-coded RTT estimate, and converge to a more accurate value
|
| + // as more packets are received. This means that SPW should receive frequent
|
| + // RTT notifications when the TCP/QUIC connection has just started, and less
|
| + // frequent notification afterwards.
|
| + return rtt_notification_received_count_ < 1;
|
| +}
|
| +
|
| +void SocketPerformanceWatcher::Reset() {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| +
|
| + rtt_notification_received_count_ = 0;
|
| +
|
| + task_runner_->PostTask(
|
| + FROM_HERE, base::Bind(&SocketPerformanceWatcherFactory::OnWatcherReset,
|
| + socket_performance_watcher_factory_));
|
| +}
|
| +
|
| +base::WeakPtr<SocketPerformanceWatcher> SocketPerformanceWatcher::GetWeakPtr() {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| +
|
| + return weak_ptr_factory_.GetWeakPtr();
|
| }
|
|
|
| } // namespace net
|
|
|