| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All Rights Reserved. | 2 * Copyright (C) 2012 Google 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 11 matching lines...) Expand all Loading... |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 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/dom/IdTargetObserverRegistry.h" | 26 #include "core/dom/IdTargetObserverRegistry.h" |
| 27 | 27 |
| 28 #include "core/dom/IdTargetObserver.h" | 28 #include "core/dom/IdTargetObserver.h" |
| 29 | 29 |
| 30 namespace blink { | 30 namespace blink { |
| 31 | 31 |
| 32 PassOwnPtrWillBeRawPtr<IdTargetObserverRegistry> IdTargetObserverRegistry::creat
e() | 32 RawPtr<IdTargetObserverRegistry> IdTargetObserverRegistry::create() |
| 33 { | 33 { |
| 34 return adoptPtrWillBeNoop(new IdTargetObserverRegistry()); | 34 return new IdTargetObserverRegistry(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 DEFINE_TRACE(IdTargetObserverRegistry) | 37 DEFINE_TRACE(IdTargetObserverRegistry) |
| 38 { | 38 { |
| 39 #if ENABLE(OILPAN) | 39 #if ENABLE(OILPAN) |
| 40 visitor->trace(m_registry); | 40 visitor->trace(m_registry); |
| 41 visitor->trace(m_notifyingObserversInSet); | 41 visitor->trace(m_notifyingObserversInSet); |
| 42 #endif | 42 #endif |
| 43 } | 43 } |
| 44 | 44 |
| 45 void IdTargetObserverRegistry::addObserver(const AtomicString& id, IdTargetObser
ver* observer) | 45 void IdTargetObserverRegistry::addObserver(const AtomicString& id, IdTargetObser
ver* observer) |
| 46 { | 46 { |
| 47 if (id.isEmpty()) | 47 if (id.isEmpty()) |
| 48 return; | 48 return; |
| 49 | 49 |
| 50 IdToObserverSetMap::AddResult result = m_registry.add(id.impl(), nullptr); | 50 IdToObserverSetMap::AddResult result = m_registry.add(id.impl(), nullptr); |
| 51 if (result.isNewEntry) | 51 if (result.isNewEntry) |
| 52 result.storedValue->value = adoptPtrWillBeNoop(new ObserverSet()); | 52 result.storedValue->value = new ObserverSet(); |
| 53 | 53 |
| 54 result.storedValue->value->add(observer); | 54 result.storedValue->value->add(observer); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void IdTargetObserverRegistry::removeObserver(const AtomicString& id, IdTargetOb
server* observer) | 57 void IdTargetObserverRegistry::removeObserver(const AtomicString& id, IdTargetOb
server* observer) |
| 58 { | 58 { |
| 59 if (id.isEmpty() || m_registry.isEmpty()) | 59 if (id.isEmpty() || m_registry.isEmpty()) |
| 60 return; | 60 return; |
| 61 | 61 |
| 62 IdToObserverSetMap::iterator iter = m_registry.find(id.impl()); | 62 IdToObserverSetMap::iterator iter = m_registry.find(id.impl()); |
| 63 | 63 |
| 64 ObserverSet* set = iter->value.get(); | 64 ObserverSet* set = iter->value.get(); |
| 65 set->remove(observer); | 65 set->remove(observer); |
| 66 if (set->isEmpty() && set != m_notifyingObserversInSet) | 66 if (set->isEmpty() && set != m_notifyingObserversInSet) |
| 67 m_registry.remove(iter); | 67 m_registry.remove(iter); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void IdTargetObserverRegistry::notifyObserversInternal(const AtomicString& id) | 70 void IdTargetObserverRegistry::notifyObserversInternal(const AtomicString& id) |
| 71 { | 71 { |
| 72 ASSERT(!id.isEmpty()); | 72 ASSERT(!id.isEmpty()); |
| 73 ASSERT(!m_registry.isEmpty()); | 73 ASSERT(!m_registry.isEmpty()); |
| 74 | 74 |
| 75 m_notifyingObserversInSet = m_registry.get(id.impl()); | 75 m_notifyingObserversInSet = m_registry.get(id.impl()); |
| 76 if (!m_notifyingObserversInSet) | 76 if (!m_notifyingObserversInSet) |
| 77 return; | 77 return; |
| 78 | 78 |
| 79 WillBeHeapVector<RawPtrWillBeMember<IdTargetObserver>> copy; | 79 HeapVector<Member<IdTargetObserver>> copy; |
| 80 copyToVector(*m_notifyingObserversInSet, copy); | 80 copyToVector(*m_notifyingObserversInSet, copy); |
| 81 for (const auto& observer : copy) { | 81 for (const auto& observer : copy) { |
| 82 if (m_notifyingObserversInSet->contains(observer)) | 82 if (m_notifyingObserversInSet->contains(observer)) |
| 83 observer->idTargetChanged(); | 83 observer->idTargetChanged(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 if (m_notifyingObserversInSet->isEmpty()) | 86 if (m_notifyingObserversInSet->isEmpty()) |
| 87 m_registry.remove(id.impl()); | 87 m_registry.remove(id.impl()); |
| 88 | 88 |
| 89 m_notifyingObserversInSet = nullptr; | 89 m_notifyingObserversInSet = nullptr; |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool IdTargetObserverRegistry::hasObservers(const AtomicString& id) const | 92 bool IdTargetObserverRegistry::hasObservers(const AtomicString& id) const |
| 93 { | 93 { |
| 94 if (id.isEmpty() || m_registry.isEmpty()) | 94 if (id.isEmpty() || m_registry.isEmpty()) |
| 95 return false; | 95 return false; |
| 96 ObserverSet* set = m_registry.get(id.impl()); | 96 ObserverSet* set = m_registry.get(id.impl()); |
| 97 return set && !set->isEmpty(); | 97 return set && !set->isEmpty(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 } // namespace blink | 100 } // namespace blink |
| OLD | NEW |