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/memory/ref_counted.h" | |
13 #include "base/memory/weak_ptr.h" | |
14 #include "base/threading/thread_checker.h" | |
9 #include "net/base/net_export.h" | 15 #include "net/base/net_export.h" |
10 #include "net/base/socket_performance_watcher_factory.h" | 16 #include "net/base/socket_performance_watcher_factory.h" |
11 | 17 |
12 namespace base { | 18 namespace base { |
19 class SingleThreadTaskRunner; | |
13 class TimeDelta; | 20 class TimeDelta; |
14 } // namespace base | 21 } // namespace base |
15 | 22 |
16 namespace net { | 23 namespace net { |
17 | 24 |
18 // SocketPerformanceWatcher is the base class for recording and aggregating | 25 // SocketPerformanceWatcher is the base class for recording and aggregating |
19 // socket statistics. | 26 // socket statistics. |
20 class NET_EXPORT_PRIVATE SocketPerformanceWatcher { | 27 class NET_EXPORT_PRIVATE SocketPerformanceWatcher { |
21 public: | 28 public: |
22 // |socket_performance_watcher_factory| is the factory that constructed | 29 // |socket_performance_watcher_factory| is the factory that constructed |
23 // |this| watcher. | 30 // |this| watcher. |socket_performance_watcher_factory| may live on a |
31 // different thread, and should be accessed only on the |task_runner|. | |
24 SocketPerformanceWatcher( | 32 SocketPerformanceWatcher( |
25 const SocketPerformanceWatcherFactory::Protocol protocol, | 33 const SocketPerformanceWatcherFactory::Protocol protocol, |
26 SocketPerformanceWatcherFactory* socket_performance_watcher_factory); | 34 const base::WeakPtr<SocketPerformanceWatcherFactory>& |
35 socket_performance_watcher_factory, | |
Ryan Sleevi
2016/03/21 23:25:32
DESIGN: You should *NEVER* pass a WeakPtr<Foo> to
tbansal1
2016/03/23 20:01:33
Done.
| |
36 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | |
27 | 37 |
28 virtual ~SocketPerformanceWatcher(); | 38 ~SocketPerformanceWatcher(); |
29 | 39 |
30 // Called when updated transport layer RTT information is available. This | 40 // Called when updated transport layer RTT information is available. This |
31 // must be the transport layer RTT from this device to the remote transport | 41 // 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 | 42 // layer endpoint. This method is called immediately after the observation is |
33 // made, hence no timestamp. | 43 // made, hence no timestamp. |
34 void OnUpdatedRTTAvailable(const base::TimeDelta& rtt) const; | 44 void OnUpdatedRTTAvailable(const base::TimeDelta& rtt); |
45 | |
46 // Returns |true| if the current SocketPerformanceWatcher is interested | |
47 // in receiving a new RTT estimate (via OnUpdatedRTTAvailable). | |
48 // Callers may use this to avoid doing expensive work computing the | |
49 // RTT when the SocketPerformanceWatcher is not interested in such | |
50 // updates. | |
51 bool ShouldNotifyUpdatedRTT() const WARN_UNUSED_RESULT; | |
52 | |
53 // Resets the internal state of this SocketPerformanceWatcher in preparation | |
54 // for observing a new socket. | |
55 // Note: The new socket must share the same protocol as the previously | |
56 // observed socket. | |
57 void Reset(); | |
58 | |
59 base::WeakPtr<SocketPerformanceWatcher> GetWeakPtr(); | |
35 | 60 |
36 private: | 61 private: |
37 // Transport layer protocol used by the socket that |this| is watching. | 62 // Transport layer protocol used by the socket that |this| is watching. |
38 const SocketPerformanceWatcherFactory::Protocol protocol_; | 63 const SocketPerformanceWatcherFactory::Protocol protocol_; |
39 | 64 |
65 // Number of RTT notifications received. | |
66 size_t rtt_notification_received_count_; | |
67 | |
40 // |socket_performance_watcher_factory_| is the factory that created | 68 // |socket_performance_watcher_factory_| is the factory that created |
41 // |this| watcher. | 69 // |this| watcher. |socket_performance_watcher_factory_| may live on a |
42 SocketPerformanceWatcherFactory* socket_performance_watcher_factory_; | 70 // different thread than |this|. |
71 const base::WeakPtr<SocketPerformanceWatcherFactory> | |
72 socket_performance_watcher_factory_; | |
73 | |
74 base::ThreadChecker thread_checker_; | |
75 | |
76 // TaskRunner on which |socket_performance_watcher_factory_| should be | |
77 // accessed. | |
78 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
79 | |
80 base::WeakPtrFactory<SocketPerformanceWatcher> weak_ptr_factory_; | |
43 | 81 |
44 DISALLOW_COPY_AND_ASSIGN(SocketPerformanceWatcher); | 82 DISALLOW_COPY_AND_ASSIGN(SocketPerformanceWatcher); |
45 }; | 83 }; |
46 | 84 |
47 } // namespace net | 85 } // namespace net |
48 | 86 |
49 #endif // NET_BASE_SOCKET_PERFORMANCE_WATCHER_H_ | 87 #endif // NET_BASE_SOCKET_PERFORMANCE_WATCHER_H_ |
OLD | NEW |