Changeset 161830 in webkit


Ignore:
Timestamp:
Jan 12, 2014, 12:59:30 PM (12 years ago)
Author:
andersca@apple.com
Message:

Clean up NetworkStateNotifier class
https://bugs.webkit.org/show_bug.cgi?id=126850

Reviewed by Andreas Kling.

Use std::call_once instead of AtomicallyInitializedStatic and a std::function
instead of a custom function pointer typedef.

  • platform/network/NetworkStateNotifier.cpp:

(WebCore::networkStateNotifier):
(WebCore::NetworkStateNotifier::addNetworkStateChangeListener):
(WebCore::NetworkStateNotifier::notifyNetworkStateChange):

  • platform/network/NetworkStateNotifier.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r161828 r161830  
     12014-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
    1172014-01-12  Simon Fraser  <simon.fraser@apple.com>
    218
  • trunk/Source/WebCore/platform/network/NetworkStateNotifier.cpp

    r152894 r161830  
    2727#include "NetworkStateNotifier.h"
    2828
     29#include <mutex>
    2930#include <wtf/Assertions.h>
    3031#include <wtf/StdLibExtras.h>
    31 #include <wtf/Threading.h>
    3232
    3333namespace WebCore {
     
    3535NetworkStateNotifier& networkStateNotifier()
    3636{
    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    });
    3843
    3944    return *networkStateNotifier;
    4045}
    4146
    42 void NetworkStateNotifier::addNetworkStateChangeListener(NetworkStateChangeListener listener)
     47void NetworkStateNotifier::addNetworkStateChangeListener(std::function<void (bool)> listener)
    4348{
    4449    ASSERT(listener);
    45     m_listeners.append(listener);
     50
     51    m_listeners.append(std::move(listener));
    4652}
    4753
    4854void NetworkStateNotifier::notifyNetworkStateChange()
    4955{
    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);
    5358}
    5459
    55 }
     60} // namespace WebCore
  • trunk/Source/WebCore/platform/network/NetworkStateNotifier.h

    r161768 r161830  
    5959    ~NetworkStateNotifier();
    6060#endif
    61     typedef void (*NetworkStateChangeListener)(bool m_isOnLine);
    62     void addNetworkStateChangeListener(NetworkStateChangeListener);
     61    void addNetworkStateChangeListener(std::function<void (bool isOnLine)>);
    6362
    6463    bool onLine() const { return m_isOnLine; }
     
    7069private:
    7170    bool m_isOnLine;
    72     Vector<NetworkStateChangeListener> m_listeners;
     71    Vector<std::function<void (bool)>> m_listeners;
    7372
    7473    void notifyNetworkStateChange();
Note: See TracChangeset for help on using the changeset viewer.