Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: Source/core/dom/MutationObserverRegistration.cpp

Issue 265793017: Oilpan: move node/element rare data objects to the heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Implement a weak-like Node reference from a MO registration object Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 19 matching lines...) Expand all
30 30
31 #include "config.h" 31 #include "config.h"
32 32
33 #include "core/dom/MutationObserverRegistration.h" 33 #include "core/dom/MutationObserverRegistration.h"
34 34
35 #include "core/dom/Node.h" 35 #include "core/dom/Node.h"
36 #include "core/dom/QualifiedName.h" 36 #include "core/dom/QualifiedName.h"
37 37
38 namespace WebCore { 38 namespace WebCore {
39 39
40 PassOwnPtrWillBeRawPtr<MutationObserverRegistration> MutationObserverRegistratio n::create(MutationObserver& observer, Node& registrationNode, MutationObserverOp tions options, const HashSet<AtomicString>& attributeFilter) 40 PassOwnPtrWillBeRawPtr<MutationObserverRegistration> MutationObserverRegistratio n::create(MutationObserver& observer, Node* registrationNode, MutationObserverOp tions options, const HashSet<AtomicString>& attributeFilter)
41 { 41 {
42 return adoptPtrWillBeNoop(new MutationObserverRegistration(observer, registr ationNode, options, attributeFilter)); 42 return adoptPtrWillBeNoop(new MutationObserverRegistration(observer, registr ationNode, options, attributeFilter));
43 } 43 }
44 44
45 MutationObserverRegistration::MutationObserverRegistration(MutationObserver& obs erver, Node& registrationNode, MutationObserverOptions options, const HashSet<At omicString>& attributeFilter) 45 MutationObserverRegistration::MutationObserverRegistration(MutationObserver& obs erver, Node* registrationNode, MutationObserverOptions options, const HashSet<At omicString>& attributeFilter)
46 : m_observer(observer) 46 : m_observer(observer)
47 , m_registrationNode(registrationNode) 47 , m_registrationNode(registrationNode)
48 #if ENABLE(OILPAN)
49 , m_keepAlive(false)
50 #endif
48 , m_options(options) 51 , m_options(options)
49 , m_attributeFilter(attributeFilter) 52 , m_attributeFilter(attributeFilter)
50 { 53 {
51 m_observer->observationStarted(this); 54 m_observer->observationStarted(this);
52 } 55 }
53 56
54 MutationObserverRegistration::~MutationObserverRegistration() 57 MutationObserverRegistration::~MutationObserverRegistration()
55 { 58 {
56 // dispose() hasn't been called if this assert triggers. 59 #if !ENABLE(OILPAN)
57 ASSERT(!m_observer); 60 dispose();
61 #endif
58 } 62 }
59 63
60 void MutationObserverRegistration::dispose() 64 void MutationObserverRegistration::dispose()
61 { 65 {
62 clearTransientRegistrations(); 66 clearTransientRegistrations();
63 m_observer->observationEnded(this); 67 m_observer->observationEnded(this);
64 m_observer.clear(); 68 m_observer.clear();
65 } 69 }
66 70
67 void MutationObserverRegistration::resetObservation(MutationObserverOptions opti ons, const HashSet<AtomicString>& attributeFilter) 71 void MutationObserverRegistration::resetObservation(MutationObserverOptions opti ons, const HashSet<AtomicString>& attributeFilter)
68 { 72 {
69 clearTransientRegistrations(); 73 clearTransientRegistrations();
70 m_options = options; 74 m_options = options;
71 m_attributeFilter = attributeFilter; 75 m_attributeFilter = attributeFilter;
72 } 76 }
73 77
74 void MutationObserverRegistration::observedSubtreeNodeWillDetach(Node& node) 78 void MutationObserverRegistration::observedSubtreeNodeWillDetach(Node& node)
75 { 79 {
76 if (!isSubtree()) 80 if (!isSubtree())
77 return; 81 return;
78 82
79 node.registerTransientMutationObserver(this); 83 node.registerTransientMutationObserver(this);
80 m_observer->setHasTransientRegistration(); 84 m_observer->setHasTransientRegistration();
81 85
82 if (!m_transientRegistrationNodes) { 86 if (!m_transientRegistrationNodes) {
83 m_transientRegistrationNodes = adoptPtr(new NodeHashSet); 87 m_transientRegistrationNodes = adoptPtr(new NodeHashSet);
84 88
89 #if ENABLE(OILPAN)
90 ASSERT(!m_keepAlive);
91 m_keepAlive = true;
92 #else
85 ASSERT(!m_registrationNodeKeepAlive); 93 ASSERT(!m_registrationNodeKeepAlive);
86 m_registrationNodeKeepAlive = PassRefPtr<Node>(m_registrationNode); // B alanced in clearTransientRegistrations. 94 m_registrationNodeKeepAlive = PassRefPtr<Node>(m_registrationNode.get()) ; // Balanced in clearTransientRegistrations.
95 #endif
87 } 96 }
88 m_transientRegistrationNodes->add(&node); 97 m_transientRegistrationNodes->add(&node);
89 } 98 }
90 99
91 void MutationObserverRegistration::clearTransientRegistrations() 100 void MutationObserverRegistration::clearTransientRegistrations()
92 { 101 {
93 if (!m_transientRegistrationNodes) { 102 if (!m_transientRegistrationNodes) {
103 #if ENABLE(OILPAN)
104 ASSERT(!m_keepAlive);
105 #else
94 ASSERT(!m_registrationNodeKeepAlive); 106 ASSERT(!m_registrationNodeKeepAlive);
107 #endif
95 return; 108 return;
96 } 109 }
97 110
98 for (NodeHashSet::iterator iter = m_transientRegistrationNodes->begin(); ite r != m_transientRegistrationNodes->end(); ++iter) 111 for (NodeHashSet::iterator iter = m_transientRegistrationNodes->begin(); ite r != m_transientRegistrationNodes->end(); ++iter)
99 (*iter)->unregisterTransientMutationObserver(this); 112 (*iter)->unregisterTransientMutationObserver(this);
100 113
101 m_transientRegistrationNodes.clear(); 114 m_transientRegistrationNodes.clear();
102 115
116 #if ENABLE(OILPAN)
117 ASSERT(m_keepAlive);
118 m_keepAlive = false;
119 #else
103 ASSERT(m_registrationNodeKeepAlive); 120 ASSERT(m_registrationNodeKeepAlive);
104 m_registrationNodeKeepAlive = nullptr; // Balanced in observeSubtreeNodeWill Detach. 121 m_registrationNodeKeepAlive = nullptr; // Balanced in observeSubtreeNodeWill Detach.
122 #endif
105 } 123 }
106 124
107 void MutationObserverRegistration::unregister() 125 void MutationObserverRegistration::unregister()
108 { 126 {
109 m_registrationNode.unregisterMutationObserver(this); 127 m_registrationNode->unregisterMutationObserver(this);
110 // The above line will cause this object to be deleted, so don't do any more in this function. 128 // The above line will cause this object to be deleted, so don't do any more in this function.
111 } 129 }
112 130
113 bool MutationObserverRegistration::shouldReceiveMutationFrom(Node& node, Mutatio nObserver::MutationType type, const QualifiedName* attributeName) const 131 bool MutationObserverRegistration::shouldReceiveMutationFrom(Node& node, Mutatio nObserver::MutationType type, const QualifiedName* attributeName) const
114 { 132 {
115 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute Name); 133 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute Name);
116 if (!(m_options & type)) 134 if (!(m_options & type))
117 return false; 135 return false;
118 136
119 if (m_registrationNode != node && !isSubtree()) 137 if (m_registrationNode != &node && !isSubtree())
120 return false; 138 return false;
121 139
122 if (type != MutationObserver::Attributes || !(m_options & MutationObserver:: AttributeFilter)) 140 if (type != MutationObserver::Attributes || !(m_options & MutationObserver:: AttributeFilter))
123 return true; 141 return true;
124 142
125 if (!attributeName->namespaceURI().isNull()) 143 if (!attributeName->namespaceURI().isNull())
126 return false; 144 return false;
127 145
128 return m_attributeFilter.contains(attributeName->localName()); 146 return m_attributeFilter.contains(attributeName->localName());
129 } 147 }
130 148
131 void MutationObserverRegistration::addRegistrationNodesToSet(HashSet<Node*>& nod es) const 149 void MutationObserverRegistration::addRegistrationNodesToSet(HashSet<Node*>& nod es) const
132 { 150 {
133 nodes.add(&m_registrationNode); 151 nodes.add(m_registrationNode.get());
134 if (!m_transientRegistrationNodes) 152 if (!m_transientRegistrationNodes)
135 return; 153 return;
136 for (NodeHashSet::const_iterator iter = m_transientRegistrationNodes->begin( ); iter != m_transientRegistrationNodes->end(); ++iter) 154 for (NodeHashSet::const_iterator iter = m_transientRegistrationNodes->begin( ); iter != m_transientRegistrationNodes->end(); ++iter)
137 nodes.add(iter->get()); 155 nodes.add(iter->get());
138 } 156 }
139 157
158 #if ENABLE(OILPAN)
159 void MutationObserverRegistration::clearWeakMembers(Visitor* visitor)
160 {
161 if (!m_keepAlive && !visitor->isAlive(m_registrationNode))
162 dispose();
haraken 2014/05/07 02:10:26 Would you elaborate on why we need to call dispose
sof 2014/05/07 07:01:01 The pair of weak&strong fields stays the same (see
163 }
164 #endif
165
140 void MutationObserverRegistration::trace(Visitor* visitor) 166 void MutationObserverRegistration::trace(Visitor* visitor)
141 { 167 {
142 visitor->trace(m_observer); 168 visitor->trace(m_observer);
169 visitor->trace(m_registrationNode);
170 #if ENABLE(OILPAN)
171 visitor->registerWeakMembers<MutationObserverRegistration, &MutationObserver Registration::clearWeakMembers>(this);
172 #endif
143 } 173 }
144 174
145 } // namespace WebCore 175 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698