| 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" | 12 #include "platform/wtf/Optional.h" |
| 13 #include "platform/wtf/Time.h" | 13 #include "platform/wtf/Time.h" |
| 14 #include "public/platform/WebConnectionType.h" | 14 #include "public/platform/WebConnectionType.h" |
| 15 #include "public/platform/WebEffectiveConnectionType.h" |
| 15 | 16 |
| 16 namespace blink { | 17 namespace blink { |
| 17 | 18 |
| 18 class ExecutionContext; | 19 class ExecutionContext; |
| 19 | 20 |
| 20 class NetworkInformation final | 21 class NetworkInformation final |
| 21 : public EventTargetWithInlineData, | 22 : public EventTargetWithInlineData, |
| 22 public ActiveScriptWrappable<NetworkInformation>, | 23 public ActiveScriptWrappable<NetworkInformation>, |
| 23 public ContextLifecycleObserver, | 24 public ContextLifecycleObserver, |
| 24 public NetworkStateNotifier::NetworkStateObserver { | 25 public NetworkStateNotifier::NetworkStateObserver { |
| 25 USING_GARBAGE_COLLECTED_MIXIN(NetworkInformation); | 26 USING_GARBAGE_COLLECTED_MIXIN(NetworkInformation); |
| 26 DEFINE_WRAPPERTYPEINFO(); | 27 DEFINE_WRAPPERTYPEINFO(); |
| 27 | 28 |
| 28 public: | 29 public: |
| 29 static NetworkInformation* Create(ExecutionContext*); | 30 static NetworkInformation* Create(ExecutionContext*); |
| 30 ~NetworkInformation() override; | 31 ~NetworkInformation() override; |
| 31 | 32 |
| 32 String type() const; | 33 String type() const; |
| 33 double downlinkMax() const; | 34 double downlinkMax() const; |
| 35 String effectiveType() const; |
| 34 unsigned long rtt() const; | 36 unsigned long rtt() const; |
| 35 double downlink() const; | 37 double downlink() const; |
| 36 | 38 |
| 37 // NetworkStateObserver overrides. | 39 // NetworkStateObserver overrides. |
| 38 void ConnectionChange(WebConnectionType, | 40 void ConnectionChange(WebConnectionType, |
| 39 double downlink_max_mbps, | 41 double downlink_max_mbps, |
| 42 WebEffectiveConnectionType effective_type, |
| 40 const Optional<TimeDelta>& http_rtt, | 43 const Optional<TimeDelta>& http_rtt, |
| 41 const Optional<TimeDelta>& transport_rtt, | 44 const Optional<TimeDelta>& transport_rtt, |
| 42 const Optional<double>& downlink_mbps) override; | 45 const Optional<double>& downlink_mbps) override; |
| 43 | 46 |
| 44 // EventTarget overrides. | 47 // EventTarget overrides. |
| 45 const AtomicString& InterfaceName() const override; | 48 const AtomicString& InterfaceName() const override; |
| 46 ExecutionContext* GetExecutionContext() const override; | 49 ExecutionContext* GetExecutionContext() const override; |
| 47 void RemoveAllEventListeners() override; | 50 void RemoveAllEventListeners() override; |
| 48 | 51 |
| 49 // ScriptWrappable | 52 // ScriptWrappable |
| (...skipping 18 matching lines...) Expand all Loading... |
| 68 explicit NetworkInformation(ExecutionContext*); | 71 explicit NetworkInformation(ExecutionContext*); |
| 69 void StartObserving(); | 72 void StartObserving(); |
| 70 void StopObserving(); | 73 void StopObserving(); |
| 71 | 74 |
| 72 // Touched only on context thread. | 75 // Touched only on context thread. |
| 73 WebConnectionType type_; | 76 WebConnectionType type_; |
| 74 | 77 |
| 75 // Touched only on context thread. | 78 // Touched only on context thread. |
| 76 double downlink_max_mbps_; | 79 double downlink_max_mbps_; |
| 77 | 80 |
| 81 // Current effective connection type, which is the connection type whose |
| 82 // typical performance is most similar to the measured performance of the |
| 83 // network in use. |
| 84 WebEffectiveConnectionType effective_type_; |
| 85 |
| 78 // Transport RTT estimate. Rounded off to the nearest 25 msec. Touched only on | 86 // Transport RTT estimate. Rounded off to the nearest 25 msec. Touched only on |
| 79 // context thread. | 87 // context thread. |
| 80 unsigned long transport_rtt_msec_; | 88 unsigned long transport_rtt_msec_; |
| 81 | 89 |
| 82 // Downlink throughput estimate. Rounded off to the nearest 25 kbps. Touched | 90 // Downlink throughput estimate. Rounded off to the nearest 25 kbps. Touched |
| 83 // only on context thread. | 91 // only on context thread. |
| 84 double downlink_mbps_; | 92 double downlink_mbps_; |
| 85 | 93 |
| 86 // Whether this object is listening for events from NetworkStateNotifier. | 94 // Whether this object is listening for events from NetworkStateNotifier. |
| 87 bool observing_; | 95 bool observing_; |
| 88 | 96 |
| 89 // Whether ContextLifecycleObserver::contextDestroyed has been called. | 97 // Whether ContextLifecycleObserver::contextDestroyed has been called. |
| 90 bool context_stopped_; | 98 bool context_stopped_; |
| 91 }; | 99 }; |
| 92 | 100 |
| 93 } // namespace blink | 101 } // namespace blink |
| 94 | 102 |
| 95 #endif // NetworkInformation_h | 103 #endif // NetworkInformation_h |
| OLD | NEW |