Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(601)

Unified Diff: third_party/WebKit/Source/core/page/NetworkStateNotifier.h

Issue 2087293003: [DevTools] Network.emulateNetworkConditions now affects NetworkStateNotifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: proper initialized checks Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/page/NetworkStateNotifier.h
diff --git a/third_party/WebKit/Source/core/page/NetworkStateNotifier.h b/third_party/WebKit/Source/core/page/NetworkStateNotifier.h
index f25348326696b0878417f9c196ede217120dfa30..e2e36ffed22e8ad5c849d380dd838d4eb9a0c73b 100644
--- a/third_party/WebKit/Source/core/page/NetworkStateNotifier.h
+++ b/third_party/WebKit/Source/core/page/NetworkStateNotifier.h
@@ -48,11 +48,15 @@ public:
};
NetworkStateNotifier()
- : m_initialized(false)
+ : m_onLineInitialized(false)
, m_isOnLine(true)
+ , m_connectionInitialized(false)
, m_type(WebConnectionTypeOther)
, m_maxBandwidthMbps(kInvalidMaxBandwidth)
- , m_testUpdatesOnly(false)
+ , m_hasOverride(false)
+ , m_overrideOnLine(true)
+ , m_overrideType(WebConnectionTypeOther)
+ , m_overrideMaxBandwidthMbps(kInvalidMaxBandwidth)
{
}
@@ -60,8 +64,8 @@ public:
bool onLine() const
{
MutexLocker locker(m_mutex);
- ASSERT(m_initialized);
- return m_isOnLine;
+ DCHECK(m_hasOverride || m_onLineInitialized);
+ return m_hasOverride ? m_overrideOnLine : m_isOnLine;
}
void setOnLine(bool);
@@ -70,8 +74,8 @@ public:
WebConnectionType connectionType() const
{
MutexLocker locker(m_mutex);
- ASSERT(m_initialized);
- return m_type;
+ DCHECK(m_hasOverride || m_connectionInitialized);
+ return m_hasOverride ? m_overrideType : m_type;
}
// Can be called on any thread.
@@ -99,12 +103,22 @@ public:
double maxBandwidth() const
{
MutexLocker locker(m_mutex);
- ASSERT(m_initialized);
- return m_maxBandwidthMbps;
+ DCHECK(m_hasOverride || m_connectionInitialized);
+ return m_hasOverride ? m_overrideMaxBandwidthMbps : m_maxBandwidthMbps;
}
void setWebConnection(WebConnectionType, double maxBandwidthMbps);
+ // When called, successive setWebConnectionType/setOnLine calls are ignored,
+ // and supplied overridden values are used instead.
+ // This is used for layout tests (see crbug.com/377736) and inspector emulation.
+ //
+ // Since this class is a singleton, tests must clear override when completed to
+ // avoid indeterminate state across the test harness. When switching in or out of test
+ // mode, all state will be reset to default values.
+ void setOverride(bool onLine, WebConnectionType, double maxBandwidthMbps);
+ void clearOverride();
+
// Must be called on the context's thread. An added observer must be removed
// before its ExecutionContext is deleted. It's possible for an observer to
// be called twice for the same event if it is first removed and then added
@@ -112,18 +126,6 @@ public:
void addObserver(NetworkStateObserver*, ExecutionContext*);
void removeObserver(NetworkStateObserver*, ExecutionContext*);
- // The following functions are for testing purposes.
-
- // When true, setWebConnectionType calls are ignored and only setWebConnectionTypeForTest
- // can update the connection type. This is used for layout tests (see crbug.com/377736).
- //
- // Since this class is a singleton, tests must call this with false when completed to
- // avoid indeterminate state across the test harness. When switching in or out of test
- // mode, all state will be reset to default values.
- void setTestUpdatesOnly(bool);
- // Tests should call this as it will change the type regardless of the value of m_testUpdatesOnly.
- void setWebConnectionForTest(WebConnectionType, double maxBandwidthMbps);
-
private:
struct ObserverList {
ObserverList()
@@ -137,14 +139,12 @@ private:
const int kInvalidMaxBandwidth = -1;
- void setWebConnectionImpl(WebConnectionType, double maxBandwidthMbps);
- void setMaxBandwidthImpl(double maxBandwidthMbps);
-
// The ObserverListMap is cross-thread accessed, adding/removing Observers running
// within an ExecutionContext. Kept off-heap to ease cross-thread allocation and use;
// the observers are (already) responsible for explicitly unregistering while finalizing.
using ObserverListMap = HashMap<UntracedMember<ExecutionContext>, std::unique_ptr<ObserverList>>;
+ void notifyObservers();
void notifyObserversOfConnectionChangeOnContext(WebConnectionType, double maxBandwidthMbps, ExecutionContext*);
ObserverList* lockAndFindObserverList(ExecutionContext*);
@@ -155,12 +155,16 @@ private:
void collectZeroedObservers(ObserverList*, ExecutionContext*);
mutable Mutex m_mutex;
- bool m_initialized;
+ bool m_onLineInitialized;
bool m_isOnLine;
+ bool m_connectionInitialized;
WebConnectionType m_type;
double m_maxBandwidthMbps;
ObserverListMap m_observers;
- bool m_testUpdatesOnly;
+ bool m_hasOverride;
+ bool m_overrideOnLine;
+ WebConnectionType m_overrideType;
+ double m_overrideMaxBandwidthMbps;
};
CORE_EXPORT NetworkStateNotifier& networkStateNotifier();

Powered by Google App Engine
This is Rietveld 408576698