| 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 "config.h" | 5 #include "config.h" |
| 6 #include "modules/netinfo/NetworkInformation.h" | 6 #include "modules/netinfo/NetworkInformation.h" |
| 7 | 7 |
| 8 #include "core/dom/ExecutionContext.h" | 8 #include "core/dom/ExecutionContext.h" |
| 9 #include "core/events/Event.h" | 9 #include "core/events/Event.h" |
| 10 #include "core/page/NetworkStateNotifier.h" | 10 #include "core/page/NetworkStateNotifier.h" |
| 11 #include "modules/EventTargetModules.h" | 11 #include "modules/EventTargetModules.h" |
| 12 #include "platform/RuntimeEnabledFeatures.h" |
| 12 #include "wtf/text/WTFString.h" | 13 #include "wtf/text/WTFString.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 using namespace blink; | 17 using namespace blink; |
| 17 | 18 |
| 18 String connectionTypeToString(WebConnectionType type) | 19 String connectionTypeToString(WebConnectionType type) |
| 19 { | 20 { |
| 20 switch (type) { | 21 switch (type) { |
| 21 case ConnectionTypeCellular: | 22 case ConnectionTypeCellular: |
| 22 return "cellular"; | 23 return "cellular"; |
| 23 case ConnectionTypeBluetooth: | 24 case ConnectionTypeBluetooth: |
| 24 return "bluetooth"; | 25 return "bluetooth"; |
| 25 case ConnectionTypeEthernet: | 26 case ConnectionTypeEthernet: |
| 26 return "ethernet"; | 27 return "ethernet"; |
| 27 case ConnectionTypeWifi: | 28 case ConnectionTypeWifi: |
| 28 return "wifi"; | 29 return "wifi"; |
| 30 case ConnectionTypeWimax: |
| 31 return "wimax"; |
| 29 case ConnectionTypeOther: | 32 case ConnectionTypeOther: |
| 30 return "other"; | 33 return "other"; |
| 31 case ConnectionTypeNone: | 34 case ConnectionTypeNone: |
| 32 return "none"; | 35 return "none"; |
| 33 case ConnectionTypeUnknown: | 36 case ConnectionTypeUnknown: |
| 34 return "unknown"; | 37 return "unknown"; |
| 35 } | 38 } |
| 36 ASSERT_NOT_REACHED(); | 39 ASSERT_NOT_REACHED(); |
| 37 return "none"; | 40 return "none"; |
| 38 } | 41 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 57 { | 60 { |
| 58 // m_type is only updated when listening for events, so ask networkStateNoti
fier | 61 // m_type is only updated when listening for events, so ask networkStateNoti
fier |
| 59 // if not listening (crbug.com/379841). | 62 // if not listening (crbug.com/379841). |
| 60 if (!m_observing) | 63 if (!m_observing) |
| 61 return connectionTypeToString(networkStateNotifier().connectionType()); | 64 return connectionTypeToString(networkStateNotifier().connectionType()); |
| 62 | 65 |
| 63 // If observing, return m_type which changes when the event fires, per spec. | 66 // If observing, return m_type which changes when the event fires, per spec. |
| 64 return connectionTypeToString(m_type); | 67 return connectionTypeToString(m_type); |
| 65 } | 68 } |
| 66 | 69 |
| 67 void NetworkInformation::connectionTypeChange(WebConnectionType type) | 70 double NetworkInformation::downlinkMax() const |
| 71 { |
| 72 if (!m_observing) |
| 73 return networkStateNotifier().maxBandwidth(); |
| 74 |
| 75 return m_downlinkMaxMbps; |
| 76 } |
| 77 |
| 78 void NetworkInformation::connectionChange(WebConnectionType type, double downlin
kMaxMbps) |
| 68 { | 79 { |
| 69 ASSERT(executionContext()->isContextThread()); | 80 ASSERT(executionContext()->isContextThread()); |
| 70 | 81 |
| 71 // This can happen if the observer removes and then adds itself again | 82 // This can happen if the observer removes and then adds itself again |
| 72 // during notification. | 83 // during notification. |
| 73 if (m_type == type) | 84 if (m_type == type && m_downlinkMaxMbps == downlinkMaxMbps) |
| 74 return; | 85 return; |
| 75 | 86 |
| 76 m_type = type; | 87 m_type = type; |
| 88 m_downlinkMaxMbps = downlinkMaxMbps; |
| 77 dispatchEvent(Event::create(EventTypeNames::typechange)); | 89 dispatchEvent(Event::create(EventTypeNames::typechange)); |
| 90 |
| 91 if (RuntimeEnabledFeatures::netInfoDownlinkMaxEnabled()) |
| 92 dispatchEvent(Event::create(EventTypeNames::change)); |
| 78 } | 93 } |
| 79 | 94 |
| 80 const AtomicString& NetworkInformation::interfaceName() const | 95 const AtomicString& NetworkInformation::interfaceName() const |
| 81 { | 96 { |
| 82 return EventTargetNames::NetworkInformation; | 97 return EventTargetNames::NetworkInformation; |
| 83 } | 98 } |
| 84 | 99 |
| 85 ExecutionContext* NetworkInformation::executionContext() const | 100 ExecutionContext* NetworkInformation::executionContext() const |
| 86 { | 101 { |
| 87 return ActiveDOMObject::executionContext(); | 102 return ActiveDOMObject::executionContext(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 { | 153 { |
| 139 if (m_observing) { | 154 if (m_observing) { |
| 140 networkStateNotifier().removeObserver(this, executionContext()); | 155 networkStateNotifier().removeObserver(this, executionContext()); |
| 141 m_observing = false; | 156 m_observing = false; |
| 142 } | 157 } |
| 143 } | 158 } |
| 144 | 159 |
| 145 NetworkInformation::NetworkInformation(ExecutionContext* context) | 160 NetworkInformation::NetworkInformation(ExecutionContext* context) |
| 146 : ActiveDOMObject(context) | 161 : ActiveDOMObject(context) |
| 147 , m_type(networkStateNotifier().connectionType()) | 162 , m_type(networkStateNotifier().connectionType()) |
| 163 , m_downlinkMaxMbps(networkStateNotifier().maxBandwidth()) |
| 148 , m_observing(false) | 164 , m_observing(false) |
| 149 , m_contextStopped(false) | 165 , m_contextStopped(false) |
| 150 { | 166 { |
| 151 } | 167 } |
| 152 | 168 |
| 153 DEFINE_TRACE(NetworkInformation) | 169 DEFINE_TRACE(NetworkInformation) |
| 154 { | 170 { |
| 155 RefCountedGarbageCollectedEventTargetWithInlineData<NetworkInformation>::tra
ce(visitor); | 171 RefCountedGarbageCollectedEventTargetWithInlineData<NetworkInformation>::tra
ce(visitor); |
| 156 ActiveDOMObject::trace(visitor); | 172 ActiveDOMObject::trace(visitor); |
| 157 } | 173 } |
| 158 | 174 |
| 159 } // namespace blink | 175 } // namespace blink |
| OLD | NEW |