| 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 #ifndef NET_NQE_SOCKET_WATCHER_H_ | 5 #ifndef NET_NQE_SOCKET_WATCHER_H_ |
| 6 #define NET_NQE_SOCKET_WATCHER_H_ | 6 #define NET_NQE_SOCKET_WATCHER_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 11 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
| 14 #include "base/time/time.h" |
| 15 #include "net/base/net_export.h" |
| 12 #include "net/socket/socket_performance_watcher.h" | 16 #include "net/socket/socket_performance_watcher.h" |
| 13 #include "net/socket/socket_performance_watcher_factory.h" | 17 #include "net/socket/socket_performance_watcher_factory.h" |
| 14 | 18 |
| 15 namespace base { | 19 namespace base { |
| 16 class SingleThreadTaskRunner; | 20 class SingleThreadTaskRunner; |
| 21 class TickClock; |
| 17 class TimeDelta; | 22 class TimeDelta; |
| 18 } // namespace base | 23 } // namespace base |
| 19 | 24 |
| 20 namespace net { | 25 namespace net { |
| 21 | 26 |
| 22 namespace { | 27 namespace { |
| 23 typedef base::Callback<void(SocketPerformanceWatcherFactory::Protocol protocol, | 28 typedef base::Callback<void(SocketPerformanceWatcherFactory::Protocol protocol, |
| 24 const base::TimeDelta& rtt)> | 29 const base::TimeDelta& rtt)> |
| 25 OnUpdatedRTTAvailableCallback; | 30 OnUpdatedRTTAvailableCallback; |
| 26 } | 31 } |
| 27 | 32 |
| 28 namespace nqe { | 33 namespace nqe { |
| 29 | 34 |
| 30 namespace internal { | 35 namespace internal { |
| 31 | 36 |
| 32 // SocketWatcher implements SocketPerformanceWatcher, and is not thread-safe. | 37 // SocketWatcher implements SocketPerformanceWatcher, and is not thread-safe. |
| 33 class SocketWatcher : public SocketPerformanceWatcher { | 38 class NET_EXPORT_PRIVATE SocketWatcher : public SocketPerformanceWatcher { |
| 34 public: | 39 public: |
| 35 // Creates a SocketWatcher which can be used to watch a socket that uses | 40 // Creates a SocketWatcher which can be used to watch a socket that uses |
| 36 // |protocol| as the transport layer protocol. The socket watcher will call | 41 // |protocol| as the transport layer protocol. The socket watcher will call |
| 37 // |updated_rtt_observation_callback| on |task_runner| every time a new RTT | 42 // |updated_rtt_observation_callback| on |task_runner| every time a new RTT |
| 38 // observation is available. | 43 // observation is available. |min_notification_interval| is the minimum |
| 44 // interval betweeen consecutive notifications to this socket watcher. |
| 45 // |tick_clock| is guaranteed to be non-null. |
| 39 SocketWatcher(SocketPerformanceWatcherFactory::Protocol protocol, | 46 SocketWatcher(SocketPerformanceWatcherFactory::Protocol protocol, |
| 47 base::TimeDelta min_notification_interval, |
| 40 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 48 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 41 OnUpdatedRTTAvailableCallback updated_rtt_observation_callback); | 49 OnUpdatedRTTAvailableCallback updated_rtt_observation_callback, |
| 50 base::TickClock* tick_clock); |
| 42 | 51 |
| 43 ~SocketWatcher() override; | 52 ~SocketWatcher() override; |
| 44 | 53 |
| 45 // SocketPerformanceWatcher implementation: | 54 // SocketPerformanceWatcher implementation: |
| 46 bool ShouldNotifyUpdatedRTT() const override; | 55 bool ShouldNotifyUpdatedRTT() const override; |
| 47 void OnUpdatedRTTAvailable(const base::TimeDelta& rtt) override; | 56 void OnUpdatedRTTAvailable(const base::TimeDelta& rtt) override; |
| 48 void OnConnectionChanged() override; | 57 void OnConnectionChanged() override; |
| 49 | 58 |
| 50 private: | 59 private: |
| 51 // Transport layer protocol used by the socket that |this| is watching. | 60 // Transport layer protocol used by the socket that |this| is watching. |
| 52 const SocketPerformanceWatcherFactory::Protocol protocol_; | 61 const SocketPerformanceWatcherFactory::Protocol protocol_; |
| 53 | 62 |
| 54 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 63 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 55 | 64 |
| 56 // Called every time a new RTT observation is available. | 65 // Called every time a new RTT observation is available. |
| 57 OnUpdatedRTTAvailableCallback updated_rtt_observation_callback_; | 66 OnUpdatedRTTAvailableCallback updated_rtt_observation_callback_; |
| 58 | 67 |
| 68 // Minimum interval betweeen consecutive incoming notifications. |
| 69 const base::TimeDelta rtt_notifications_minimum_interval_; |
| 70 |
| 71 // Time when this was last notified of updated RTT. |
| 72 base::TimeTicks last_rtt_notification_; |
| 73 |
| 74 base::TickClock* tick_clock_; |
| 75 |
| 59 base::ThreadChecker thread_checker_; | 76 base::ThreadChecker thread_checker_; |
| 60 | 77 |
| 61 DISALLOW_COPY_AND_ASSIGN(SocketWatcher); | 78 DISALLOW_COPY_AND_ASSIGN(SocketWatcher); |
| 62 }; | 79 }; |
| 63 | 80 |
| 64 } // namespace internal | 81 } // namespace internal |
| 65 | 82 |
| 66 } // namespace nqe | 83 } // namespace nqe |
| 67 | 84 |
| 68 } // namespace net | 85 } // namespace net |
| 69 | 86 |
| 70 #endif // NET_NQE_SOCKET_WATCHER_H_ | 87 #endif // NET_NQE_SOCKET_WATCHER_H_ |
| OLD | NEW |