This source file includes following definitions.
- create
- addObserver
- removeObserver
- notifyObserversInternal
- hasObservers
#include "config.h"
#include "core/dom/IdTargetObserverRegistry.h"
#include "core/dom/IdTargetObserver.h"
namespace WebCore {
PassOwnPtr<IdTargetObserverRegistry> IdTargetObserverRegistry::create()
{
return adoptPtr(new IdTargetObserverRegistry());
}
void IdTargetObserverRegistry::addObserver(const AtomicString& id, IdTargetObserver* observer)
{
if (id.isEmpty())
return;
IdToObserverSetMap::AddResult result = m_registry.add(id.impl(), nullptr);
if (result.isNewEntry)
result.storedValue->value = adoptPtr(new ObserverSet());
result.storedValue->value->add(observer);
}
void IdTargetObserverRegistry::removeObserver(const AtomicString& id, IdTargetObserver* observer)
{
if (id.isEmpty() || m_registry.isEmpty())
return;
IdToObserverSetMap::iterator iter = m_registry.find(id.impl());
ObserverSet* set = iter->value.get();
set->remove(observer);
if (set->isEmpty() && set != m_notifyingObserversInSet)
m_registry.remove(iter);
}
void IdTargetObserverRegistry::notifyObserversInternal(const AtomicString& id)
{
ASSERT(!id.isEmpty());
ASSERT(!m_registry.isEmpty());
m_notifyingObserversInSet = m_registry.get(id.impl());
if (!m_notifyingObserversInSet)
return;
Vector<IdTargetObserver*> copy;
copyToVector(*m_notifyingObserversInSet, copy);
for (Vector<IdTargetObserver*>::const_iterator it = copy.begin(); it != copy.end(); ++it) {
if (m_notifyingObserversInSet->contains(*it))
(*it)->idTargetChanged();
}
if (m_notifyingObserversInSet->isEmpty())
m_registry.remove(id.impl());
m_notifyingObserversInSet = 0;
}
bool IdTargetObserverRegistry::hasObservers(const AtomicString& id) const
{
if (id.isEmpty() || m_registry.isEmpty())
return false;
ObserverSet* set = m_registry.get(id.impl());
return set && !set->isEmpty();
}
}