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 628b377de6a04f3f2954bf2f6754bb7eb38ceb58..d7b8e08af3a86ec1f9411d8834c60197a53bb41c 100644 |
--- a/third_party/WebKit/Source/core/page/NetworkStateNotifier.cpp |
+++ b/third_party/WebKit/Source/core/page/NetworkStateNotifier.cpp |
@@ -42,28 +42,43 @@ 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) |
+ m_onLineInitialized = true; |
+ |
+ if (m_isOnLine == onLineValue) |
return; |
+ m_isOnLine = onLineValue; |
- m_isOnLine = onLine; |
+ 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_connectionInitialized = 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 +115,42 @@ 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_hasOverride = true; |
+ m_overrideOnLine = onLineValue; |
+ m_overrideType = type; |
+ m_overrideMaxBandwidthMbps = maxBandwidthMbps; |
} |
- m_testUpdatesOnly = updatesOnly; |
+ notifyObservers(); |
+ Page::networkStateChanged(onLine()); |
jkarlin
2016/06/24 14:47:50
setOnline and setWebConnection check if anything h
dgozman
2016/06/24 15:13:44
I think this would be undesirable. Consider two ca
jkarlin
2016/06/24 19:20:16
The clients of NetworkStateNotifier (e.g., the onl
dgozman
2016/06/27 23:03:49
Alright, you convinced me. Can't go against the sp
|
} |
-void NetworkStateNotifier::setWebConnectionForTest(WebConnectionType type, double maxBandwidthMbps) |
+void NetworkStateNotifier::clearOverride() |
{ |
- ASSERT(isMainThread()); |
- ASSERT(m_testUpdatesOnly); |
- setWebConnectionImpl(type, maxBandwidthMbps); |
+ DCHECK(isMainThread()); |
+ |
+ { |
+ MutexLocker locker(m_mutex); |
+ m_hasOverride = false; |
+ } |
+ |
+ notifyObservers(); |
+ Page::networkStateChanged(onLine()); |
jkarlin
2016/06/24 14:47:50
setOnline and setWebConnection check if anything h
|
} |
-void NetworkStateNotifier::setWebConnectionImpl(WebConnectionType type, double maxBandwidthMbps) |
+void NetworkStateNotifier::notifyObservers() |
{ |
ASSERT(isMainThread()); |
+ WebConnectionType type = connectionType(); |
+ double maxBandwidthMbps = maxBandwidth(); |
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, crossThreadUnretained(this), type, maxBandwidthMbps)); |