| 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 #include "modules/netinfo/NetworkInformation.h" | 5 #include "modules/netinfo/NetworkInformation.h" |
| 6 | 6 |
| 7 #include "core/dom/ExecutionContext.h" | 7 #include "core/dom/ExecutionContext.h" |
| 8 #include "core/events/Event.h" | 8 #include "core/events/Event.h" |
| 9 #include "core/page/NetworkStateNotifier.h" | 9 #include "core/page/NetworkStateNotifier.h" |
| 10 #include "modules/EventTargetModules.h" | 10 #include "modules/EventTargetModules.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 } | 38 } |
| 39 ASSERT_NOT_REACHED(); | 39 ASSERT_NOT_REACHED(); |
| 40 return "none"; | 40 return "none"; |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 namespace blink { | 45 namespace blink { |
| 46 | 46 |
| 47 NetworkInformation* NetworkInformation::create(ExecutionContext* context) { | 47 NetworkInformation* NetworkInformation::create(ExecutionContext* context) { |
| 48 NetworkInformation* connection = new NetworkInformation(context); | 48 return new NetworkInformation(context); |
| 49 connection->suspendIfNeeded(); | |
| 50 return connection; | |
| 51 } | 49 } |
| 52 | 50 |
| 53 NetworkInformation::~NetworkInformation() { | 51 NetworkInformation::~NetworkInformation() { |
| 54 ASSERT(!m_observing); | 52 ASSERT(!m_observing); |
| 55 } | 53 } |
| 56 | 54 |
| 57 String NetworkInformation::type() const { | 55 String NetworkInformation::type() const { |
| 58 // m_type is only updated when listening for events, so ask | 56 // m_type is only updated when listening for events, so ask |
| 59 // networkStateNotifier if not listening (crbug.com/379841). | 57 // networkStateNotifier if not listening (crbug.com/379841). |
| 60 if (!m_observing) | 58 if (!m_observing) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 86 | 84 |
| 87 if (RuntimeEnabledFeatures::netInfoDownlinkMaxEnabled()) | 85 if (RuntimeEnabledFeatures::netInfoDownlinkMaxEnabled()) |
| 88 dispatchEvent(Event::create(EventTypeNames::change)); | 86 dispatchEvent(Event::create(EventTypeNames::change)); |
| 89 } | 87 } |
| 90 | 88 |
| 91 const AtomicString& NetworkInformation::interfaceName() const { | 89 const AtomicString& NetworkInformation::interfaceName() const { |
| 92 return EventTargetNames::NetworkInformation; | 90 return EventTargetNames::NetworkInformation; |
| 93 } | 91 } |
| 94 | 92 |
| 95 ExecutionContext* NetworkInformation::getExecutionContext() const { | 93 ExecutionContext* NetworkInformation::getExecutionContext() const { |
| 96 return SuspendableObject::getExecutionContext(); | 94 return ContextLifecycleObserver::getExecutionContext(); |
| 97 } | 95 } |
| 98 | 96 |
| 99 void NetworkInformation::addedEventListener( | 97 void NetworkInformation::addedEventListener( |
| 100 const AtomicString& eventType, | 98 const AtomicString& eventType, |
| 101 RegisteredEventListener& registeredListener) { | 99 RegisteredEventListener& registeredListener) { |
| 102 EventTargetWithInlineData::addedEventListener(eventType, registeredListener); | 100 EventTargetWithInlineData::addedEventListener(eventType, registeredListener); |
| 103 startObserving(); | 101 startObserving(); |
| 104 } | 102 } |
| 105 | 103 |
| 106 void NetworkInformation::removedEventListener( | 104 void NetworkInformation::removedEventListener( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } | 137 } |
| 140 | 138 |
| 141 void NetworkInformation::stopObserving() { | 139 void NetworkInformation::stopObserving() { |
| 142 if (m_observing) { | 140 if (m_observing) { |
| 143 networkStateNotifier().removeObserver(this, getExecutionContext()); | 141 networkStateNotifier().removeObserver(this, getExecutionContext()); |
| 144 m_observing = false; | 142 m_observing = false; |
| 145 } | 143 } |
| 146 } | 144 } |
| 147 | 145 |
| 148 NetworkInformation::NetworkInformation(ExecutionContext* context) | 146 NetworkInformation::NetworkInformation(ExecutionContext* context) |
| 149 : SuspendableObject(context), | 147 : ContextLifecycleObserver(context), |
| 150 m_type(networkStateNotifier().connectionType()), | 148 m_type(networkStateNotifier().connectionType()), |
| 151 m_downlinkMaxMbps(networkStateNotifier().maxBandwidth()), | 149 m_downlinkMaxMbps(networkStateNotifier().maxBandwidth()), |
| 152 m_observing(false), | 150 m_observing(false), |
| 153 m_contextStopped(false) {} | 151 m_contextStopped(false) {} |
| 154 | 152 |
| 155 DEFINE_TRACE(NetworkInformation) { | 153 DEFINE_TRACE(NetworkInformation) { |
| 156 EventTargetWithInlineData::trace(visitor); | 154 EventTargetWithInlineData::trace(visitor); |
| 157 SuspendableObject::trace(visitor); | 155 ContextLifecycleObserver::trace(visitor); |
| 158 } | 156 } |
| 159 | 157 |
| 160 } // namespace blink | 158 } // namespace blink |
| OLD | NEW |