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