OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 NetworkInformation_h | 5 #ifndef NetworkInformation_h |
6 #define NetworkInformation_h | 6 #define NetworkInformation_h |
7 | 7 |
8 #include "core/dom/ContextLifecycleObserver.h" | 8 #include "core/dom/ContextLifecycleObserver.h" |
9 #include "core/events/EventTarget.h" | 9 #include "core/events/EventTarget.h" |
10 #include "platform/bindings/ActiveScriptWrappable.h" | 10 #include "platform/bindings/ActiveScriptWrappable.h" |
11 #include "platform/network/NetworkStateNotifier.h" | 11 #include "platform/network/NetworkStateNotifier.h" |
| 12 #include "platform/wtf/Optional.h" |
| 13 #include "platform/wtf/Time.h" |
12 #include "public/platform/WebConnectionType.h" | 14 #include "public/platform/WebConnectionType.h" |
13 | 15 |
14 namespace blink { | 16 namespace blink { |
15 | 17 |
16 class ExecutionContext; | 18 class ExecutionContext; |
17 | 19 |
18 class NetworkInformation final | 20 class NetworkInformation final |
19 : public EventTargetWithInlineData, | 21 : public EventTargetWithInlineData, |
20 public ActiveScriptWrappable<NetworkInformation>, | 22 public ActiveScriptWrappable<NetworkInformation>, |
21 public ContextLifecycleObserver, | 23 public ContextLifecycleObserver, |
22 public NetworkStateNotifier::NetworkStateObserver { | 24 public NetworkStateNotifier::NetworkStateObserver { |
23 USING_GARBAGE_COLLECTED_MIXIN(NetworkInformation); | 25 USING_GARBAGE_COLLECTED_MIXIN(NetworkInformation); |
24 DEFINE_WRAPPERTYPEINFO(); | 26 DEFINE_WRAPPERTYPEINFO(); |
25 | 27 |
26 public: | 28 public: |
27 static NetworkInformation* Create(ExecutionContext*); | 29 static NetworkInformation* Create(ExecutionContext*); |
28 ~NetworkInformation() override; | 30 ~NetworkInformation() override; |
29 | 31 |
30 String type() const; | 32 String type() const; |
31 double downlinkMax() const; | 33 double downlinkMax() const; |
| 34 unsigned long rtt() const; |
| 35 double downlink() const; |
32 | 36 |
33 // NetworkStateObserver overrides. | 37 // NetworkStateObserver overrides. |
34 void ConnectionChange(WebConnectionType, double downlink_max_mbps) override; | 38 void ConnectionChange(WebConnectionType, |
| 39 double downlink_max_mbps, |
| 40 const Optional<TimeDelta>& http_rtt, |
| 41 const Optional<TimeDelta>& transport_rtt, |
| 42 const Optional<double>& downlink_mbps) override; |
35 | 43 |
36 // EventTarget overrides. | 44 // EventTarget overrides. |
37 const AtomicString& InterfaceName() const override; | 45 const AtomicString& InterfaceName() const override; |
38 ExecutionContext* GetExecutionContext() const override; | 46 ExecutionContext* GetExecutionContext() const override; |
39 void RemoveAllEventListeners() override; | 47 void RemoveAllEventListeners() override; |
40 | 48 |
41 // ScriptWrappable | 49 // ScriptWrappable |
42 bool HasPendingActivity() const final; | 50 bool HasPendingActivity() const final; |
43 | 51 |
44 // ContextLifecycleObserver overrides. | 52 // ContextLifecycleObserver overrides. |
(...skipping 15 matching lines...) Expand all Loading... |
60 explicit NetworkInformation(ExecutionContext*); | 68 explicit NetworkInformation(ExecutionContext*); |
61 void StartObserving(); | 69 void StartObserving(); |
62 void StopObserving(); | 70 void StopObserving(); |
63 | 71 |
64 // Touched only on context thread. | 72 // Touched only on context thread. |
65 WebConnectionType type_; | 73 WebConnectionType type_; |
66 | 74 |
67 // Touched only on context thread. | 75 // Touched only on context thread. |
68 double downlink_max_mbps_; | 76 double downlink_max_mbps_; |
69 | 77 |
| 78 // Transport RTT estimate. Rounded off to the nearest 25 msec. Touched only on |
| 79 // context thread. |
| 80 unsigned long transport_rtt_msec_; |
| 81 |
| 82 // Downlink throughput estimate. Rounded off to the nearest 25 kbps. Touched |
| 83 // only on context thread. |
| 84 double downlink_mbps_; |
| 85 |
70 // Whether this object is listening for events from NetworkStateNotifier. | 86 // Whether this object is listening for events from NetworkStateNotifier. |
71 bool observing_; | 87 bool observing_; |
72 | 88 |
73 // Whether ContextLifecycleObserver::contextDestroyed has been called. | 89 // Whether ContextLifecycleObserver::contextDestroyed has been called. |
74 bool context_stopped_; | 90 bool context_stopped_; |
75 }; | 91 }; |
76 | 92 |
77 } // namespace blink | 93 } // namespace blink |
78 | 94 |
79 #endif // NetworkInformation_h | 95 #endif // NetworkInformation_h |
OLD | NEW |