OLD | NEW |
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 15 matching lines...) Expand all Loading... |
26 */ | 26 */ |
27 | 27 |
28 #include "config.h" | 28 #include "config.h" |
29 #include "core/dom/ContextLifecycleNotifier.h" | 29 #include "core/dom/ContextLifecycleNotifier.h" |
30 | 30 |
31 #include "core/dom/ActiveDOMObject.h" | 31 #include "core/dom/ActiveDOMObject.h" |
32 #include "wtf/TemporaryChange.h" | 32 #include "wtf/TemporaryChange.h" |
33 | 33 |
34 namespace blink { | 34 namespace blink { |
35 | 35 |
36 void ContextLifecycleNotifier::addObserver(ContextLifecycleObserver* observer) | |
37 { | |
38 LifecycleNotifier<ExecutionContext, ContextLifecycleObserver>::addObserver(o
bserver); | |
39 if (observer->observerType() == ContextLifecycleObserver::ActiveDOMObjectTyp
e) | |
40 RELEASE_ASSERT(m_iterating != IteratingOverActiveDOMObjects); | |
41 } | |
42 | |
43 void ContextLifecycleNotifier::notifyResumingActiveDOMObjects() | 36 void ContextLifecycleNotifier::notifyResumingActiveDOMObjects() |
44 { | 37 { |
45 TemporaryChange<IterationType> scope(m_iterating, IteratingOverActiveDOMObje
cts); | 38 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); |
46 Vector<ContextLifecycleObserver*> snapshotOfObservers; | 39 Vector<ContextLifecycleObserver*> snapshotOfObservers; |
47 copyToVector(m_observers, snapshotOfObservers); | 40 copyToVector(m_observers, snapshotOfObservers); |
48 for (ContextLifecycleObserver* observer : snapshotOfObservers) { | 41 for (ContextLifecycleObserver* observer : snapshotOfObservers) { |
49 // FIXME: Oilpan: At the moment, it's possible that a ActiveDOMObject | 42 // FIXME: Oilpan: At the moment, it's possible that a ActiveDOMObject |
50 // observer is destructed while iterating. Once we enable Oilpan by defa
ult | 43 // observer is destructed while iterating. Once we enable Oilpan by defa
ult |
51 // for all LifecycleObserver<T>s, we can remove the hack by making m_obs
ervers | 44 // for all LifecycleObserver<T>s, we can remove the hack by making m_obs
ervers |
52 // a HeapHashSet<WeakMember<LifecycleObserver<T>>>. | 45 // a HeapHashSet<WeakMember<LifecycleObserver<T>>>. |
53 // (i.e., we can just iterate m_observers without taking a snapshot). | 46 // (i.e., we can just iterate m_observers without taking a snapshot). |
54 // For more details, see https://codereview.chromium.org/247253002/. | 47 // For more details, see https://codereview.chromium.org/247253002/. |
55 if (m_observers.contains(observer)) { | 48 if (m_observers.contains(observer)) { |
56 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMO
bjectType) | 49 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMO
bjectType) |
57 continue; | 50 continue; |
58 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs
erver); | 51 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs
erver); |
59 ASSERT(activeDOMObject->executionContext() == context()); | 52 ASSERT(activeDOMObject->executionContext() == context()); |
60 ASSERT(activeDOMObject->suspendIfNeededCalled()); | 53 ASSERT(activeDOMObject->suspendIfNeededCalled()); |
61 activeDOMObject->resume(); | 54 activeDOMObject->resume(); |
62 } | 55 } |
63 } | 56 } |
64 } | 57 } |
65 | 58 |
66 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects() | 59 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects() |
67 { | 60 { |
68 TemporaryChange<IterationType> scope(m_iterating, IteratingOverActiveDOMObje
cts); | 61 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); |
69 Vector<ContextLifecycleObserver*> snapshotOfObservers; | 62 Vector<ContextLifecycleObserver*> snapshotOfObservers; |
70 copyToVector(m_observers, snapshotOfObservers); | 63 copyToVector(m_observers, snapshotOfObservers); |
71 for (ContextLifecycleObserver* observer : snapshotOfObservers) { | 64 for (ContextLifecycleObserver* observer : snapshotOfObservers) { |
72 // It's possible that the ActiveDOMObject is already destructed. | 65 // It's possible that the ActiveDOMObject is already destructed. |
73 // See a FIXME above. | 66 // See a FIXME above. |
74 if (m_observers.contains(observer)) { | 67 if (m_observers.contains(observer)) { |
75 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMO
bjectType) | 68 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMO
bjectType) |
76 continue; | 69 continue; |
77 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs
erver); | 70 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs
erver); |
78 ASSERT(activeDOMObject->executionContext() == context()); | 71 ASSERT(activeDOMObject->executionContext() == context()); |
79 ASSERT(activeDOMObject->suspendIfNeededCalled()); | 72 ASSERT(activeDOMObject->suspendIfNeededCalled()); |
80 activeDOMObject->suspend(); | 73 activeDOMObject->suspend(); |
81 } | 74 } |
82 } | 75 } |
83 } | 76 } |
84 | 77 |
85 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() | 78 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() |
86 { | 79 { |
87 TemporaryChange<IterationType> scope(m_iterating, IteratingOverActiveDOMObje
cts); | 80 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); |
88 Vector<ContextLifecycleObserver*> snapshotOfObservers; | 81 Vector<ContextLifecycleObserver*> snapshotOfObservers; |
89 copyToVector(m_observers, snapshotOfObservers); | 82 copyToVector(m_observers, snapshotOfObservers); |
90 for (ContextLifecycleObserver* observer : snapshotOfObservers) { | 83 for (ContextLifecycleObserver* observer : snapshotOfObservers) { |
91 // It's possible that the ActiveDOMObject is already destructed. | 84 // It's possible that the ActiveDOMObject is already destructed. |
92 // See a FIXME above. | 85 // See a FIXME above. |
93 if (m_observers.contains(observer)) { | 86 if (m_observers.contains(observer)) { |
94 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMO
bjectType) | 87 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMO
bjectType) |
95 continue; | 88 continue; |
96 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs
erver); | 89 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs
erver); |
97 ASSERT(activeDOMObject->executionContext() == context()); | 90 ASSERT(activeDOMObject->executionContext() == context()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 continue; | 125 continue; |
133 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observe
r); | 126 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observe
r); |
134 if (activeDOMObject == object) | 127 if (activeDOMObject == object) |
135 return true; | 128 return true; |
136 } | 129 } |
137 return false; | 130 return false; |
138 } | 131 } |
139 #endif | 132 #endif |
140 | 133 |
141 } // namespace blink | 134 } // namespace blink |
OLD | NEW |