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

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: Thread safe observer list 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 | « no previous file | Source/core/page/NetworkStateNotifier.cpp » ('j') | Source/core/page/NetworkStateNotifier.cpp » ('J')
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..933511d3f170eac7df80de2a1852070b11c9b7f7 100644
--- a/Source/core/page/NetworkStateNotifier.h
+++ b/Source/core/page/NetworkStateNotifier.h
@@ -26,17 +26,34 @@
#ifndef NetworkStateNotifier_h
#define NetworkStateNotifier_h
+#include "public/platform/WebNetworkConnection.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::WebNetworkConnection::ConnectionType) = 0;
adamk 2014/05/20 15:00:36 Nit: Don't break lines like this in Blink; there's
jkarlin 2014/05/20 16:20:23 Done.
+ };
+
+ typedef NetworkStateObserver* ObserverType;
adamk 2014/05/20 15:00:36 I found this typedef a bit confusing while reading
jkarlin 2014/05/20 16:20:23 Done.
+
NetworkStateNotifier()
- : m_isOnLine(true) { }
+ : m_isOnLine(true)
+ , m_type(blink::WebNetworkConnection::Other)
+ {
+ }
bool onLine() const
{
@@ -46,13 +63,41 @@ public:
void setOnLine(bool);
+ blink::WebNetworkConnection::ConnectionType connectionType() const
+ {
+ MutexLocker locker(m_mutex);
+ return m_type;
+ }
+
+ void setWebConnectionType(blink::WebNetworkConnection::ConnectionType);
+
+ // Must be called on the context's thread. Do not call add/removeObserver
+ // while handling a connectionTypeChange notification as it mutates the
+ // container while it's being iterated over.
+ void addObserver(ObserverType, ExecutionContext*);
+ void removeObserver(ObserverType, ExecutionContext*);
+
private:
+ struct ObserverList {
+ ObserverList()
+ : iterating(false)
+ {
+ }
+ bool iterating;
+ Vector<ObserverType> observers;
+ };
+
+ typedef HashMap<ExecutionContext*, ObserverList> ObserverListMap;
+
+ void notifyObserversOnContext(ExecutionContext*, blink::WebNetworkConnection::ConnectionType);
+
mutable Mutex m_mutex;
bool m_isOnLine;
+ blink::WebNetworkConnection::ConnectionType m_type;
+ ObserverListMap m_observers;
};
NetworkStateNotifier& networkStateNotifier();
-
adamk 2014/05/20 15:00:36 Nit: I'd leave this blank line.
-};
+}
adamk 2014/05/20 15:00:36 and maybe add a "// namespace WebCore" comment
jkarlin 2014/05/20 16:20:23 Done.
#endif // NetworkStateNotifier_h
« no previous file with comments | « no previous file | Source/core/page/NetworkStateNotifier.cpp » ('j') | Source/core/page/NetworkStateNotifier.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698