Chromium Code Reviews| Index: third_party/WebKit/Source/core/page/NetworkStateNotifier.cpp |
| diff --git a/third_party/WebKit/Source/core/page/NetworkStateNotifier.cpp b/third_party/WebKit/Source/core/page/NetworkStateNotifier.cpp |
| index e6658bded3b8b61266228af695f071f8062ddfe4..b913828c513b2e55e6af120129933dfa8236bb4c 100644 |
| --- a/third_party/WebKit/Source/core/page/NetworkStateNotifier.cpp |
| +++ b/third_party/WebKit/Source/core/page/NetworkStateNotifier.cpp |
| @@ -42,28 +42,42 @@ NetworkStateNotifier& networkStateNotifier() |
| return networkStateNotifier; |
| } |
| -void NetworkStateNotifier::setOnLine(bool onLine) |
| +void NetworkStateNotifier::setOnLine(bool onLineValue) |
| { |
| - ASSERT(isMainThread()); |
| + DCHECK(isMainThread()); |
| { |
| MutexLocker locker(m_mutex); |
| - if (m_isOnLine == onLine) |
| + if (m_isOnLine == onLineValue) |
| return; |
| - m_isOnLine = onLine; |
| + m_isOnLine = onLineValue; |
| + |
| + if (m_hasOverride) |
| + return; |
| } |
| - Page::networkStateChanged(onLine); |
| + Page::networkStateChanged(onLine()); |
| } |
| void NetworkStateNotifier::setWebConnection(WebConnectionType type, double maxBandwidthMbps) |
| { |
| - ASSERT(isMainThread()); |
| - if (m_testUpdatesOnly) |
| - return; |
| + DCHECK(isMainThread()); |
| + |
| + { |
| + MutexLocker locker(m_mutex); |
| + m_initialized = true; |
| + |
| + if (m_type == type && m_maxBandwidthMbps == maxBandwidthMbps) |
| + return; |
| + m_type = type; |
| + m_maxBandwidthMbps = maxBandwidthMbps; |
| + |
| + if (m_hasOverride) |
| + return; |
| + } |
| - setWebConnectionImpl(type, maxBandwidthMbps); |
| + notifyObservers(); |
| } |
| void NetworkStateNotifier::addObserver(NetworkStateObserver* observer, ExecutionContext* context) |
| @@ -100,40 +114,44 @@ void NetworkStateNotifier::removeObserver(NetworkStateObserver* observer, Execut |
| collectZeroedObservers(observerList, context); |
| } |
| -void NetworkStateNotifier::setTestUpdatesOnly(bool updatesOnly) |
| +void NetworkStateNotifier::setOverride(bool onLineValue, WebConnectionType type, double maxBandwidthMbps) |
| { |
| - ASSERT(isMainThread()); |
| - MutexLocker locker(m_mutex); |
| + DCHECK(isMainThread()); |
| - // Reset state to default when entering or leaving test mode. |
| - if (updatesOnly != m_testUpdatesOnly) { |
| - m_isOnLine = true; |
| - m_type = WebConnectionTypeOther; |
| - m_maxBandwidthMbps = std::numeric_limits<double>::infinity(); |
| + { |
| + MutexLocker locker(m_mutex); |
| + m_initialized = true; |
| + m_hasOverride = true; |
| + m_overrideOnLine = onLineValue; |
| + m_overrideType = type; |
| + m_overrideMaxBandwidthMbps = maxBandwidthMbps; |
| } |
| - m_testUpdatesOnly = updatesOnly; |
| + notifyObservers(); |
| + Page::networkStateChanged(onLine()); |
| } |
| -void NetworkStateNotifier::setWebConnectionForTest(WebConnectionType type, double maxBandwidthMbps) |
| +void NetworkStateNotifier::clearOverride() |
| { |
| - ASSERT(isMainThread()); |
| - ASSERT(m_testUpdatesOnly); |
| - setWebConnectionImpl(type, maxBandwidthMbps); |
| + DCHECK(isMainThread()); |
| + |
| + { |
| + MutexLocker locker(m_mutex); |
| + DCHECK(m_initialized); |
| + m_hasOverride = false; |
| + } |
| + |
| + notifyObservers(); |
| + Page::networkStateChanged(onLine()); |
| } |
| -void NetworkStateNotifier::setWebConnectionImpl(WebConnectionType type, double maxBandwidthMbps) |
| +void NetworkStateNotifier::notifyObservers() |
| { |
| ASSERT(isMainThread()); |
| + WebConnectionType type = connectionType(); |
| + double maxBandwidthMbps = maxBandwidth(); |
|
jkarlin
2016/06/23 12:53:46
The underlying values of type and bandwidth might
dgozman
2016/06/23 15:00:22
How is that possible? Both notifyObservers and all
jkarlin
2016/06/24 14:47:50
Oh right, good point about this all running on the
|
| MutexLocker locker(m_mutex); |
| - m_initialized = true; |
| - |
| - if (m_type == type && m_maxBandwidthMbps == maxBandwidthMbps) |
| - return; |
| - m_type = type; |
| - m_maxBandwidthMbps = maxBandwidthMbps; |
| - |
| for (const auto& entry : m_observers) { |
| ExecutionContext* context = entry.key; |
| context->postTask(BLINK_FROM_HERE, createCrossThreadTask(&NetworkStateNotifier::notifyObserversOfConnectionChangeOnContext, AllowCrossThreadAccess(this), type, maxBandwidthMbps)); |