OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_NQE_SOCKET_WATCHER_H_ |
| 6 #define NET_NQE_SOCKET_WATCHER_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/threading/thread_checker.h" |
| 12 #include "net/socket/socket_performance_watcher.h" |
| 13 #include "net/socket/socket_performance_watcher_factory.h" |
| 14 |
| 15 namespace base { |
| 16 class SingleThreadTaskRunner; |
| 17 class TimeDelta; |
| 18 } // namespace base |
| 19 |
| 20 namespace net { |
| 21 |
| 22 namespace { |
| 23 typedef base::Callback<void(SocketPerformanceWatcherFactory::Protocol protocol, |
| 24 const base::TimeDelta& rtt)> |
| 25 OnUpdatedRTTAvailableCallback; |
| 26 } |
| 27 |
| 28 namespace nqe { |
| 29 |
| 30 namespace internal { |
| 31 |
| 32 // SocketWatcher implements SocketPerformanceWatcher, and is not thread-safe. |
| 33 class SocketWatcher : public SocketPerformanceWatcher { |
| 34 public: |
| 35 // 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 |
| 37 // |updated_rtt_observation_callback| on |task_runner| every time a new RTT |
| 38 // observation is available. |
| 39 SocketWatcher(SocketPerformanceWatcherFactory::Protocol protocol, |
| 40 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 41 OnUpdatedRTTAvailableCallback updated_rtt_observation_callback); |
| 42 |
| 43 ~SocketWatcher() override; |
| 44 |
| 45 // SocketPerformanceWatcher implementation: |
| 46 bool ShouldNotifyUpdatedRTT() const override; |
| 47 void OnUpdatedRTTAvailable(const base::TimeDelta& rtt) override; |
| 48 void OnConnectionChanged() override; |
| 49 |
| 50 private: |
| 51 // Transport layer protocol used by the socket that |this| is watching. |
| 52 const SocketPerformanceWatcherFactory::Protocol protocol_; |
| 53 |
| 54 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 55 |
| 56 // Called every time a new RTT observation is available. |
| 57 OnUpdatedRTTAvailableCallback updated_rtt_observation_callback_; |
| 58 |
| 59 base::ThreadChecker thread_checker_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(SocketWatcher); |
| 62 }; |
| 63 |
| 64 } // namespace internal |
| 65 |
| 66 } // namespace nqe |
| 67 |
| 68 } // namespace net |
| 69 |
| 70 #endif // NET_NQE_SOCKET_WATCHER_H_ |
OLD | NEW |