Commit d48ffbff authored by tkent@chromium.org's avatar tkent@chromium.org

Oilpan: Prepare to move IdTargetObserver and IdTargetObserverRegistry to Oilpan heap.

BUG=357163

Review URL: https://codereview.chromium.org/278803002

git-svn-id: svn://svn.chromium.org/blink/trunk@173747 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 0b05081f
......@@ -30,24 +30,29 @@
namespace WebCore {
IdTargetObserver::IdTargetObserver(IdTargetObserverRegistry& registry, const AtomicString& id)
: m_registry(registry)
IdTargetObserver::IdTargetObserver(IdTargetObserverRegistry& observerRegistry, const AtomicString& id)
: m_registry(&observerRegistry)
, m_id(id)
{
m_registry.addObserver(m_id, this);
registry().addObserver(m_id, this);
}
IdTargetObserver::~IdTargetObserver()
{
#if !ENABLE(OILPAN)
m_registry.removeObserver(m_id, this);
registry().removeObserver(m_id, this);
#endif
}
void IdTargetObserver::trace(Visitor* visitor)
{
visitor->trace(m_registry);
}
void IdTargetObserver::unregister()
{
#if ENABLE(OILPAN)
m_registry.removeObserver(m_id, this);
registry().removeObserver(m_id, this);
#endif
}
......
......@@ -26,15 +26,17 @@
#ifndef IdTargetObserver_h
#define IdTargetObserver_h
#include "platform/heap/Handle.h"
#include "wtf/text/AtomicString.h"
namespace WebCore {
class IdTargetObserverRegistry;
class IdTargetObserver {
class IdTargetObserver : public NoBaseWillBeGarbageCollectedFinalized<IdTargetObserver> {
public:
virtual ~IdTargetObserver();
virtual void trace(Visitor*);
virtual void idTargetChanged() = 0;
virtual void unregister();
......@@ -42,7 +44,9 @@ protected:
IdTargetObserver(IdTargetObserverRegistry&, const AtomicString& id);
private:
IdTargetObserverRegistry& m_registry;
IdTargetObserverRegistry& registry() { return *m_registry; }
RawPtrWillBeMember<IdTargetObserverRegistry> m_registry;
AtomicString m_id;
};
......
......@@ -30,9 +30,15 @@
namespace WebCore {
PassOwnPtr<IdTargetObserverRegistry> IdTargetObserverRegistry::create()
PassOwnPtrWillBeRawPtr<IdTargetObserverRegistry> IdTargetObserverRegistry::create()
{
return adoptPtr(new IdTargetObserverRegistry());
return adoptPtrWillBeNoop(new IdTargetObserverRegistry());
}
void IdTargetObserverRegistry::trace(Visitor* visitor)
{
visitor->trace(m_registry);
visitor->trace(m_notifyingObserversInSet);
}
void IdTargetObserverRegistry::addObserver(const AtomicString& id, IdTargetObserver* observer)
......@@ -42,7 +48,7 @@ void IdTargetObserverRegistry::addObserver(const AtomicString& id, IdTargetObser
IdToObserverSetMap::AddResult result = m_registry.add(id.impl(), nullptr);
if (result.isNewEntry)
result.storedValue->value = adoptPtr(new ObserverSet());
result.storedValue->value = adoptPtrWillBeNoop(new ObserverSet());
result.storedValue->value->add(observer);
}
......@@ -69,9 +75,9 @@ void IdTargetObserverRegistry::notifyObserversInternal(const AtomicString& id)
if (!m_notifyingObserversInSet)
return;
Vector<IdTargetObserver*> copy;
WillBeHeapVector<RawPtrWillBeMember<IdTargetObserver> > copy;
copyToVector(*m_notifyingObserversInSet, copy);
for (Vector<IdTargetObserver*>::const_iterator it = copy.begin(); it != copy.end(); ++it) {
for (WillBeHeapVector<RawPtrWillBeMember<IdTargetObserver> >::const_iterator it = copy.begin(); it != copy.end(); ++it) {
if (m_notifyingObserversInSet->contains(*it))
(*it)->idTargetChanged();
}
......@@ -79,7 +85,7 @@ void IdTargetObserverRegistry::notifyObserversInternal(const AtomicString& id)
if (m_notifyingObserversInSet->isEmpty())
m_registry.remove(id.impl());
m_notifyingObserversInSet = 0;
m_notifyingObserversInSet = nullptr;
}
bool IdTargetObserverRegistry::hasObservers(const AtomicString& id) const
......
......@@ -26,6 +26,7 @@
#ifndef IdTargetObserverRegistry_h
#define IdTargetObserverRegistry_h
#include "platform/heap/Handle.h"
#include "wtf/Forward.h"
#include "wtf/HashMap.h"
#include "wtf/HashSet.h"
......@@ -36,24 +37,26 @@ namespace WebCore {
class IdTargetObserver;
class IdTargetObserverRegistry {
WTF_MAKE_NONCOPYABLE(IdTargetObserverRegistry); WTF_MAKE_FAST_ALLOCATED;
class IdTargetObserverRegistry FINAL : public NoBaseWillBeGarbageCollectedFinalized<IdTargetObserverRegistry> {
WTF_MAKE_NONCOPYABLE(IdTargetObserverRegistry);
WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
friend class IdTargetObserver;
public:
static PassOwnPtr<IdTargetObserverRegistry> create();
static PassOwnPtrWillBeRawPtr<IdTargetObserverRegistry> create();
void trace(Visitor*);
void notifyObservers(const AtomicString& id);
bool hasObservers(const AtomicString& id) const;
private:
IdTargetObserverRegistry() : m_notifyingObserversInSet(0) { }
IdTargetObserverRegistry() : m_notifyingObserversInSet(nullptr) { }
void addObserver(const AtomicString& id, IdTargetObserver*);
void removeObserver(const AtomicString& id, IdTargetObserver*);
void notifyObserversInternal(const AtomicString& id);
typedef HashSet<IdTargetObserver*> ObserverSet;
typedef HashMap<StringImpl*, OwnPtr<ObserverSet> > IdToObserverSetMap;
typedef WillBeHeapHashSet<RawPtrWillBeMember<IdTargetObserver> > ObserverSet;
typedef WillBeHeapHashMap<StringImpl*, OwnPtrWillBeMember<ObserverSet> > IdToObserverSetMap;
IdToObserverSetMap m_registry;
ObserverSet* m_notifyingObserversInSet;
RawPtrWillBeMember<ObserverSet> m_notifyingObserversInSet;
};
inline void IdTargetObserverRegistry::notifyObservers(const AtomicString& id)
......
......@@ -542,6 +542,7 @@ void TreeScope::trace(Visitor* visitor)
visitor->trace(m_rootNode);
visitor->trace(m_document);
visitor->trace(m_parentTreeScope);
visitor->trace(m_idTargetObserverRegistry);
visitor->trace(m_selection);
}
......
......@@ -186,7 +186,7 @@ private:
OwnPtr<DocumentOrderedMap> m_imageMapsByName;
OwnPtr<DocumentOrderedMap> m_labelsByForAttribute;
OwnPtr<IdTargetObserverRegistry> m_idTargetObserverRegistry;
OwnPtrWillBeMember<IdTargetObserverRegistry> m_idTargetObserverRegistry;
mutable RefPtrWillBeMember<DOMSelection> m_selection;
};
......
......@@ -36,12 +36,11 @@ namespace WebCore {
using namespace HTMLNames;
// FIXME: Oilpan: IdTargetObserver should be on-heap.
class FormAttributeTargetObserver : public NoBaseWillBeGarbageCollectedFinalized<FormAttributeTargetObserver>, public IdTargetObserver {
class FormAttributeTargetObserver : public IdTargetObserver {
WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
public:
static PassOwnPtrWillBeRawPtr<FormAttributeTargetObserver> create(const AtomicString& id, FormAssociatedElement*);
void trace(Visitor* visitor) { visitor->trace(m_element); }
virtual void trace(Visitor*) OVERRIDE;
virtual void idTargetChanged() OVERRIDE;
private:
......@@ -338,6 +337,12 @@ FormAttributeTargetObserver::FormAttributeTargetObserver(const AtomicString& id,
{
}
void FormAttributeTargetObserver::trace(Visitor* visitor)
{
visitor->trace(m_element);
IdTargetObserver::trace(visitor);
}
void FormAttributeTargetObserver::idTargetChanged()
{
m_element->formAttributeTargetChanged();
......
......@@ -83,15 +83,16 @@ namespace WebCore {
using namespace HTMLNames;
class ListAttributeTargetObserver : public IdTargetObserver {
WTF_MAKE_FAST_ALLOCATED;
WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
public:
static PassOwnPtr<ListAttributeTargetObserver> create(const AtomicString& id, HTMLInputElement*);
static PassOwnPtrWillBeRawPtr<ListAttributeTargetObserver> create(const AtomicString& id, HTMLInputElement*);
virtual void trace(Visitor*) OVERRIDE;
virtual void idTargetChanged() OVERRIDE;
private:
ListAttributeTargetObserver(const AtomicString& id, HTMLInputElement*);
HTMLInputElement* m_element;
RawPtrWillBeMember<HTMLInputElement> m_element;
};
// FIXME: According to HTML4, the length attribute's value can be arbitrarily
......@@ -140,6 +141,7 @@ void HTMLInputElement::trace(Visitor* visitor)
{
visitor->trace(m_inputType);
visitor->trace(m_inputTypeView);
visitor->trace(m_listAttributeTargetObserver);
HTMLTextFormControlElement::trace(visitor);
}
......@@ -1507,7 +1509,7 @@ bool HTMLInputElement::hasValidDataListOptions() const
return false;
}
void HTMLInputElement::setListAttributeTargetObserver(PassOwnPtr<ListAttributeTargetObserver> newObserver)
void HTMLInputElement::setListAttributeTargetObserver(PassOwnPtrWillBeRawPtr<ListAttributeTargetObserver> newObserver)
{
if (m_listAttributeTargetObserver)
m_listAttributeTargetObserver->unregister();
......@@ -1762,9 +1764,9 @@ void HTMLInputElement::setWidth(unsigned width)
setUnsignedIntegralAttribute(widthAttr, width);
}
PassOwnPtr<ListAttributeTargetObserver> ListAttributeTargetObserver::create(const AtomicString& id, HTMLInputElement* element)
PassOwnPtrWillBeRawPtr<ListAttributeTargetObserver> ListAttributeTargetObserver::create(const AtomicString& id, HTMLInputElement* element)
{
return adoptPtr(new ListAttributeTargetObserver(id, element));
return adoptPtrWillBeNoop(new ListAttributeTargetObserver(id, element));
}
ListAttributeTargetObserver::ListAttributeTargetObserver(const AtomicString& id, HTMLInputElement* element)
......@@ -1773,6 +1775,12 @@ ListAttributeTargetObserver::ListAttributeTargetObserver(const AtomicString& id,
{
}
void ListAttributeTargetObserver::trace(Visitor* visitor)
{
visitor->trace(m_element);
IdTargetObserver::trace(visitor);
}
void ListAttributeTargetObserver::idTargetChanged()
{
m_element->listAttributeTargetChanged();
......
......@@ -361,7 +361,7 @@ private:
virtual void subtreeHasChanged() OVERRIDE FINAL;
void setListAttributeTargetObserver(PassOwnPtr<ListAttributeTargetObserver>);
void setListAttributeTargetObserver(PassOwnPtrWillBeRawPtr<ListAttributeTargetObserver>);
void resetListAttributeTargetObserver();
void parseMaxLengthAttribute(const AtomicString&);
void updateValueIfNeeded();
......@@ -401,7 +401,7 @@ private:
// that it lives as long as its owning element lives. If we move the loader into
// the ImageInput object we may delete the loader while this element lives on.
OwnPtr<HTMLImageLoader> m_imageLoader;
OwnPtr<ListAttributeTargetObserver> m_listAttributeTargetObserver;
OwnPtrWillBeMember<ListAttributeTargetObserver> m_listAttributeTargetObserver;
};
} //namespace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment