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

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

Issue 289333003: Adds type information to the NetworkStateNotifier. Also allows for registration of observers. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Remove unused member Created 6 years, 7 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
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/page/NetworkStateNotifier.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/page/NetworkStateNotifier.h
diff --git a/Source/core/page/NetworkStateNotifier.h b/Source/core/page/NetworkStateNotifier.h
index 7e5fb725d6ed50145f3b1ecab2a47a7eff2bd009..2759274ae6b809d126db871f13dd0fca22d4dbaf 100644
--- a/Source/core/page/NetworkStateNotifier.h
+++ b/Source/core/page/NetworkStateNotifier.h
@@ -26,17 +26,31 @@
#ifndef NetworkStateNotifier_h
#define NetworkStateNotifier_h
+#include "public/platform/WebConnectionType.h"
#include "wtf/FastAllocBase.h"
+#include "wtf/HashMap.h"
#include "wtf/Noncopyable.h"
#include "wtf/ThreadingPrimitives.h"
+#include "wtf/Vector.h"
namespace WebCore {
+class ExecutionContext;
+
class NetworkStateNotifier {
WTF_MAKE_NONCOPYABLE(NetworkStateNotifier); WTF_MAKE_FAST_ALLOCATED;
public:
+ class NetworkStateObserver {
+ public:
+ // Will be called on the thread of the context passed in addObserver.
+ virtual void connectionTypeChange(blink::WebConnectionType) = 0;
+ };
+
NetworkStateNotifier()
- : m_isOnLine(true) { }
+ : m_isOnLine(true)
+ , m_type(blink::ConnectionTypeOther)
+ {
+ }
bool onLine() const
{
@@ -46,13 +60,49 @@ public:
void setOnLine(bool);
+ blink::WebConnectionType connectionType() const
+ {
+ MutexLocker locker(m_mutex);
+ return m_type;
+ }
+
+ void setWebConnectionType(blink::WebConnectionType);
+
+ // Must be called on the context's thread. An added observer must be
+ // removed before its ExecutionContext is deleted.
+ void addObserver(NetworkStateObserver*, ExecutionContext*);
+ void removeObserver(NetworkStateObserver*, ExecutionContext*);
+
private:
+ struct ObserverList {
+ ObserverList()
+ : iterating(false)
+ {
+ }
+ bool iterating;
+ Vector<NetworkStateObserver*> observers;
+ Vector<size_t> zeroedObservers; // Indices in observers that are 0.
+ };
+
+ typedef HashMap<ExecutionContext*, OwnPtr<ObserverList> > ObserverListMap;
+
+ void notifyObserversOnContext(ExecutionContext*, blink::WebConnectionType);
+
+ ObserverList* lockAndFindObserverList(ExecutionContext*);
+
+ // Removed observers are nulled out in the list in case the list is being
+ // iterated over. Once done iterating, call this to clean up nulled
+ // observers.
+ void collectZeroedObservers(ObserverList*, ExecutionContext*);
+
mutable Mutex m_mutex;
bool m_isOnLine;
+ blink::WebConnectionType m_type;
+ ObserverListMap m_observers;
};
NetworkStateNotifier& networkStateNotifier();
-};
+} // namespace WebCore
#endif // NetworkStateNotifier_h
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/page/NetworkStateNotifier.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698