| 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..d3600fc529d72c97fe4cf34f31307a8da534f64f 100644
|
| --- a/third_party/WebKit/Source/core/page/NetworkStateNotifier.h
|
| +++ b/third_party/WebKit/Source/core/page/NetworkStateNotifier.h
|
| @@ -52,7 +52,10 @@ public:
|
| , m_isOnLine(true)
|
| , m_type(WebConnectionTypeOther)
|
| , m_maxBandwidthMbps(kInvalidMaxBandwidth)
|
| - , m_testUpdatesOnly(false)
|
| + , m_hasOverride(false)
|
| + , m_overrideOnLine(true)
|
| + , m_overrideType(WebConnectionTypeOther)
|
| + , m_overrideMaxBandwidthMbps(kInvalidMaxBandwidth)
|
| {
|
| }
|
|
|
| @@ -61,7 +64,7 @@ public:
|
| {
|
| MutexLocker locker(m_mutex);
|
| ASSERT(m_initialized);
|
| - return m_isOnLine;
|
| + return m_hasOverride ? m_overrideOnLine : m_isOnLine;
|
| }
|
|
|
| void setOnLine(bool);
|
| @@ -71,7 +74,7 @@ public:
|
| {
|
| MutexLocker locker(m_mutex);
|
| ASSERT(m_initialized);
|
| - return m_type;
|
| + return m_hasOverride ? m_overrideType : m_type;
|
| }
|
|
|
| // Can be called on any thread.
|
| @@ -100,11 +103,21 @@ public:
|
| {
|
| MutexLocker locker(m_mutex);
|
| ASSERT(m_initialized);
|
| - return m_maxBandwidthMbps;
|
| + 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 +125,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 +138,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*);
|
| @@ -160,7 +159,10 @@ private:
|
| 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();
|
|
|