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 16 matching lines...) Expand all Loading... |
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 ContextLifecycleNotifier::ContextLifecycleNotifier(ExecutionContext* context) | 36 ContextLifecycleNotifier::ContextLifecycleNotifier(ExecutionContext* context) |
37 : LifecycleNotifier<ExecutionContext>(context) | 37 : LifecycleNotifier<ExecutionContext, ContextLifecycleObserver>(context) |
38 { | 38 { |
39 } | 39 } |
40 | 40 |
41 void ContextLifecycleNotifier::addObserver(ContextLifecycleNotifier::Observer* o
bserver) | 41 void ContextLifecycleNotifier::addObserver(ContextLifecycleObserver* observer) |
42 { | 42 { |
43 LifecycleNotifier<ExecutionContext>::addObserver(observer); | 43 LifecycleNotifier<ExecutionContext, ContextLifecycleObserver>::addObserver(o
bserver); |
44 | 44 if (observer->observerType() == ContextLifecycleObserver::ActiveDOMObjectTyp
e) { |
45 if (observer->observerType() == Observer::ActiveDOMObjectType) { | |
46 RELEASE_ASSERT(m_iterating != IteratingOverActiveDOMObjects); | 45 RELEASE_ASSERT(m_iterating != IteratingOverActiveDOMObjects); |
47 m_activeDOMObjects.add(static_cast<ActiveDOMObject*>(observer)); | 46 m_activeDOMObjects.add(static_cast<ActiveDOMObject*>(observer)); |
48 } | 47 } |
49 } | 48 } |
50 | 49 |
51 void ContextLifecycleNotifier::removeObserver(ContextLifecycleNotifier::Observer
* observer) | 50 void ContextLifecycleNotifier::removeObserver(ContextLifecycleObserver* observer
) |
52 { | 51 { |
53 LifecycleNotifier<ExecutionContext>::removeObserver(observer); | 52 LifecycleNotifier<ExecutionContext, ContextLifecycleObserver>::removeObserve
r(observer); |
54 | 53 if (observer->observerType() == ContextLifecycleObserver::ActiveDOMObjectTyp
e) |
55 if (observer->observerType() == Observer::ActiveDOMObjectType) { | |
56 m_activeDOMObjects.remove(static_cast<ActiveDOMObject*>(observer)); | 54 m_activeDOMObjects.remove(static_cast<ActiveDOMObject*>(observer)); |
57 } | |
58 } | 55 } |
59 | 56 |
60 void ContextLifecycleNotifier::notifyResumingActiveDOMObjects() | 57 void ContextLifecycleNotifier::notifyResumingActiveDOMObjects() |
61 { | 58 { |
62 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD
OMObjects); | 59 TemporaryChange<IterationType> scope(m_iterating, IteratingOverActiveDOMObje
cts); |
63 Vector<ActiveDOMObject*> snapshotOfActiveDOMObjects; | 60 Vector<ActiveDOMObject*> snapshotOfActiveDOMObjects; |
64 copyToVector(m_activeDOMObjects, snapshotOfActiveDOMObjects); | 61 copyToVector(m_activeDOMObjects, snapshotOfActiveDOMObjects); |
65 for (ActiveDOMObject* obj : snapshotOfActiveDOMObjects) { | 62 for (ActiveDOMObject* obj : snapshotOfActiveDOMObjects) { |
66 // FIXME: Oilpan: At the moment, it's possible that the ActiveDOMObject | 63 // FIXME: Oilpan: At the moment, it's possible that the ActiveDOMObject |
67 // is destructed during the iteration. Once we enable Oilpan by default | 64 // is destructed during the iteration. Once we enable Oilpan by default |
68 // for ActiveDOMObjects, we can remove the hack by making | 65 // for ActiveDOMObjects, we can remove the hack by making |
69 // m_activeDOMObjects a HeapHashSet<WeakMember<ActiveDOMObjects>>. | 66 // m_activeDOMObjects a HeapHashSet<WeakMember<ActiveDOMObject>>. |
70 // (i.e., we can just iterate m_activeDOMObjects without taking | 67 // (i.e., we can just iterate m_activeDOMObjects without taking |
71 // a snapshot). | 68 // a snapshot). |
72 // For more details, see https://codereview.chromium.org/247253002/. | 69 // For more details, see https://codereview.chromium.org/247253002/. |
73 if (m_activeDOMObjects.contains(obj)) { | 70 if (m_activeDOMObjects.contains(obj)) { |
74 ASSERT(obj->executionContext() == context()); | 71 ASSERT(obj->executionContext() == context()); |
75 ASSERT(obj->suspendIfNeededCalled()); | 72 ASSERT(obj->suspendIfNeededCalled()); |
76 obj->resume(); | 73 obj->resume(); |
77 } | 74 } |
78 } | 75 } |
79 } | 76 } |
80 | 77 |
81 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects() | 78 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects() |
82 { | 79 { |
83 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD
OMObjects); | 80 TemporaryChange<IterationType> scope(m_iterating, IteratingOverActiveDOMObje
cts); |
84 Vector<ActiveDOMObject*> snapshotOfActiveDOMObjects; | 81 Vector<ActiveDOMObject*> snapshotOfActiveDOMObjects; |
85 copyToVector(m_activeDOMObjects, snapshotOfActiveDOMObjects); | 82 copyToVector(m_activeDOMObjects, snapshotOfActiveDOMObjects); |
86 for (ActiveDOMObject* obj : snapshotOfActiveDOMObjects) { | 83 for (ActiveDOMObject* obj : snapshotOfActiveDOMObjects) { |
87 // It's possible that the ActiveDOMObject is already destructed. | 84 // It's possible that the ActiveDOMObject is already destructed. |
88 // See a FIXME above. | 85 // See a FIXME above. |
89 if (m_activeDOMObjects.contains(obj)) { | 86 if (m_activeDOMObjects.contains(obj)) { |
90 ASSERT(obj->executionContext() == context()); | 87 ASSERT(obj->executionContext() == context()); |
91 ASSERT(obj->suspendIfNeededCalled()); | 88 ASSERT(obj->suspendIfNeededCalled()); |
92 obj->suspend(); | 89 obj->suspend(); |
93 } | 90 } |
94 } | 91 } |
95 } | 92 } |
96 | 93 |
97 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() | 94 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() |
98 { | 95 { |
99 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD
OMObjects); | 96 TemporaryChange<IterationType> scope(m_iterating, IteratingOverActiveDOMObje
cts); |
100 Vector<ActiveDOMObject*> snapshotOfActiveDOMObjects; | 97 Vector<ActiveDOMObject*> snapshotOfActiveDOMObjects; |
101 copyToVector(m_activeDOMObjects, snapshotOfActiveDOMObjects); | 98 copyToVector(m_activeDOMObjects, snapshotOfActiveDOMObjects); |
102 for (ActiveDOMObject* obj : snapshotOfActiveDOMObjects) { | 99 for (ActiveDOMObject* obj : snapshotOfActiveDOMObjects) { |
103 // It's possible that the ActiveDOMObject is already destructed. | 100 // It's possible that the ActiveDOMObject is already destructed. |
104 // See a FIXME above. | 101 // See a FIXME above. |
105 if (m_activeDOMObjects.contains(obj)) { | 102 if (m_activeDOMObjects.contains(obj)) { |
106 ASSERT(obj->executionContext() == context()); | 103 ASSERT(obj->executionContext() == context()); |
107 ASSERT(obj->suspendIfNeededCalled()); | 104 ASSERT(obj->suspendIfNeededCalled()); |
108 obj->stop(); | 105 obj->stop(); |
109 } | 106 } |
110 } | 107 } |
111 } | 108 } |
112 | 109 |
113 bool ContextLifecycleNotifier::hasPendingActivity() const | 110 bool ContextLifecycleNotifier::hasPendingActivity() const |
114 { | 111 { |
115 for (ActiveDOMObject* obj : m_activeDOMObjects) { | 112 for (ActiveDOMObject* obj : m_activeDOMObjects) { |
116 if (obj->hasPendingActivity()) | 113 if (obj->hasPendingActivity()) |
117 return true; | 114 return true; |
118 } | 115 } |
119 return false; | 116 return false; |
120 } | 117 } |
121 | 118 |
122 } // namespace blink | 119 } // namespace blink |
OLD | NEW |