IdTargetObserverRegistry.h [plain text]
#ifndef IdTargetObserverRegistry_h
#define IdTargetObserverRegistry_h
#include <memory>
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/text/AtomicString.h>
namespace WebCore {
class IdTargetObserver;
class IdTargetObserverRegistry {
WTF_MAKE_FAST_ALLOCATED;
friend class IdTargetObserver;
public:
IdTargetObserverRegistry()
: m_notifyingObserversInSet(0)
{ }
void notifyObservers(const AtomicString& id);
void notifyObservers(const AtomicStringImpl& id);
private:
void addObserver(const AtomicString& id, IdTargetObserver*);
void removeObserver(const AtomicString& id, IdTargetObserver*);
void notifyObserversInternal(const AtomicStringImpl& id);
typedef HashSet<IdTargetObserver*> ObserverSet;
typedef HashMap<const AtomicStringImpl*, std::unique_ptr<ObserverSet>> IdToObserverSetMap;
IdToObserverSetMap m_registry;
ObserverSet* m_notifyingObserversInSet;
};
inline void IdTargetObserverRegistry::notifyObservers(const AtomicString& id)
{
if (!id.isEmpty())
return notifyObservers(*id.impl());
}
inline void IdTargetObserverRegistry::notifyObservers(const AtomicStringImpl& id)
{
ASSERT(!m_notifyingObserversInSet);
ASSERT(id.length());
if (m_registry.isEmpty())
return;
IdTargetObserverRegistry::notifyObserversInternal(id);
}
}
#endif // IdTargetObserverRegistry_h