Changeset 161830 in webkit
- Timestamp:
- Jan 12, 2014, 12:59:30 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r161828 r161830 1 2014-01-12 Anders Carlsson <andersca@apple.com> 2 3 Clean up NetworkStateNotifier class 4 https://bugs.webkit.org/show_bug.cgi?id=126850 5 6 Reviewed by Andreas Kling. 7 8 Use std::call_once instead of AtomicallyInitializedStatic and a std::function 9 instead of a custom function pointer typedef. 10 11 * platform/network/NetworkStateNotifier.cpp: 12 (WebCore::networkStateNotifier): 13 (WebCore::NetworkStateNotifier::addNetworkStateChangeListener): 14 (WebCore::NetworkStateNotifier::notifyNetworkStateChange): 15 * platform/network/NetworkStateNotifier.h: 16 1 17 2014-01-12 Simon Fraser <simon.fraser@apple.com> 2 18 -
trunk/Source/WebCore/platform/network/NetworkStateNotifier.cpp
r152894 r161830 27 27 #include "NetworkStateNotifier.h" 28 28 29 #include <mutex> 29 30 #include <wtf/Assertions.h> 30 31 #include <wtf/StdLibExtras.h> 31 #include <wtf/Threading.h>32 32 33 33 namespace WebCore { … … 35 35 NetworkStateNotifier& networkStateNotifier() 36 36 { 37 AtomicallyInitializedStatic(NetworkStateNotifier*, networkStateNotifier = new NetworkStateNotifier); 37 static std::once_flag onceFlag; 38 static NetworkStateNotifier* networkStateNotifier; 39 40 std::call_once(onceFlag, []{ 41 networkStateNotifier = std::make_unique<NetworkStateNotifier>().release(); 42 }); 38 43 39 44 return *networkStateNotifier; 40 45 } 41 46 42 void NetworkStateNotifier::addNetworkStateChangeListener( NetworkStateChangeListenerlistener)47 void NetworkStateNotifier::addNetworkStateChangeListener(std::function<void (bool)> listener) 43 48 { 44 49 ASSERT(listener); 45 m_listeners.append(listener); 50 51 m_listeners.append(std::move(listener)); 46 52 } 47 53 48 54 void NetworkStateNotifier::notifyNetworkStateChange() 49 55 { 50 Vector<NetworkStateChangeListener>::iterator end = m_listeners.end(); 51 for (Vector<NetworkStateChangeListener>::iterator it = m_listeners.begin(); it != end; ++it) 52 (*it)(m_isOnLine); 56 for (const auto& listener : m_listeners) 57 listener(m_isOnLine); 53 58 } 54 59 55 } 60 } // namespace WebCore -
trunk/Source/WebCore/platform/network/NetworkStateNotifier.h
r161768 r161830 59 59 ~NetworkStateNotifier(); 60 60 #endif 61 typedef void (*NetworkStateChangeListener)(bool m_isOnLine); 62 void addNetworkStateChangeListener(NetworkStateChangeListener); 61 void addNetworkStateChangeListener(std::function<void (bool isOnLine)>); 63 62 64 63 bool onLine() const { return m_isOnLine; } … … 70 69 private: 71 70 bool m_isOnLine; 72 Vector< NetworkStateChangeListener> m_listeners;71 Vector<std::function<void (bool)>> m_listeners; 73 72 74 73 void notifyNetworkStateChange();
Note:
See TracChangeset
for help on using the changeset viewer.