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

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

Issue 965393002: Simplify ContextLifecycleNotifier's handling of ActiveDOMObjects. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: manually count the ActiveDOMObjects instead Created 5 years, 9 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
« no previous file with comments | « Source/core/dom/ContextLifecycleNotifier.h ('k') | Source/core/dom/ExecutionContext.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) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2013 Google Inc. All Rights Reserved. 3 * Copyright (C) 2013 Google 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 23 matching lines...) Expand all
34 namespace blink { 34 namespace blink {
35 35
36 ContextLifecycleNotifier::ContextLifecycleNotifier(ExecutionContext* context) 36 ContextLifecycleNotifier::ContextLifecycleNotifier(ExecutionContext* context)
37 : LifecycleNotifier<ExecutionContext, ContextLifecycleObserver>(context) 37 : LifecycleNotifier<ExecutionContext, ContextLifecycleObserver>(context)
38 { 38 {
39 } 39 }
40 40
41 void ContextLifecycleNotifier::addObserver(ContextLifecycleObserver* observer) 41 void ContextLifecycleNotifier::addObserver(ContextLifecycleObserver* observer)
42 { 42 {
43 LifecycleNotifier<ExecutionContext, ContextLifecycleObserver>::addObserver(o bserver); 43 LifecycleNotifier<ExecutionContext, ContextLifecycleObserver>::addObserver(o bserver);
44 if (observer->observerType() == ContextLifecycleObserver::ActiveDOMObjectTyp e) { 44 if (observer->observerType() == ContextLifecycleObserver::ActiveDOMObjectTyp e)
45 RELEASE_ASSERT(m_iterating != IteratingOverActiveDOMObjects); 45 RELEASE_ASSERT(m_iterating != IteratingOverActiveDOMObjects);
46 m_activeDOMObjects.add(static_cast<ActiveDOMObject*>(observer));
47 }
48 } 46 }
49 47
50 void ContextLifecycleNotifier::removeObserver(ContextLifecycleObserver* observer ) 48 void ContextLifecycleNotifier::removeObserver(ContextLifecycleObserver* observer )
51 { 49 {
52 LifecycleNotifier<ExecutionContext, ContextLifecycleObserver>::removeObserve r(observer); 50 LifecycleNotifier<ExecutionContext, ContextLifecycleObserver>::removeObserve r(observer);
53 if (observer->observerType() == ContextLifecycleObserver::ActiveDOMObjectTyp e)
54 m_activeDOMObjects.remove(static_cast<ActiveDOMObject*>(observer));
55 } 51 }
56 52
57 void ContextLifecycleNotifier::notifyResumingActiveDOMObjects() 53 void ContextLifecycleNotifier::notifyResumingActiveDOMObjects()
58 { 54 {
59 TemporaryChange<IterationType> scope(m_iterating, IteratingOverActiveDOMObje cts); 55 TemporaryChange<IterationType> scope(m_iterating, IteratingOverActiveDOMObje cts);
60 Vector<ActiveDOMObject*> snapshotOfActiveDOMObjects; 56 Vector<ContextLifecycleObserver*> snapshotOfObservers;
61 copyToVector(m_activeDOMObjects, snapshotOfActiveDOMObjects); 57 copyToVector(m_observers, snapshotOfObservers);
62 for (ActiveDOMObject* obj : snapshotOfActiveDOMObjects) { 58 for (ContextLifecycleObserver* observer : snapshotOfObservers) {
63 // FIXME: Oilpan: At the moment, it's possible that the ActiveDOMObject 59 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec tType)
64 // is destructed during the iteration. Once we enable Oilpan by default 60 continue;
65 // for ActiveDOMObjects, we can remove the hack by making 61 // FIXME: Oilpan: At the moment, it's possible that a ActiveDOMObject
66 // m_activeDOMObjects a HeapHashSet<WeakMember<ActiveDOMObject>>. 62 // observer is destructed while iterating. Once we enable Oilpan by defa ult
67 // (i.e., we can just iterate m_activeDOMObjects without taking 63 // for all LifecycleObserver<T>s, we can remove the hack by making m_obs ervers
68 // a snapshot). 64 // a HeapHashSet<WeakMember<LifecycleObserver<T>>>.
65 // (i.e., we can just iterate m_observers without taking a snapshot).
69 // For more details, see https://codereview.chromium.org/247253002/. 66 // For more details, see https://codereview.chromium.org/247253002/.
70 if (m_activeDOMObjects.contains(obj)) { 67 if (m_observers.contains(observer)) {
71 ASSERT(obj->executionContext() == context()); 68 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs erver);
72 ASSERT(obj->suspendIfNeededCalled()); 69 ASSERT(activeDOMObject->executionContext() == context());
73 obj->resume(); 70 ASSERT(activeDOMObject->suspendIfNeededCalled());
71 activeDOMObject->resume();
74 } 72 }
75 } 73 }
76 } 74 }
77 75
78 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects() 76 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects()
79 { 77 {
80 TemporaryChange<IterationType> scope(m_iterating, IteratingOverActiveDOMObje cts); 78 TemporaryChange<IterationType> scope(m_iterating, IteratingOverActiveDOMObje cts);
81 Vector<ActiveDOMObject*> snapshotOfActiveDOMObjects; 79 Vector<ContextLifecycleObserver*> snapshotOfObservers;
82 copyToVector(m_activeDOMObjects, snapshotOfActiveDOMObjects); 80 copyToVector(m_observers, snapshotOfObservers);
83 for (ActiveDOMObject* obj : snapshotOfActiveDOMObjects) { 81 for (ContextLifecycleObserver* observer : snapshotOfObservers) {
82 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec tType)
83 continue;
84 // It's possible that the ActiveDOMObject is already destructed. 84 // It's possible that the ActiveDOMObject is already destructed.
85 // See a FIXME above. 85 // See a FIXME above.
86 if (m_activeDOMObjects.contains(obj)) { 86 if (m_observers.contains(observer)) {
87 ASSERT(obj->executionContext() == context()); 87 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs erver);
88 ASSERT(obj->suspendIfNeededCalled()); 88 ASSERT(activeDOMObject->executionContext() == context());
89 obj->suspend(); 89 ASSERT(activeDOMObject->suspendIfNeededCalled());
90 activeDOMObject->suspend();
90 } 91 }
91 } 92 }
92 } 93 }
93 94
94 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() 95 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects()
95 { 96 {
96 TemporaryChange<IterationType> scope(m_iterating, IteratingOverActiveDOMObje cts); 97 TemporaryChange<IterationType> scope(m_iterating, IteratingOverActiveDOMObje cts);
97 Vector<ActiveDOMObject*> snapshotOfActiveDOMObjects; 98 Vector<ContextLifecycleObserver*> snapshotOfObservers;
98 copyToVector(m_activeDOMObjects, snapshotOfActiveDOMObjects); 99 copyToVector(m_observers, snapshotOfObservers);
99 for (ActiveDOMObject* obj : snapshotOfActiveDOMObjects) { 100 for (ContextLifecycleObserver* observer : snapshotOfObservers) {
101 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec tType)
102 continue;
100 // It's possible that the ActiveDOMObject is already destructed. 103 // It's possible that the ActiveDOMObject is already destructed.
101 // See a FIXME above. 104 // See a FIXME above.
102 if (m_activeDOMObjects.contains(obj)) { 105 if (m_observers.contains(observer)) {
103 ASSERT(obj->executionContext() == context()); 106 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs erver);
104 ASSERT(obj->suspendIfNeededCalled()); 107 ASSERT(activeDOMObject->executionContext() == context());
105 obj->stop(); 108 ASSERT(activeDOMObject->suspendIfNeededCalled());
109 activeDOMObject->stop();
106 } 110 }
107 } 111 }
108 } 112 }
109 113
114 unsigned ContextLifecycleNotifier::activeDOMObjectCount() const
115 {
116 unsigned activeDOMObjects = 0;
117 for (ContextLifecycleObserver* observer : m_observers) {
118 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec tType)
119 continue;
120 activeDOMObjects++;
121 }
122 return activeDOMObjects;
123 }
124
110 bool ContextLifecycleNotifier::hasPendingActivity() const 125 bool ContextLifecycleNotifier::hasPendingActivity() const
111 { 126 {
112 for (ActiveDOMObject* obj : m_activeDOMObjects) { 127 for (ContextLifecycleObserver* observer : m_observers) {
113 if (obj->hasPendingActivity()) 128 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec tType)
129 continue;
130 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observe r);
131 if (activeDOMObject->hasPendingActivity())
114 return true; 132 return true;
115 } 133 }
116 return false; 134 return false;
117 } 135 }
118 136
137 #if ENABLE(ASSERT)
138 bool ContextLifecycleNotifier::contains(ActiveDOMObject* object) const
139 {
140 for (ContextLifecycleObserver* observer : m_observers) {
141 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec tType)
142 continue;
143 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observe r);
144 if (activeDOMObject == object)
145 return true;
146 }
147 return false;
148 }
149 #endif
150
119 } // namespace blink 151 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/dom/ContextLifecycleNotifier.h ('k') | Source/core/dom/ExecutionContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698