| 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 12 matching lines...) Expand all Loading... |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "core/page/NetworkStateNotifier.h" | 26 #include "core/page/NetworkStateNotifier.h" |
| 27 | 27 |
| 28 #include "core/dom/CrossThreadTask.h" | 28 #include "core/dom/CrossThreadTask.h" |
| 29 #include "core/dom/ExecutionContext.h" | 29 #include "core/dom/ExecutionContext.h" |
| 30 #include "core/page/Page.h" | 30 #include "core/page/Page.h" |
| 31 #include "wtf/Assertions.h" | 31 #include "wtf/Assertions.h" |
| 32 #include "wtf/Functional.h" | 32 #include "wtf/Functional.h" |
| 33 #include "wtf/PtrUtil.h" | |
| 34 #include "wtf/StdLibExtras.h" | 33 #include "wtf/StdLibExtras.h" |
| 35 #include "wtf/Threading.h" | 34 #include "wtf/Threading.h" |
| 36 | 35 |
| 37 namespace blink { | 36 namespace blink { |
| 38 | 37 |
| 39 NetworkStateNotifier& networkStateNotifier() | 38 NetworkStateNotifier& networkStateNotifier() |
| 40 { | 39 { |
| 41 DEFINE_THREAD_SAFE_STATIC_LOCAL(NetworkStateNotifier, networkStateNotifier,
new NetworkStateNotifier); | 40 DEFINE_THREAD_SAFE_STATIC_LOCAL(NetworkStateNotifier, networkStateNotifier,
new NetworkStateNotifier); |
| 42 return networkStateNotifier; | 41 return networkStateNotifier; |
| 43 } | 42 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 67 } | 66 } |
| 68 | 67 |
| 69 void NetworkStateNotifier::addObserver(NetworkStateObserver* observer, Execution
Context* context) | 68 void NetworkStateNotifier::addObserver(NetworkStateObserver* observer, Execution
Context* context) |
| 70 { | 69 { |
| 71 ASSERT(context->isContextThread()); | 70 ASSERT(context->isContextThread()); |
| 72 ASSERT(observer); | 71 ASSERT(observer); |
| 73 | 72 |
| 74 MutexLocker locker(m_mutex); | 73 MutexLocker locker(m_mutex); |
| 75 ObserverListMap::AddResult result = m_observers.add(context, nullptr); | 74 ObserverListMap::AddResult result = m_observers.add(context, nullptr); |
| 76 if (result.isNewEntry) | 75 if (result.isNewEntry) |
| 77 result.storedValue->value = wrapUnique(new ObserverList); | 76 result.storedValue->value = adoptPtr(new ObserverList); |
| 78 | 77 |
| 79 ASSERT(result.storedValue->value->observers.find(observer) == kNotFound); | 78 ASSERT(result.storedValue->value->observers.find(observer) == kNotFound); |
| 80 result.storedValue->value->observers.append(observer); | 79 result.storedValue->value->observers.append(observer); |
| 81 } | 80 } |
| 82 | 81 |
| 83 void NetworkStateNotifier::removeObserver(NetworkStateObserver* observer, Execut
ionContext* context) | 82 void NetworkStateNotifier::removeObserver(NetworkStateObserver* observer, Execut
ionContext* context) |
| 84 { | 83 { |
| 85 ASSERT(context->isContextThread()); | 84 ASSERT(context->isContextThread()); |
| 86 ASSERT(observer); | 85 ASSERT(observer); |
| 87 | 86 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 182 |
| 184 list->zeroedObservers.clear(); | 183 list->zeroedObservers.clear(); |
| 185 | 184 |
| 186 if (list->observers.isEmpty()) { | 185 if (list->observers.isEmpty()) { |
| 187 MutexLocker locker(m_mutex); | 186 MutexLocker locker(m_mutex); |
| 188 m_observers.remove(context); // deletes list | 187 m_observers.remove(context); // deletes list |
| 189 } | 188 } |
| 190 } | 189 } |
| 191 | 190 |
| 192 } // namespace blink | 191 } // namespace blink |
| OLD | NEW |