| 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/ActiveDOMObject.h" | 8 #include "core/dom/ActiveDOMObject.h" |
| 9 #include "core/events/EventTarget.h" | 9 #include "core/events/EventTarget.h" |
| 10 #include "core/page/NetworkStateNotifier.h" | 10 #include "core/page/NetworkStateNotifier.h" |
| 11 #include "public/platform/WebConnectionType.h" | 11 #include "public/platform/WebConnectionType.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 class ExecutionContext; | 15 class ExecutionContext; |
| 16 | 16 |
| 17 class NetworkInformation final | 17 class NetworkInformation final |
| 18 : public RefCountedGarbageCollectedEventTargetWithInlineData<NetworkInformat
ion> | 18 : public RefCountedGarbageCollectedEventTargetWithInlineData<NetworkInformat
ion> |
| 19 , public ActiveDOMObject | 19 , public ActiveDOMObject |
| 20 , public NetworkStateNotifier::NetworkStateObserver { | 20 , public NetworkStateNotifier::NetworkStateObserver { |
| 21 REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(NetworkInformation); | 21 REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(NetworkInformation); |
| 22 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(NetworkInformation); | 22 USING_GARBAGE_COLLECTED_MIXIN(NetworkInformation); |
| 23 DEFINE_WRAPPERTYPEINFO(); | 23 DEFINE_WRAPPERTYPEINFO(); |
| 24 public: | 24 public: |
| 25 static NetworkInformation* create(ExecutionContext*); | 25 static NetworkInformation* create(ExecutionContext*); |
| 26 ~NetworkInformation() override; | 26 ~NetworkInformation() override; |
| 27 | 27 |
| 28 String type() const; | 28 String type() const; |
| 29 double downlinkMax() const; | 29 double downlinkMax() const; |
| 30 | 30 |
| 31 // NetworkStateObserver overrides. | 31 // NetworkStateObserver overrides. |
| 32 void connectionChange(WebConnectionType, double downlinkMaxMbps) override; | 32 void connectionChange(WebConnectionType, double downlinkMaxMbps) override; |
| 33 | 33 |
| 34 // EventTarget overrides. | 34 // EventTarget overrides. |
| 35 const AtomicString& interfaceName() const override; | 35 const AtomicString& interfaceName() const override; |
| 36 ExecutionContext* executionContext() const override; | 36 ExecutionContext* executionContext() const override; |
| 37 void removeAllEventListeners() override; | 37 void removeAllEventListeners() override; |
| 38 | 38 |
| 39 // ActiveDOMObject overrides. | 39 // ActiveDOMObject overrides. |
| 40 bool hasPendingActivity() const override; | 40 bool hasPendingActivity() const override; |
| 41 void stop() override; | 41 void stop() override; |
| 42 | 42 |
| 43 DECLARE_VIRTUAL_TRACE(); | 43 DECLARE_VIRTUAL_TRACE(); |
| 44 | 44 |
| 45 DEFINE_ATTRIBUTE_EVENT_LISTENER(change); | 45 DEFINE_ATTRIBUTE_EVENT_LISTENER(change); |
| 46 DEFINE_ATTRIBUTE_EVENT_LISTENER(typechange); // Deprecated | 46 DEFINE_ATTRIBUTE_EVENT_LISTENER(typechange); // Deprecated |
| 47 | 47 |
| 48 protected: | 48 protected: |
| 49 // EventTarget overrides. | 49 // EventTarget overrides. |
| 50 bool addEventListenerInternal(const AtomicString& eventType, PassRefPtrWillB
eRawPtr<EventListener>, const EventListenerOptions&) override; | 50 bool addEventListenerInternal(const AtomicString& eventType, RawPtr<EventLis
tener>, const EventListenerOptions&) override; |
| 51 bool removeEventListenerInternal(const AtomicString& eventType, PassRefPtrWi
llBeRawPtr<EventListener>, const EventListenerOptions&) override; | 51 bool removeEventListenerInternal(const AtomicString& eventType, RawPtr<Event
Listener>, const EventListenerOptions&) override; |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 explicit NetworkInformation(ExecutionContext*); | 54 explicit NetworkInformation(ExecutionContext*); |
| 55 void startObserving(); | 55 void startObserving(); |
| 56 void stopObserving(); | 56 void stopObserving(); |
| 57 | 57 |
| 58 // Touched only on context thread. | 58 // Touched only on context thread. |
| 59 WebConnectionType m_type; | 59 WebConnectionType m_type; |
| 60 | 60 |
| 61 // Touched only on context thread. | 61 // Touched only on context thread. |
| 62 double m_downlinkMaxMbps; | 62 double m_downlinkMaxMbps; |
| 63 | 63 |
| 64 // Whether this object is listening for events from NetworkStateNotifier. | 64 // Whether this object is listening for events from NetworkStateNotifier. |
| 65 bool m_observing; | 65 bool m_observing; |
| 66 | 66 |
| 67 // Whether ActiveDOMObject::stop has been called. | 67 // Whether ActiveDOMObject::stop has been called. |
| 68 bool m_contextStopped; | 68 bool m_contextStopped; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 } // namespace blink | 71 } // namespace blink |
| 72 | 72 |
| 73 #endif // NetworkInformation_h | 73 #endif // NetworkInformation_h |
| OLD | NEW |