OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_BASE_SOCKET_PERFORMANCE_WATCHER_H_ | 5 #ifndef NET_BASE_SOCKET_PERFORMANCE_WATCHER_H_ |
6 #define NET_BASE_SOCKET_PERFORMANCE_WATCHER_H_ | 6 #define NET_BASE_SOCKET_PERFORMANCE_WATCHER_H_ |
7 | 7 |
| 8 #include <stddef.h> |
| 9 |
| 10 #include "base/compiler_specific.h" |
8 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/threading/thread_checker.h" |
9 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
10 #include "net/base/socket_performance_watcher_factory.h" | 14 #include "net/base/socket_performance_watcher_factory.h" |
11 | 15 |
12 namespace base { | 16 namespace base { |
13 class TimeDelta; | 17 class TimeDelta; |
14 } // namespace base | 18 } // namespace base |
15 | 19 |
16 namespace net { | 20 namespace net { |
17 | 21 |
18 // SocketPerformanceWatcher is the base class for recording and aggregating | 22 // SocketPerformanceWatcher is the base class for recording and aggregating |
19 // socket statistics. | 23 // socket statistics. |
20 class NET_EXPORT_PRIVATE SocketPerformanceWatcher { | 24 class NET_EXPORT_PRIVATE SocketPerformanceWatcher { |
21 public: | 25 public: |
22 // |socket_performance_watcher_factory| is the factory that constructed | 26 // |socket_performance_watcher_factory| is the factory that constructed |
23 // |this| watcher. | 27 // |this| watcher. |socket_performance_watcher_factory| may live on a |
| 28 // different thread, and should be accessed only on the |task_runner|. |
24 SocketPerformanceWatcher( | 29 SocketPerformanceWatcher( |
25 const SocketPerformanceWatcherFactory::Protocol protocol, | 30 SocketPerformanceWatcherFactory::Protocol protocol, |
26 SocketPerformanceWatcherFactory* socket_performance_watcher_factory); | 31 SocketPerformanceWatcherFactory* socket_performance_watcher_factory); |
27 | 32 |
28 virtual ~SocketPerformanceWatcher(); | 33 ~SocketPerformanceWatcher(); |
29 | 34 |
30 // Called when updated transport layer RTT information is available. This | 35 // Called when updated transport layer RTT information is available. This |
31 // must be the transport layer RTT from this device to the remote transport | 36 // must be the transport layer RTT from this device to the remote transport |
32 // layer endpoint. This method is called immediately after the observation is | 37 // layer endpoint. This method is called immediately after the observation is |
33 // made, hence no timestamp. | 38 // made, hence no timestamp. |
34 void OnUpdatedRTTAvailable(const base::TimeDelta& rtt) const; | 39 void OnUpdatedRTTAvailable(const base::TimeDelta& rtt); |
| 40 |
| 41 // Returns |true| if the current SocketPerformanceWatcher is interested |
| 42 // in receiving a new RTT estimate (via OnUpdatedRTTAvailable). |
| 43 // Callers may use this to avoid doing expensive work computing the |
| 44 // RTT when the SocketPerformanceWatcher is not interested in such |
| 45 // updates. |
| 46 bool ShouldNotifyUpdatedRTT() const WARN_UNUSED_RESULT; |
| 47 |
| 48 // Resets the internal state of this SocketPerformanceWatcher in preparation |
| 49 // for observing a new socket. |
| 50 // Note: The new socket must share the same protocol as the previously |
| 51 // observed socket. |
| 52 void Reset(); |
35 | 53 |
36 private: | 54 private: |
37 // Transport layer protocol used by the socket that |this| is watching. | 55 // Transport layer protocol used by the socket that |this| is watching. |
38 const SocketPerformanceWatcherFactory::Protocol protocol_; | 56 const SocketPerformanceWatcherFactory::Protocol protocol_; |
39 | 57 |
| 58 // Number of RTT notifications received. |
| 59 size_t rtt_notification_received_count_; |
| 60 |
40 // |socket_performance_watcher_factory_| is the factory that created | 61 // |socket_performance_watcher_factory_| is the factory that created |
41 // |this| watcher. | 62 // |this| watcher. |
42 SocketPerformanceWatcherFactory* socket_performance_watcher_factory_; | 63 SocketPerformanceWatcherFactory* socket_performance_watcher_factory_; |
43 | 64 |
| 65 base::ThreadChecker thread_checker_; |
| 66 |
44 DISALLOW_COPY_AND_ASSIGN(SocketPerformanceWatcher); | 67 DISALLOW_COPY_AND_ASSIGN(SocketPerformanceWatcher); |
45 }; | 68 }; |
46 | 69 |
47 } // namespace net | 70 } // namespace net |
48 | 71 |
49 #endif // NET_BASE_SOCKET_PERFORMANCE_WATCHER_H_ | 72 #endif // NET_BASE_SOCKET_PERFORMANCE_WATCHER_H_ |
OLD | NEW |