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/events/Event.h" | 9 #include "core/events/Event.h" |
9 #include "core/page/NetworkStateNotifier.h" | 10 #include "core/page/NetworkStateNotifier.h" |
10 #include "modules/EventTargetModules.h" | 11 #include "modules/EventTargetModules.h" |
11 #include "platform/RuntimeEnabledFeatures.h" | 12 #include "platform/RuntimeEnabledFeatures.h" |
12 #include "wtf/text/WTFString.h" | 13 #include "wtf/text/WTFString.h" |
13 | 14 |
14 namespace blink { | 15 namespace blink { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } | 123 } |
123 | 124 |
124 void NetworkInformation::contextDestroyed(ExecutionContext*) { | 125 void NetworkInformation::contextDestroyed(ExecutionContext*) { |
125 m_contextStopped = true; | 126 m_contextStopped = true; |
126 stopObserving(); | 127 stopObserving(); |
127 } | 128 } |
128 | 129 |
129 void NetworkInformation::startObserving() { | 130 void NetworkInformation::startObserving() { |
130 if (!m_observing && !m_contextStopped) { | 131 if (!m_observing && !m_contextStopped) { |
131 m_type = networkStateNotifier().connectionType(); | 132 m_type = networkStateNotifier().connectionType(); |
132 networkStateNotifier().addObserver(this, getExecutionContext()); | 133 networkStateNotifier().addObserver( |
| 134 this, TaskRunnerHelper::get(TaskType::Networking, getExecutionContext()) |
| 135 .get()); |
133 m_observing = true; | 136 m_observing = true; |
134 } | 137 } |
135 } | 138 } |
136 | 139 |
137 void NetworkInformation::stopObserving() { | 140 void NetworkInformation::stopObserving() { |
138 if (m_observing) { | 141 if (m_observing) { |
139 networkStateNotifier().removeObserver(this, getExecutionContext()); | 142 networkStateNotifier().removeObserver( |
| 143 this, TaskRunnerHelper::get(TaskType::Networking, getExecutionContext()) |
| 144 .get()); |
140 m_observing = false; | 145 m_observing = false; |
141 } | 146 } |
142 } | 147 } |
143 | 148 |
144 NetworkInformation::NetworkInformation(ExecutionContext* context) | 149 NetworkInformation::NetworkInformation(ExecutionContext* context) |
145 : ContextLifecycleObserver(context), | 150 : ContextLifecycleObserver(context), |
146 m_type(networkStateNotifier().connectionType()), | 151 m_type(networkStateNotifier().connectionType()), |
147 m_downlinkMaxMbps(networkStateNotifier().maxBandwidth()), | 152 m_downlinkMaxMbps(networkStateNotifier().maxBandwidth()), |
148 m_observing(false), | 153 m_observing(false), |
149 m_contextStopped(false) {} | 154 m_contextStopped(false) {} |
150 | 155 |
151 DEFINE_TRACE(NetworkInformation) { | 156 DEFINE_TRACE(NetworkInformation) { |
152 EventTargetWithInlineData::trace(visitor); | 157 EventTargetWithInlineData::trace(visitor); |
153 ContextLifecycleObserver::trace(visitor); | 158 ContextLifecycleObserver::trace(visitor); |
154 } | 159 } |
155 | 160 |
156 } // namespace blink | 161 } // namespace blink |
OLD | NEW |