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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 double NetworkInformation::downlinkMax() const | 71 double NetworkInformation::downlinkMax() const |
72 { | 72 { |
73 if (!m_observing) | 73 if (!m_observing) |
74 return networkStateNotifier().maxBandwidth(); | 74 return networkStateNotifier().maxBandwidth(); |
75 | 75 |
76 return m_downlinkMaxMbps; | 76 return m_downlinkMaxMbps; |
77 } | 77 } |
78 | 78 |
79 void NetworkInformation::connectionChange(WebConnectionType type, double downlin
kMaxMbps) | 79 void NetworkInformation::connectionChange(WebConnectionType type, double downlin
kMaxMbps) |
80 { | 80 { |
81 ASSERT(executionContext()->isContextThread()); | 81 ASSERT(getExecutionContext()->isContextThread()); |
82 | 82 |
83 // This can happen if the observer removes and then adds itself again | 83 // This can happen if the observer removes and then adds itself again |
84 // during notification. | 84 // during notification. |
85 if (m_type == type && m_downlinkMaxMbps == downlinkMaxMbps) | 85 if (m_type == type && m_downlinkMaxMbps == downlinkMaxMbps) |
86 return; | 86 return; |
87 | 87 |
88 m_type = type; | 88 m_type = type; |
89 m_downlinkMaxMbps = downlinkMaxMbps; | 89 m_downlinkMaxMbps = downlinkMaxMbps; |
90 dispatchEvent(Event::create(EventTypeNames::typechange)); | 90 dispatchEvent(Event::create(EventTypeNames::typechange)); |
91 | 91 |
92 if (RuntimeEnabledFeatures::netInfoDownlinkMaxEnabled()) | 92 if (RuntimeEnabledFeatures::netInfoDownlinkMaxEnabled()) |
93 dispatchEvent(Event::create(EventTypeNames::change)); | 93 dispatchEvent(Event::create(EventTypeNames::change)); |
94 } | 94 } |
95 | 95 |
96 const AtomicString& NetworkInformation::interfaceName() const | 96 const AtomicString& NetworkInformation::interfaceName() const |
97 { | 97 { |
98 return EventTargetNames::NetworkInformation; | 98 return EventTargetNames::NetworkInformation; |
99 } | 99 } |
100 | 100 |
101 ExecutionContext* NetworkInformation::executionContext() const | 101 ExecutionContext* NetworkInformation::getExecutionContext() const |
102 { | 102 { |
103 return ActiveDOMObject::executionContext(); | 103 return ActiveDOMObject::getExecutionContext(); |
104 } | 104 } |
105 | 105 |
106 bool NetworkInformation::addEventListenerInternal(const AtomicString& eventType,
PassRefPtrWillBeRawPtr<EventListener> listener, const EventListenerOptions& opt
ions) | 106 bool NetworkInformation::addEventListenerInternal(const AtomicString& eventType,
PassRefPtrWillBeRawPtr<EventListener> listener, const EventListenerOptions& opt
ions) |
107 { | 107 { |
108 if (!EventTargetWithInlineData::addEventListenerInternal(eventType, listener
, options)) | 108 if (!EventTargetWithInlineData::addEventListenerInternal(eventType, listener
, options)) |
109 return false; | 109 return false; |
110 startObserving(); | 110 startObserving(); |
111 return true; | 111 return true; |
112 } | 112 } |
113 | 113 |
(...skipping 24 matching lines...) Expand all Loading... |
138 void NetworkInformation::stop() | 138 void NetworkInformation::stop() |
139 { | 139 { |
140 m_contextStopped = true; | 140 m_contextStopped = true; |
141 stopObserving(); | 141 stopObserving(); |
142 } | 142 } |
143 | 143 |
144 void NetworkInformation::startObserving() | 144 void NetworkInformation::startObserving() |
145 { | 145 { |
146 if (!m_observing && !m_contextStopped) { | 146 if (!m_observing && !m_contextStopped) { |
147 m_type = networkStateNotifier().connectionType(); | 147 m_type = networkStateNotifier().connectionType(); |
148 networkStateNotifier().addObserver(this, executionContext()); | 148 networkStateNotifier().addObserver(this, getExecutionContext()); |
149 m_observing = true; | 149 m_observing = true; |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 void NetworkInformation::stopObserving() | 153 void NetworkInformation::stopObserving() |
154 { | 154 { |
155 if (m_observing) { | 155 if (m_observing) { |
156 networkStateNotifier().removeObserver(this, executionContext()); | 156 networkStateNotifier().removeObserver(this, getExecutionContext()); |
157 m_observing = false; | 157 m_observing = false; |
158 } | 158 } |
159 } | 159 } |
160 | 160 |
161 NetworkInformation::NetworkInformation(ExecutionContext* context) | 161 NetworkInformation::NetworkInformation(ExecutionContext* context) |
162 : ActiveDOMObject(context) | 162 : ActiveDOMObject(context) |
163 , m_type(networkStateNotifier().connectionType()) | 163 , m_type(networkStateNotifier().connectionType()) |
164 , m_downlinkMaxMbps(networkStateNotifier().maxBandwidth()) | 164 , m_downlinkMaxMbps(networkStateNotifier().maxBandwidth()) |
165 , m_observing(false) | 165 , m_observing(false) |
166 , m_contextStopped(false) | 166 , m_contextStopped(false) |
167 { | 167 { |
168 } | 168 } |
169 | 169 |
170 DEFINE_TRACE(NetworkInformation) | 170 DEFINE_TRACE(NetworkInformation) |
171 { | 171 { |
172 RefCountedGarbageCollectedEventTargetWithInlineData<NetworkInformation>::tra
ce(visitor); | 172 RefCountedGarbageCollectedEventTargetWithInlineData<NetworkInformation>::tra
ce(visitor); |
173 ActiveDOMObject::trace(visitor); | 173 ActiveDOMObject::trace(visitor); |
174 } | 174 } |
175 | 175 |
176 } // namespace blink | 176 } // namespace blink |
OLD | NEW |