| 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 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 "config.h" | 26 #include "config.h" |
| 27 #include "core/dom/IdTargetObserverRegistry.h" | 27 #include "core/dom/IdTargetObserverRegistry.h" |
| 28 | 28 |
| 29 #include "core/dom/IdTargetObserver.h" | 29 #include "core/dom/IdTargetObserver.h" |
| 30 | 30 |
| 31 namespace WebCore { | 31 namespace WebCore { |
| 32 | 32 |
| 33 PassOwnPtr<IdTargetObserverRegistry> IdTargetObserverRegistry::create() | 33 PassOwnPtrWillBeRawPtr<IdTargetObserverRegistry> IdTargetObserverRegistry::creat
e() |
| 34 { | 34 { |
| 35 return adoptPtr(new IdTargetObserverRegistry()); | 35 return adoptPtrWillBeNoop(new IdTargetObserverRegistry()); |
| 36 } |
| 37 |
| 38 void IdTargetObserverRegistry::trace(Visitor* visitor) |
| 39 { |
| 40 visitor->trace(m_registry); |
| 41 visitor->trace(m_notifyingObserversInSet); |
| 36 } | 42 } |
| 37 | 43 |
| 38 void IdTargetObserverRegistry::addObserver(const AtomicString& id, IdTargetObser
ver* observer) | 44 void IdTargetObserverRegistry::addObserver(const AtomicString& id, IdTargetObser
ver* observer) |
| 39 { | 45 { |
| 40 if (id.isEmpty()) | 46 if (id.isEmpty()) |
| 41 return; | 47 return; |
| 42 | 48 |
| 43 IdToObserverSetMap::AddResult result = m_registry.add(id.impl(), nullptr); | 49 IdToObserverSetMap::AddResult result = m_registry.add(id.impl(), nullptr); |
| 44 if (result.isNewEntry) | 50 if (result.isNewEntry) |
| 45 result.storedValue->value = adoptPtr(new ObserverSet()); | 51 result.storedValue->value = adoptPtrWillBeNoop(new ObserverSet()); |
| 46 | 52 |
| 47 result.storedValue->value->add(observer); | 53 result.storedValue->value->add(observer); |
| 48 } | 54 } |
| 49 | 55 |
| 50 void IdTargetObserverRegistry::removeObserver(const AtomicString& id, IdTargetOb
server* observer) | 56 void IdTargetObserverRegistry::removeObserver(const AtomicString& id, IdTargetOb
server* observer) |
| 51 { | 57 { |
| 52 if (id.isEmpty() || m_registry.isEmpty()) | 58 if (id.isEmpty() || m_registry.isEmpty()) |
| 53 return; | 59 return; |
| 54 | 60 |
| 55 IdToObserverSetMap::iterator iter = m_registry.find(id.impl()); | 61 IdToObserverSetMap::iterator iter = m_registry.find(id.impl()); |
| 56 | 62 |
| 57 ObserverSet* set = iter->value.get(); | 63 ObserverSet* set = iter->value.get(); |
| 58 set->remove(observer); | 64 set->remove(observer); |
| 59 if (set->isEmpty() && set != m_notifyingObserversInSet) | 65 if (set->isEmpty() && set != m_notifyingObserversInSet) |
| 60 m_registry.remove(iter); | 66 m_registry.remove(iter); |
| 61 } | 67 } |
| 62 | 68 |
| 63 void IdTargetObserverRegistry::notifyObserversInternal(const AtomicString& id) | 69 void IdTargetObserverRegistry::notifyObserversInternal(const AtomicString& id) |
| 64 { | 70 { |
| 65 ASSERT(!id.isEmpty()); | 71 ASSERT(!id.isEmpty()); |
| 66 ASSERT(!m_registry.isEmpty()); | 72 ASSERT(!m_registry.isEmpty()); |
| 67 | 73 |
| 68 m_notifyingObserversInSet = m_registry.get(id.impl()); | 74 m_notifyingObserversInSet = m_registry.get(id.impl()); |
| 69 if (!m_notifyingObserversInSet) | 75 if (!m_notifyingObserversInSet) |
| 70 return; | 76 return; |
| 71 | 77 |
| 72 Vector<IdTargetObserver*> copy; | 78 WillBeHeapVector<RawPtrWillBeMember<IdTargetObserver> > copy; |
| 73 copyToVector(*m_notifyingObserversInSet, copy); | 79 copyToVector(*m_notifyingObserversInSet, copy); |
| 74 for (Vector<IdTargetObserver*>::const_iterator it = copy.begin(); it != copy
.end(); ++it) { | 80 for (WillBeHeapVector<RawPtrWillBeMember<IdTargetObserver> >::const_iterator
it = copy.begin(); it != copy.end(); ++it) { |
| 75 if (m_notifyingObserversInSet->contains(*it)) | 81 if (m_notifyingObserversInSet->contains(*it)) |
| 76 (*it)->idTargetChanged(); | 82 (*it)->idTargetChanged(); |
| 77 } | 83 } |
| 78 | 84 |
| 79 if (m_notifyingObserversInSet->isEmpty()) | 85 if (m_notifyingObserversInSet->isEmpty()) |
| 80 m_registry.remove(id.impl()); | 86 m_registry.remove(id.impl()); |
| 81 | 87 |
| 82 m_notifyingObserversInSet = 0; | 88 m_notifyingObserversInSet = nullptr; |
| 83 } | 89 } |
| 84 | 90 |
| 85 bool IdTargetObserverRegistry::hasObservers(const AtomicString& id) const | 91 bool IdTargetObserverRegistry::hasObservers(const AtomicString& id) const |
| 86 { | 92 { |
| 87 if (id.isEmpty() || m_registry.isEmpty()) | 93 if (id.isEmpty() || m_registry.isEmpty()) |
| 88 return false; | 94 return false; |
| 89 ObserverSet* set = m_registry.get(id.impl()); | 95 ObserverSet* set = m_registry.get(id.impl()); |
| 90 return set && !set->isEmpty(); | 96 return set && !set->isEmpty(); |
| 91 } | 97 } |
| 92 | 98 |
| 93 } // namespace WebCore | 99 } // namespace WebCore |
| OLD | NEW |