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