OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 16 matching lines...) Expand all Loading... |
27 #define NetworkStateNotifier_h | 27 #define NetworkStateNotifier_h |
28 | 28 |
29 #include "core/CoreExport.h" | 29 #include "core/CoreExport.h" |
30 #include "core/dom/ExecutionContext.h" | 30 #include "core/dom/ExecutionContext.h" |
31 #include "public/platform/WebConnectionType.h" | 31 #include "public/platform/WebConnectionType.h" |
32 #include "wtf/Allocator.h" | 32 #include "wtf/Allocator.h" |
33 #include "wtf/HashMap.h" | 33 #include "wtf/HashMap.h" |
34 #include "wtf/Noncopyable.h" | 34 #include "wtf/Noncopyable.h" |
35 #include "wtf/ThreadingPrimitives.h" | 35 #include "wtf/ThreadingPrimitives.h" |
36 #include "wtf/Vector.h" | 36 #include "wtf/Vector.h" |
37 #include <memory> | |
38 | 37 |
39 namespace blink { | 38 namespace blink { |
40 | 39 |
41 class CORE_EXPORT NetworkStateNotifier { | 40 class CORE_EXPORT NetworkStateNotifier { |
42 WTF_MAKE_NONCOPYABLE(NetworkStateNotifier); USING_FAST_MALLOC(NetworkStateNo
tifier); | 41 WTF_MAKE_NONCOPYABLE(NetworkStateNotifier); USING_FAST_MALLOC(NetworkStateNo
tifier); |
43 public: | 42 public: |
44 class NetworkStateObserver { | 43 class NetworkStateObserver { |
45 public: | 44 public: |
46 // Will be called on the thread of the context passed in addObserver. | 45 // Will be called on the thread of the context passed in addObserver. |
47 virtual void connectionChange(WebConnectionType, double maxBandwidthMbps
) = 0; | 46 virtual void connectionChange(WebConnectionType, double maxBandwidthMbps
) = 0; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 }; | 135 }; |
137 | 136 |
138 const int kInvalidMaxBandwidth = -1; | 137 const int kInvalidMaxBandwidth = -1; |
139 | 138 |
140 void setWebConnectionImpl(WebConnectionType, double maxBandwidthMbps); | 139 void setWebConnectionImpl(WebConnectionType, double maxBandwidthMbps); |
141 void setMaxBandwidthImpl(double maxBandwidthMbps); | 140 void setMaxBandwidthImpl(double maxBandwidthMbps); |
142 | 141 |
143 // The ObserverListMap is cross-thread accessed, adding/removing Observers r
unning | 142 // The ObserverListMap is cross-thread accessed, adding/removing Observers r
unning |
144 // within an ExecutionContext. Kept off-heap to ease cross-thread allocation
and use; | 143 // within an ExecutionContext. Kept off-heap to ease cross-thread allocation
and use; |
145 // the observers are (already) responsible for explicitly unregistering whil
e finalizing. | 144 // the observers are (already) responsible for explicitly unregistering whil
e finalizing. |
146 using ObserverListMap = HashMap<UntracedMember<ExecutionContext>, std::uniqu
e_ptr<ObserverList>>; | 145 using ObserverListMap = HashMap<UntracedMember<ExecutionContext>, OwnPtr<Obs
erverList>>; |
147 | 146 |
148 void notifyObserversOfConnectionChangeOnContext(WebConnectionType, double ma
xBandwidthMbps, ExecutionContext*); | 147 void notifyObserversOfConnectionChangeOnContext(WebConnectionType, double ma
xBandwidthMbps, ExecutionContext*); |
149 | 148 |
150 ObserverList* lockAndFindObserverList(ExecutionContext*); | 149 ObserverList* lockAndFindObserverList(ExecutionContext*); |
151 | 150 |
152 // Removed observers are nulled out in the list in case the list is being | 151 // Removed observers are nulled out in the list in case the list is being |
153 // iterated over. Once done iterating, call this to clean up nulled | 152 // iterated over. Once done iterating, call this to clean up nulled |
154 // observers. | 153 // observers. |
155 void collectZeroedObservers(ObserverList*, ExecutionContext*); | 154 void collectZeroedObservers(ObserverList*, ExecutionContext*); |
156 | 155 |
157 mutable Mutex m_mutex; | 156 mutable Mutex m_mutex; |
158 bool m_initialized; | 157 bool m_initialized; |
159 bool m_isOnLine; | 158 bool m_isOnLine; |
160 WebConnectionType m_type; | 159 WebConnectionType m_type; |
161 double m_maxBandwidthMbps; | 160 double m_maxBandwidthMbps; |
162 ObserverListMap m_observers; | 161 ObserverListMap m_observers; |
163 bool m_testUpdatesOnly; | 162 bool m_testUpdatesOnly; |
164 }; | 163 }; |
165 | 164 |
166 CORE_EXPORT NetworkStateNotifier& networkStateNotifier(); | 165 CORE_EXPORT NetworkStateNotifier& networkStateNotifier(); |
167 | 166 |
168 } // namespace blink | 167 } // namespace blink |
169 | 168 |
170 #endif // NetworkStateNotifier_h | 169 #endif // NetworkStateNotifier_h |
OLD | NEW |