| 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/dom/TaskRunnerHelper.h" | 8 #include "core/dom/TaskRunnerHelper.h" |
| 9 #include "core/events/Event.h" | 9 #include "core/events/Event.h" |
| 10 #include "modules/EventTargetModules.h" | 10 #include "modules/EventTargetModules.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 return "none"; | 40 return "none"; |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 NetworkInformation* NetworkInformation::Create(ExecutionContext* context) { | 45 NetworkInformation* NetworkInformation::Create(ExecutionContext* context) { |
| 46 return new NetworkInformation(context); | 46 return new NetworkInformation(context); |
| 47 } | 47 } |
| 48 | 48 |
| 49 NetworkInformation::~NetworkInformation() { | 49 NetworkInformation::~NetworkInformation() { |
| 50 ASSERT(!observing_); | 50 DCHECK(!observing_); |
| 51 } | 51 } |
| 52 | 52 |
| 53 String NetworkInformation::type() const { | 53 String NetworkInformation::type() const { |
| 54 // m_type is only updated when listening for events, so ask | 54 // m_type is only updated when listening for events, so ask |
| 55 // networkStateNotifier if not listening (crbug.com/379841). | 55 // networkStateNotifier if not listening (crbug.com/379841). |
| 56 if (!observing_) | 56 if (!observing_) |
| 57 return ConnectionTypeToString(GetNetworkStateNotifier().ConnectionType()); | 57 return ConnectionTypeToString(GetNetworkStateNotifier().ConnectionType()); |
| 58 | 58 |
| 59 // If observing, return m_type which changes when the event fires, per spec. | 59 // If observing, return m_type which changes when the event fires, per spec. |
| 60 return ConnectionTypeToString(type_); | 60 return ConnectionTypeToString(type_); |
| 61 } | 61 } |
| 62 | 62 |
| 63 double NetworkInformation::downlinkMax() const { | 63 double NetworkInformation::downlinkMax() const { |
| 64 if (!observing_) | 64 if (!observing_) |
| 65 return GetNetworkStateNotifier().MaxBandwidth(); | 65 return GetNetworkStateNotifier().MaxBandwidth(); |
| 66 | 66 |
| 67 return downlink_max_mbps_; | 67 return downlink_max_mbps_; |
| 68 } | 68 } |
| 69 | 69 |
| 70 void NetworkInformation::ConnectionChange(WebConnectionType type, | 70 void NetworkInformation::ConnectionChange(WebConnectionType type, |
| 71 double downlink_max_mbps) { | 71 double downlink_max_mbps) { |
| 72 ASSERT(GetExecutionContext()->IsContextThread()); | 72 DCHECK(GetExecutionContext()->IsContextThread()); |
| 73 | 73 |
| 74 // This can happen if the observer removes and then adds itself again | 74 // This can happen if the observer removes and then adds itself again |
| 75 // during notification. | 75 // during notification. |
| 76 if (type_ == type && downlink_max_mbps_ == downlink_max_mbps) | 76 if (type_ == type && downlink_max_mbps_ == downlink_max_mbps) |
| 77 return; | 77 return; |
| 78 | 78 |
| 79 type_ = type; | 79 type_ = type; |
| 80 downlink_max_mbps_ = downlink_max_mbps; | 80 downlink_max_mbps_ = downlink_max_mbps; |
| 81 DispatchEvent(Event::Create(EventTypeNames::typechange)); | 81 DispatchEvent(Event::Create(EventTypeNames::typechange)); |
| 82 | 82 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 104 const AtomicString& event_type, | 104 const AtomicString& event_type, |
| 105 const RegisteredEventListener& registered_listener) { | 105 const RegisteredEventListener& registered_listener) { |
| 106 EventTargetWithInlineData::RemovedEventListener(event_type, | 106 EventTargetWithInlineData::RemovedEventListener(event_type, |
| 107 registered_listener); | 107 registered_listener); |
| 108 if (!HasEventListeners()) | 108 if (!HasEventListeners()) |
| 109 StopObserving(); | 109 StopObserving(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void NetworkInformation::RemoveAllEventListeners() { | 112 void NetworkInformation::RemoveAllEventListeners() { |
| 113 EventTargetWithInlineData::RemoveAllEventListeners(); | 113 EventTargetWithInlineData::RemoveAllEventListeners(); |
| 114 ASSERT(!HasEventListeners()); | 114 DCHECK(!HasEventListeners()); |
| 115 StopObserving(); | 115 StopObserving(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 bool NetworkInformation::HasPendingActivity() const { | 118 bool NetworkInformation::HasPendingActivity() const { |
| 119 ASSERT(context_stopped_ || observing_ == HasEventListeners()); | 119 ASSERT(context_stopped_ || observing_ == HasEventListeners()); |
| 120 | 120 |
| 121 // Prevent collection of this object when there are active listeners. | 121 // Prevent collection of this object when there are active listeners. |
| 122 return observing_; | 122 return observing_; |
| 123 } | 123 } |
| 124 | 124 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 152 downlink_max_mbps_(GetNetworkStateNotifier().MaxBandwidth()), | 152 downlink_max_mbps_(GetNetworkStateNotifier().MaxBandwidth()), |
| 153 observing_(false), | 153 observing_(false), |
| 154 context_stopped_(false) {} | 154 context_stopped_(false) {} |
| 155 | 155 |
| 156 DEFINE_TRACE(NetworkInformation) { | 156 DEFINE_TRACE(NetworkInformation) { |
| 157 EventTargetWithInlineData::Trace(visitor); | 157 EventTargetWithInlineData::Trace(visitor); |
| 158 ContextLifecycleObserver::Trace(visitor); | 158 ContextLifecycleObserver::Trace(visitor); |
| 159 } | 159 } |
| 160 | 160 |
| 161 } // namespace blink | 161 } // namespace blink |
| OLD | NEW |