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

Side by Side Diff: Source/core/dom/TreeScope.h

Issue 235113002: Oilpan: Remove guardRef and guardDeref from TreeScope. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address comments. Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All Rights Reserved. 2 * Copyright (C) 2011 Google Inc. All Rights Reserved.
3 * Copyright (C) 2012 Apple Inc. All Rights Reserved. 3 * Copyright (C) 2012 Apple Inc. All Rights Reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 bool applyAuthorStyles() const; 96 bool applyAuthorStyles() const;
97 97
98 // Used by the basic DOM mutation methods (e.g., appendChild()). 98 // Used by the basic DOM mutation methods (e.g., appendChild()).
99 void adoptIfNeeded(Node&); 99 void adoptIfNeeded(Node&);
100 100
101 Node& rootNode() const { return m_rootNode; } 101 Node& rootNode() const { return m_rootNode; }
102 102
103 IdTargetObserverRegistry& idTargetObserverRegistry() const { return *m_idTar getObserverRegistry.get(); } 103 IdTargetObserverRegistry& idTargetObserverRegistry() const { return *m_idTar getObserverRegistry.get(); }
104 104
105
106 #if !ENABLE(OILPAN)
105 // Nodes belonging to this scope hold guard references - 107 // Nodes belonging to this scope hold guard references -
106 // these are enough to keep the scope from being destroyed, but 108 // these are enough to keep the scope from being destroyed, but
107 // not enough to keep it from removing its children. This allows a 109 // not enough to keep it from removing its children. This allows a
108 // node that outlives its scope to still have a valid document 110 // node that outlives its scope to still have a valid document
109 // pointer without introducing reference cycles. 111 // pointer without introducing reference cycles.
110 void guardRef() 112 void guardRef()
111 { 113 {
112 #if ENABLE(OILPAN)
113 if (!m_guardRefCount) {
114 ASSERT(!m_keepAlive);
115 m_keepAlive = adoptPtr(new Persistent<TreeScope>(this));
116 }
117 #else
118 ASSERT(!deletionHasBegun()); 114 ASSERT(!deletionHasBegun());
119 #endif
120 ++m_guardRefCount; 115 ++m_guardRefCount;
121 } 116 }
122 117
123 void guardDeref() 118 void guardDeref()
124 { 119 {
125 ASSERT(m_guardRefCount > 0); 120 ASSERT(m_guardRefCount > 0);
126 #if !ENABLE(OILPAN)
127 ASSERT(!deletionHasBegun()); 121 ASSERT(!deletionHasBegun());
128 #endif
129 --m_guardRefCount; 122 --m_guardRefCount;
130 #if ENABLE(OILPAN)
131 if (!m_guardRefCount)
132 clearKeepAlive();
133 #else
134 if (!m_guardRefCount && !refCount() && !rootNodeHasTreeSharedParent()) { 123 if (!m_guardRefCount && !refCount() && !rootNodeHasTreeSharedParent()) {
135 beginDeletion(); 124 beginDeletion();
136 delete this; 125 delete this;
137 } 126 }
127 }
138 #endif 128 #endif
139 }
140 129
141 void removedLastRefToScope(); 130 void removedLastRefToScope();
142 131
143 #if ENABLE(OILPAN)
144 void clearKeepAlive()
145 {
146 ASSERT(m_keepAlive);
147 m_keepAlive = nullptr;
148 }
149 #endif
150
151 bool isInclusiveAncestorOf(const TreeScope&) const; 132 bool isInclusiveAncestorOf(const TreeScope&) const;
152 unsigned short comparePosition(const TreeScope&) const; 133 unsigned short comparePosition(const TreeScope&) const;
153 134
154 const TreeScope* commonAncestorTreeScope(const TreeScope& other) const; 135 const TreeScope* commonAncestorTreeScope(const TreeScope& other) const;
155 TreeScope* commonAncestorTreeScope(TreeScope& other); 136 TreeScope* commonAncestorTreeScope(TreeScope& other);
156 137
157 Element* getElementByAccessKey(const String& key) const; 138 Element* getElementByAccessKey(const String& key) const;
158 139
140 virtual void trace(Visitor*);
141
159 protected: 142 protected:
160 TreeScope(ContainerNode&, Document&); 143 TreeScope(ContainerNode&, Document&);
161 TreeScope(Document&); 144 TreeScope(Document&);
162 virtual ~TreeScope(); 145 virtual ~TreeScope();
163 146
164 void destroyTreeScopeData(); 147 void destroyTreeScopeData();
165 void setDocument(Document& document) { m_document = &document; } 148 void setDocument(Document& document) { m_document = &document; }
166 void setParentTreeScope(TreeScope&); 149 void setParentTreeScope(TreeScope&);
167 150
151 #if !ENABLE(OILPAN)
168 bool hasGuardRefCount() const { return m_guardRefCount; } 152 bool hasGuardRefCount() const { return m_guardRefCount; }
153 #endif
169 154
170 void setNeedsStyleRecalcForViewportUnits(); 155 void setNeedsStyleRecalcForViewportUnits();
171 156
172 private: 157 private:
173 virtual void dispose() { } 158 virtual void dispose() { }
174 159
175 int refCount() const; 160 int refCount() const;
176 #if SECURITY_ASSERT_ENABLED 161 #if SECURITY_ASSERT_ENABLED
177 bool deletionHasBegun(); 162 bool deletionHasBegun();
178 void beginDeletion(); 163 void beginDeletion();
179 #else 164 #else
180 bool deletionHasBegun() { return false; } 165 bool deletionHasBegun() { return false; }
181 void beginDeletion() { } 166 void beginDeletion() { }
182 #endif 167 #endif
183 168
184 bool rootNodeHasTreeSharedParent() const; 169 bool rootNodeHasTreeSharedParent() const;
185 170
186 Node& m_rootNode; 171 Node& m_rootNode;
187 Document* m_document; 172 Document* m_document;
188 TreeScope* m_parentTreeScope; 173 RawPtrWillBeMember<TreeScope> m_parentTreeScope;
174
175 #if !ENABLE(OILPAN)
189 int m_guardRefCount; 176 int m_guardRefCount;
177 #endif
190 178
191 OwnPtr<DocumentOrderedMap> m_elementsById; 179 OwnPtr<DocumentOrderedMap> m_elementsById;
192 OwnPtr<DocumentOrderedMap> m_imageMapsByName; 180 OwnPtr<DocumentOrderedMap> m_imageMapsByName;
193 OwnPtr<DocumentOrderedMap> m_labelsByForAttribute; 181 OwnPtr<DocumentOrderedMap> m_labelsByForAttribute;
haraken 2014/04/25 05:21:42 Just help me understand: When do we need to change
Mads Ager (chromium) 2014/04/25 10:58:25 These are owned by the document and are updated in
194 182
195 OwnPtr<IdTargetObserverRegistry> m_idTargetObserverRegistry; 183 OwnPtr<IdTargetObserverRegistry> m_idTargetObserverRegistry;
196 184
197 #if ENABLE(OILPAN) 185 mutable RefPtrWillBeMember<DOMSelection> m_selection;
198 // With Oilpan, a non-zero reference count will keep the TreeScope alive
199 // with a self-persistent handle. Whenever the ref count goes above zero
200 // we register the TreeScope as a root for garbage collection by allocating a
201 // persistent handle to the object itself. When the ref count goes to zero
202 // we deallocate the persistent handle again so the object can die if there
203 // are no other things keeping it alive.
204 //
205 // FIXME: Oilpan: Remove m_keepAlive and ref counting and use tracing instea d.
206 GC_PLUGIN_IGNORE("359444")
207 OwnPtr<Persistent<TreeScope> > m_keepAlive;
208 #endif
209
210 GC_PLUGIN_IGNORE("359444")
211 mutable RefPtrWillBePersistent<DOMSelection> m_selection;
212 }; 186 };
213 187
214 inline bool TreeScope::hasElementWithId(StringImpl* id) const 188 inline bool TreeScope::hasElementWithId(StringImpl* id) const
215 { 189 {
216 ASSERT(id); 190 ASSERT(id);
217 return m_elementsById && m_elementsById->contains(id); 191 return m_elementsById && m_elementsById->contains(id);
218 } 192 }
219 193
220 inline bool TreeScope::containsMultipleElementsWithId(const AtomicString& id) co nst 194 inline bool TreeScope::containsMultipleElementsWithId(const AtomicString& id) co nst
221 { 195 {
222 return m_elementsById && m_elementsById->containsMultiple(id.impl()); 196 return m_elementsById && m_elementsById->containsMultiple(id.impl());
223 } 197 }
224 198
225 inline bool operator==(const TreeScope& a, const TreeScope& b) { return &a == &b ; } 199 inline bool operator==(const TreeScope& a, const TreeScope& b) { return &a == &b ; }
226 inline bool operator==(const TreeScope& a, const TreeScope* b) { return &a == b; } 200 inline bool operator==(const TreeScope& a, const TreeScope* b) { return &a == b; }
227 inline bool operator==(const TreeScope* a, const TreeScope& b) { return a == &b; } 201 inline bool operator==(const TreeScope* a, const TreeScope& b) { return a == &b; }
228 inline bool operator!=(const TreeScope& a, const TreeScope& b) { return !(a == b ); } 202 inline bool operator!=(const TreeScope& a, const TreeScope& b) { return !(a == b ); }
229 inline bool operator!=(const TreeScope& a, const TreeScope* b) { return !(a == b ); } 203 inline bool operator!=(const TreeScope& a, const TreeScope* b) { return !(a == b ); }
230 inline bool operator!=(const TreeScope* a, const TreeScope& b) { return !(a == b ); } 204 inline bool operator!=(const TreeScope* a, const TreeScope& b) { return !(a == b ); }
231 205
232 HitTestResult hitTestInDocument(const Document*, int x, int y); 206 HitTestResult hitTestInDocument(const Document*, int x, int y);
233 TreeScope* commonTreeScope(Node*, Node*); 207 TreeScope* commonTreeScope(Node*, Node*);
234 208
235 } // namespace WebCore 209 } // namespace WebCore
236 210
237 #endif // TreeScope_h 211 #endif // TreeScope_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698