| 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_FACTORY_H_ | 5 #ifndef NET_NQE_SOCKET_WATCHER_FACTORY_H_ |
| 6 #define NET_NQE_SOCKET_WATCHER_FACTORY_H_ | 6 #define NET_NQE_SOCKET_WATCHER_FACTORY_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 15 #include "base/time/time.h" |
| 15 #include "net/socket/socket_performance_watcher.h" | 16 #include "net/socket/socket_performance_watcher.h" |
| 16 #include "net/socket/socket_performance_watcher_factory.h" | 17 #include "net/socket/socket_performance_watcher_factory.h" |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 class TimeDelta; | 20 class TimeDelta; |
| 20 } // namespace base | 21 } // namespace base |
| 21 | 22 |
| 22 namespace net { | 23 namespace net { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 typedef base::Callback<void(SocketPerformanceWatcherFactory::Protocol protocol, | 26 typedef base::Callback<void(SocketPerformanceWatcherFactory::Protocol protocol, |
| 26 const base::TimeDelta& rtt)> | 27 const base::TimeDelta& rtt)> |
| 27 OnUpdatedRTTAvailableCallback; | 28 OnUpdatedRTTAvailableCallback; |
| 28 } | 29 } |
| 29 | 30 |
| 30 namespace nqe { | 31 namespace nqe { |
| 31 | 32 |
| 32 namespace internal { | 33 namespace internal { |
| 33 | 34 |
| 34 // SocketWatcherFactory implements SocketPerformanceWatcherFactory. | 35 // SocketWatcherFactory implements SocketPerformanceWatcherFactory. |
| 35 // SocketWatcherFactory is thread safe. | 36 // SocketWatcherFactory is thread safe. |
| 36 class SocketWatcherFactory : public SocketPerformanceWatcherFactory { | 37 class SocketWatcherFactory : public SocketPerformanceWatcherFactory { |
| 37 public: | 38 public: |
| 38 // Creates a SocketWatcherFactory. All socket watchers created by | 39 // Creates a SocketWatcherFactory. All socket watchers created by |
| 39 // SocketWatcherFactory call |updated_rtt_observation_callback| on | 40 // SocketWatcherFactory call |updated_rtt_observation_callback| on |
| 40 // |task_runner| every time a new RTT observation is available. | 41 // |task_runner| every time a new RTT observation is available. |
| 42 // |min_notification_interval| is the minimum interval betweeen consecutive |
| 43 // notifications to the socket watchers created by this factory. |
| 41 SocketWatcherFactory( | 44 SocketWatcherFactory( |
| 42 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 45 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 46 base::TimeDelta min_notification_interval, |
| 43 OnUpdatedRTTAvailableCallback updated_rtt_observation_callback); | 47 OnUpdatedRTTAvailableCallback updated_rtt_observation_callback); |
| 44 | 48 |
| 45 ~SocketWatcherFactory() override; | 49 ~SocketWatcherFactory() override; |
| 46 | 50 |
| 47 // SocketPerformanceWatcherFactory implementation: | 51 // SocketPerformanceWatcherFactory implementation: |
| 48 std::unique_ptr<SocketPerformanceWatcher> CreateSocketPerformanceWatcher( | 52 std::unique_ptr<SocketPerformanceWatcher> CreateSocketPerformanceWatcher( |
| 49 const Protocol protocol) override; | 53 const Protocol protocol) override; |
| 50 | 54 |
| 51 private: | 55 private: |
| 52 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 56 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 53 | 57 |
| 58 // Minimum interval betweeen consecutive notifications to the socket watchers |
| 59 // created by this factory. |
| 60 const base::TimeDelta min_notification_interval_; |
| 61 |
| 54 // Called every time a new RTT observation is available. | 62 // Called every time a new RTT observation is available. |
| 55 OnUpdatedRTTAvailableCallback updated_rtt_observation_callback_; | 63 OnUpdatedRTTAvailableCallback updated_rtt_observation_callback_; |
| 56 | 64 |
| 57 DISALLOW_COPY_AND_ASSIGN(SocketWatcherFactory); | 65 DISALLOW_COPY_AND_ASSIGN(SocketWatcherFactory); |
| 58 }; | 66 }; |
| 59 | 67 |
| 60 } // namespace internal | 68 } // namespace internal |
| 61 | 69 |
| 62 } // namespace nqe | 70 } // namespace nqe |
| 63 | 71 |
| 64 } // namespace net | 72 } // namespace net |
| 65 | 73 |
| 66 #endif // NET_NQE_SOCKET_WATCHER_FACTORY_H_ | 74 #endif // NET_NQE_SOCKET_WATCHER_FACTORY_H_ |
| OLD | NEW |