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

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

Issue 16988003: Revert "Extract ContextLifecycleNotifier from ScriptExecutionContext." (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 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/Document.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2013 Google Inc. All Rights Reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 */
27
28 #include "config.h"
29 #include "core/dom/ContextLifecycleNotifier.h"
30
31 #include "core/dom/WebCoreMemoryInstrumentation.h"
32 #include "wtf/TemporaryChange.h"
33
34 namespace WebCore {
35
36 ContextLifecycleNotifier::ContextLifecycleNotifier(ScriptExecutionContext* conte xt)
37 : m_context(context)
38 , m_iterating(false)
39 , m_inDestructor(false)
40 {
41 }
42
43 ContextLifecycleNotifier::~ContextLifecycleNotifier()
44 {
45 m_inDestructor = true;
46 for (ContextObserverSet::iterator iter = m_destructionObservers.begin(); ite r != m_destructionObservers.end(); iter = m_destructionObservers.begin()) {
47 ContextDestructionObserver* observer = *iter;
48 m_destructionObservers.remove(observer);
49 ASSERT(observer->scriptExecutionContext() == m_context);
50 observer->contextDestroyed();
51 }
52 }
53
54 void ContextLifecycleNotifier::addObserver(ContextDestructionObserver* observer, ContextDestructionObserver::Type as)
55 {
56 RELEASE_ASSERT(!m_inDestructor);
57 RELEASE_ASSERT(!m_iterating);
58 m_destructionObservers.add(observer);
59 if (as == ContextDestructionObserver::ActiveDOMObjectType)
60 m_activeDOMObjects.add(static_cast<ActiveDOMObject*>(observer));
61 }
62
63 void ContextLifecycleNotifier::removeObserver(ContextDestructionObserver* observ er, ContextDestructionObserver::Type as)
64 {
65 RELEASE_ASSERT(!m_inDestructor);
66 RELEASE_ASSERT(!m_iterating);
67 m_destructionObservers.remove(observer);
68 if (as == ContextDestructionObserver::ActiveDOMObjectType)
69 m_activeDOMObjects.remove(static_cast<ActiveDOMObject*>(observer));
70 }
71
72 void ContextLifecycleNotifier::notifyResumingActiveDOMObjects()
73 {
74 TemporaryChange<bool> scope(this->m_iterating, true);
75 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end();
76 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter != activeObjectsEnd; ++iter) {
77 ASSERT((*iter)->scriptExecutionContext() == m_context);
78 ASSERT((*iter)->suspendIfNeededCalled());
79 (*iter)->resume();
80 }
81 }
82
83 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects(ActiveDOMObject: :ReasonForSuspension why)
84 {
85 TemporaryChange<bool> scope(this->m_iterating, true);
86 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end();
87 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter != activeObjectsEnd; ++iter) {
88 ASSERT((*iter)->scriptExecutionContext() == m_context);
89 ASSERT((*iter)->suspendIfNeededCalled());
90 (*iter)->suspend(why);
91 }
92 }
93
94 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects()
95 {
96 TemporaryChange<bool> scope(this->m_iterating, true);
97 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end();
98 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter != activeObjectsEnd; ++iter) {
99 ASSERT((*iter)->scriptExecutionContext() == m_context);
100 ASSERT((*iter)->suspendIfNeededCalled());
101 (*iter)->stop();
102 }
103 }
104
105 bool ContextLifecycleNotifier::canSuspendActiveDOMObjects()
106 {
107 TemporaryChange<bool> scope(this->m_iterating, true);
108 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end();
109 for (ActiveDOMObjectSet::const_iterator iter = m_activeDOMObjects.begin(); i ter != activeObjectsEnd; ++iter) {
110 ASSERT((*iter)->scriptExecutionContext() == m_context);
111 ASSERT((*iter)->suspendIfNeededCalled());
112 if (!(*iter)->canSuspend())
113 return false;
114 }
115
116 return true;
117 }
118
119 bool ContextLifecycleNotifier::hasPendingActivity() const
120 {
121 ActiveDOMObjectSet::const_iterator activeObjectsEnd = activeDOMObjects().end ();
122 for (ActiveDOMObjectSet::const_iterator iter = activeDOMObjects().begin(); i ter != activeObjectsEnd; ++iter) {
123 if ((*iter)->hasPendingActivity())
124 return true;
125 }
126
127 return false;
128 }
129
130 void ContextLifecycleNotifier::reportMemoryUsage(WTF::MemoryObjectInfo* memoryOb jectInfo) const
131 {
132 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
133 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end();
134 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter != activeObjectsEnd; ++iter)
135 info.addMember(*iter, "activeDOMObject", WTF::RetainingPointer);
136 }
137
138 } // namespace WebCore
139
OLDNEW
« no previous file with comments | « Source/core/dom/ContextLifecycleNotifier.h ('k') | Source/core/dom/Document.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698