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

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 + add some asserts for registration Node being present. 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
« no previous file with comments | « Source/core/dom/MutationObserverRegistration.h ('k') | Source/core/dom/Node.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
86 ASSERT(m_registrationNode);
85 ASSERT(!m_registrationNodeKeepAlive); 87 ASSERT(!m_registrationNodeKeepAlive);
86 m_registrationNodeKeepAlive = PassRefPtr<Node>(m_registrationNode); // B alanced in clearTransientRegistrations. 88 m_registrationNodeKeepAlive = PassRefPtrWillBeRawPtr<Node>(m_registratio nNode.get()); // Balanced in clearTransientRegistrations.
87 } 89 }
88 m_transientRegistrationNodes->add(&node); 90 m_transientRegistrationNodes->add(&node);
89 } 91 }
90 92
91 void MutationObserverRegistration::clearTransientRegistrations() 93 void MutationObserverRegistration::clearTransientRegistrations()
92 { 94 {
93 if (!m_transientRegistrationNodes) { 95 if (!m_transientRegistrationNodes) {
94 ASSERT(!m_registrationNodeKeepAlive); 96 ASSERT(!m_registrationNodeKeepAlive);
95 return; 97 return;
96 } 98 }
97 99
98 for (NodeHashSet::iterator iter = m_transientRegistrationNodes->begin(); ite r != m_transientRegistrationNodes->end(); ++iter) 100 for (NodeHashSet::iterator iter = m_transientRegistrationNodes->begin(); ite r != m_transientRegistrationNodes->end(); ++iter)
99 (*iter)->unregisterTransientMutationObserver(this); 101 (*iter)->unregisterTransientMutationObserver(this);
100 102
101 m_transientRegistrationNodes.clear(); 103 m_transientRegistrationNodes.clear();
102 104
103 ASSERT(m_registrationNodeKeepAlive); 105 ASSERT(m_registrationNodeKeepAlive);
104 m_registrationNodeKeepAlive = nullptr; // Balanced in observeSubtreeNodeWill Detach. 106 m_registrationNodeKeepAlive = nullptr; // Balanced in observeSubtreeNodeWill Detach.
105 } 107 }
106 108
107 void MutationObserverRegistration::unregister() 109 void MutationObserverRegistration::unregister()
108 { 110 {
109 m_registrationNode.unregisterMutationObserver(this); 111 ASSERT(m_registrationNode);
112 m_registrationNode->unregisterMutationObserver(this);
110 // The above line will cause this object to be deleted, so don't do any more in this function. 113 // The above line will cause this object to be deleted, so don't do any more in this function.
111 } 114 }
112 115
113 bool MutationObserverRegistration::shouldReceiveMutationFrom(Node& node, Mutatio nObserver::MutationType type, const QualifiedName* attributeName) const 116 bool MutationObserverRegistration::shouldReceiveMutationFrom(Node& node, Mutatio nObserver::MutationType type, const QualifiedName* attributeName) const
114 { 117 {
115 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute Name); 118 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute Name);
116 if (!(m_options & type)) 119 if (!(m_options & type))
117 return false; 120 return false;
118 121
119 if (m_registrationNode != node && !isSubtree()) 122 if (m_registrationNode != &node && !isSubtree())
120 return false; 123 return false;
121 124
122 if (type != MutationObserver::Attributes || !(m_options & MutationObserver:: AttributeFilter)) 125 if (type != MutationObserver::Attributes || !(m_options & MutationObserver:: AttributeFilter))
123 return true; 126 return true;
124 127
125 if (!attributeName->namespaceURI().isNull()) 128 if (!attributeName->namespaceURI().isNull())
126 return false; 129 return false;
127 130
128 return m_attributeFilter.contains(attributeName->localName()); 131 return m_attributeFilter.contains(attributeName->localName());
129 } 132 }
130 133
131 void MutationObserverRegistration::addRegistrationNodesToSet(HashSet<Node*>& nod es) const 134 void MutationObserverRegistration::addRegistrationNodesToSet(HashSet<Node*>& nod es) const
132 { 135 {
133 nodes.add(&m_registrationNode); 136 ASSERT(m_registrationNode);
137 nodes.add(m_registrationNode.get());
134 if (!m_transientRegistrationNodes) 138 if (!m_transientRegistrationNodes)
135 return; 139 return;
136 for (NodeHashSet::const_iterator iter = m_transientRegistrationNodes->begin( ); iter != m_transientRegistrationNodes->end(); ++iter) 140 for (NodeHashSet::const_iterator iter = m_transientRegistrationNodes->begin( ); iter != m_transientRegistrationNodes->end(); ++iter)
137 nodes.add(iter->get()); 141 nodes.add(iter->get());
138 } 142 }
139 143
140 void MutationObserverRegistration::trace(Visitor* visitor) 144 void MutationObserverRegistration::trace(Visitor* visitor)
141 { 145 {
142 visitor->trace(m_observer); 146 visitor->trace(m_observer);
147 visitor->trace(m_registrationNode);
148 visitor->trace(m_registrationNodeKeepAlive);
143 } 149 }
144 150
145 } // namespace WebCore 151 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/MutationObserverRegistration.h ('k') | Source/core/dom/Node.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698