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

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: Rebased + have MutationObserver keep a weak ref to registrations 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 , m_options(options) 48 , m_options(options)
49 , m_attributeFilter(attributeFilter) 49 , m_attributeFilter(attributeFilter)
50 { 50 {
51 m_observer->observationStarted(this); 51 m_observer->observationStarted(this);
52 } 52 }
53 53
54 MutationObserverRegistration::~MutationObserverRegistration() 54 MutationObserverRegistration::~MutationObserverRegistration()
55 { 55 {
56 // dispose() hasn't been called if this assert triggers. 56 #if !ENABLE(OILPAN)
57 ASSERT(!m_observer); 57 dispose();
58 #endif
58 } 59 }
59 60
60 void MutationObserverRegistration::dispose() 61 void MutationObserverRegistration::dispose()
61 { 62 {
62 clearTransientRegistrations(); 63 clearTransientRegistrations();
63 m_observer->observationEnded(this); 64 m_observer->observationEnded(this);
64 m_observer.clear(); 65 m_observer.clear();
65 } 66 }
66 67
67 void MutationObserverRegistration::resetObservation(MutationObserverOptions opti ons, const HashSet<AtomicString>& attributeFilter) 68 void MutationObserverRegistration::resetObservation(MutationObserverOptions opti ons, const HashSet<AtomicString>& attributeFilter)
68 { 69 {
69 clearTransientRegistrations(); 70 clearTransientRegistrations();
70 m_options = options; 71 m_options = options;
71 m_attributeFilter = attributeFilter; 72 m_attributeFilter = attributeFilter;
72 } 73 }
73 74
74 void MutationObserverRegistration::observedSubtreeNodeWillDetach(Node& node) 75 void MutationObserverRegistration::observedSubtreeNodeWillDetach(Node& node)
75 { 76 {
76 if (!isSubtree()) 77 if (!isSubtree())
77 return; 78 return;
78 79
79 node.registerTransientMutationObserver(this); 80 node.registerTransientMutationObserver(this);
80 m_observer->setHasTransientRegistration(); 81 m_observer->setHasTransientRegistration();
81 82
82 if (!m_transientRegistrationNodes) { 83 if (!m_transientRegistrationNodes) {
83 m_transientRegistrationNodes = adoptPtr(new NodeHashSet); 84 m_transientRegistrationNodes = adoptPtr(new NodeHashSet);
84 85
85 ASSERT(!m_registrationNodeKeepAlive); 86 ASSERT(!m_registrationNodeKeepAlive);
86 m_registrationNodeKeepAlive = PassRefPtr<Node>(m_registrationNode); // B alanced in clearTransientRegistrations. 87 m_registrationNodeKeepAlive = PassRefPtrWillBeRawPtr<Node>(m_registratio nNode.get()); // Balanced in clearTransientRegistrations.
haraken 2014/05/08 04:14:00 Add ASSERT(m_registrationNode).
sof 2014/05/08 06:43:15 Done.
87 } 88 }
88 m_transientRegistrationNodes->add(&node); 89 m_transientRegistrationNodes->add(&node);
89 } 90 }
90 91
91 void MutationObserverRegistration::clearTransientRegistrations() 92 void MutationObserverRegistration::clearTransientRegistrations()
92 { 93 {
93 if (!m_transientRegistrationNodes) { 94 if (!m_transientRegistrationNodes) {
94 ASSERT(!m_registrationNodeKeepAlive); 95 ASSERT(!m_registrationNodeKeepAlive);
95 return; 96 return;
96 } 97 }
97 98
98 for (NodeHashSet::iterator iter = m_transientRegistrationNodes->begin(); ite r != m_transientRegistrationNodes->end(); ++iter) 99 for (NodeHashSet::iterator iter = m_transientRegistrationNodes->begin(); ite r != m_transientRegistrationNodes->end(); ++iter)
99 (*iter)->unregisterTransientMutationObserver(this); 100 (*iter)->unregisterTransientMutationObserver(this);
100 101
101 m_transientRegistrationNodes.clear(); 102 m_transientRegistrationNodes.clear();
102 103
103 ASSERT(m_registrationNodeKeepAlive); 104 ASSERT(m_registrationNodeKeepAlive);
104 m_registrationNodeKeepAlive = nullptr; // Balanced in observeSubtreeNodeWill Detach. 105 m_registrationNodeKeepAlive = nullptr; // Balanced in observeSubtreeNodeWill Detach.
105 } 106 }
106 107
107 void MutationObserverRegistration::unregister() 108 void MutationObserverRegistration::unregister()
108 { 109 {
109 m_registrationNode.unregisterMutationObserver(this); 110 m_registrationNode->unregisterMutationObserver(this);
haraken 2014/05/08 04:14:00 Add: ASSERT(m_registrationNode); ASSERT(m_registr
sof 2014/05/08 06:43:15 First yes, 2nd wouldn't be right. Done.
110 // The above line will cause this object to be deleted, so don't do any more in this function. 111 // The above line will cause this object to be deleted, so don't do any more in this function.
111 } 112 }
112 113
113 bool MutationObserverRegistration::shouldReceiveMutationFrom(Node& node, Mutatio nObserver::MutationType type, const QualifiedName* attributeName) const 114 bool MutationObserverRegistration::shouldReceiveMutationFrom(Node& node, Mutatio nObserver::MutationType type, const QualifiedName* attributeName) const
114 { 115 {
115 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute Name); 116 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute Name);
116 if (!(m_options & type)) 117 if (!(m_options & type))
117 return false; 118 return false;
118 119
119 if (m_registrationNode != node && !isSubtree()) 120 if (m_registrationNode != &node && !isSubtree())
120 return false; 121 return false;
121 122
122 if (type != MutationObserver::Attributes || !(m_options & MutationObserver:: AttributeFilter)) 123 if (type != MutationObserver::Attributes || !(m_options & MutationObserver:: AttributeFilter))
123 return true; 124 return true;
124 125
125 if (!attributeName->namespaceURI().isNull()) 126 if (!attributeName->namespaceURI().isNull())
126 return false; 127 return false;
127 128
128 return m_attributeFilter.contains(attributeName->localName()); 129 return m_attributeFilter.contains(attributeName->localName());
129 } 130 }
130 131
131 void MutationObserverRegistration::addRegistrationNodesToSet(HashSet<Node*>& nod es) const 132 void MutationObserverRegistration::addRegistrationNodesToSet(HashSet<Node*>& nod es) const
132 { 133 {
133 nodes.add(&m_registrationNode); 134 nodes.add(m_registrationNode.get());
haraken 2014/05/08 04:14:00 Add: ASSERT(m_registrationNode); ASSERT(m_registr
sof 2014/05/08 06:43:15 First yes, 2nd wouldn't be right.
134 if (!m_transientRegistrationNodes) 135 if (!m_transientRegistrationNodes)
135 return; 136 return;
136 for (NodeHashSet::const_iterator iter = m_transientRegistrationNodes->begin( ); iter != m_transientRegistrationNodes->end(); ++iter) 137 for (NodeHashSet::const_iterator iter = m_transientRegistrationNodes->begin( ); iter != m_transientRegistrationNodes->end(); ++iter)
137 nodes.add(iter->get()); 138 nodes.add(iter->get());
138 } 139 }
139 140
140 void MutationObserverRegistration::trace(Visitor* visitor) 141 void MutationObserverRegistration::trace(Visitor* visitor)
141 { 142 {
142 visitor->trace(m_observer); 143 visitor->trace(m_observer);
144 visitor->trace(m_registrationNode);
145 visitor->trace(m_registrationNodeKeepAlive);
143 } 146 }
144 147
145 } // namespace WebCore 148 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698