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> |
37 | 38 |
38 namespace blink { | 39 namespace blink { |
39 | 40 |
40 class CORE_EXPORT NetworkStateNotifier { | 41 class CORE_EXPORT NetworkStateNotifier { |
41 WTF_MAKE_NONCOPYABLE(NetworkStateNotifier); USING_FAST_MALLOC(NetworkStateNo
tifier); | 42 WTF_MAKE_NONCOPYABLE(NetworkStateNotifier); USING_FAST_MALLOC(NetworkStateNo
tifier); |
42 public: | 43 public: |
43 class NetworkStateObserver { | 44 class NetworkStateObserver { |
44 public: | 45 public: |
45 // Will be called on the thread of the context passed in addObserver. | 46 // Will be called on the thread of the context passed in addObserver. |
46 virtual void connectionChange(WebConnectionType, double maxBandwidthMbps
) = 0; | 47 virtual void connectionChange(WebConnectionType, double maxBandwidthMbps
) = 0; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 }; | 136 }; |
136 | 137 |
137 const int kInvalidMaxBandwidth = -1; | 138 const int kInvalidMaxBandwidth = -1; |
138 | 139 |
139 void setWebConnectionImpl(WebConnectionType, double maxBandwidthMbps); | 140 void setWebConnectionImpl(WebConnectionType, double maxBandwidthMbps); |
140 void setMaxBandwidthImpl(double maxBandwidthMbps); | 141 void setMaxBandwidthImpl(double maxBandwidthMbps); |
141 | 142 |
142 // The ObserverListMap is cross-thread accessed, adding/removing Observers r
unning | 143 // The ObserverListMap is cross-thread accessed, adding/removing Observers r
unning |
143 // within an ExecutionContext. Kept off-heap to ease cross-thread allocation
and use; | 144 // within an ExecutionContext. Kept off-heap to ease cross-thread allocation
and use; |
144 // the observers are (already) responsible for explicitly unregistering whil
e finalizing. | 145 // the observers are (already) responsible for explicitly unregistering whil
e finalizing. |
145 using ObserverListMap = HashMap<UntracedMember<ExecutionContext>, OwnPtr<Obs
erverList>>; | 146 using ObserverListMap = HashMap<UntracedMember<ExecutionContext>, std::uniqu
e_ptr<ObserverList>>; |
146 | 147 |
147 void notifyObserversOfConnectionChangeOnContext(WebConnectionType, double ma
xBandwidthMbps, ExecutionContext*); | 148 void notifyObserversOfConnectionChangeOnContext(WebConnectionType, double ma
xBandwidthMbps, ExecutionContext*); |
148 | 149 |
149 ObserverList* lockAndFindObserverList(ExecutionContext*); | 150 ObserverList* lockAndFindObserverList(ExecutionContext*); |
150 | 151 |
151 // Removed observers are nulled out in the list in case the list is being | 152 // Removed observers are nulled out in the list in case the list is being |
152 // iterated over. Once done iterating, call this to clean up nulled | 153 // iterated over. Once done iterating, call this to clean up nulled |
153 // observers. | 154 // observers. |
154 void collectZeroedObservers(ObserverList*, ExecutionContext*); | 155 void collectZeroedObservers(ObserverList*, ExecutionContext*); |
155 | 156 |
156 mutable Mutex m_mutex; | 157 mutable Mutex m_mutex; |
157 bool m_initialized; | 158 bool m_initialized; |
158 bool m_isOnLine; | 159 bool m_isOnLine; |
159 WebConnectionType m_type; | 160 WebConnectionType m_type; |
160 double m_maxBandwidthMbps; | 161 double m_maxBandwidthMbps; |
161 ObserverListMap m_observers; | 162 ObserverListMap m_observers; |
162 bool m_testUpdatesOnly; | 163 bool m_testUpdatesOnly; |
163 }; | 164 }; |
164 | 165 |
165 CORE_EXPORT NetworkStateNotifier& networkStateNotifier(); | 166 CORE_EXPORT NetworkStateNotifier& networkStateNotifier(); |
166 | 167 |
167 } // namespace blink | 168 } // namespace blink |
168 | 169 |
169 #endif // NetworkStateNotifier_h | 170 #endif // NetworkStateNotifier_h |
OLD | NEW |