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

Unified Diff: Source/core/dom/ContextLifecycleNotifier.cpp

Issue 18777003: Extract simpler classes for observing context lifecycle and observe Page lifecycle inNavigatorVibra… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebaselined~ Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/ContextLifecycleNotifier.h ('k') | Source/core/dom/ContextLifecycleObserver.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/ContextLifecycleNotifier.cpp
diff --git a/Source/core/dom/ContextLifecycleNotifier.cpp b/Source/core/dom/ContextLifecycleNotifier.cpp
index 6c77804b1dfd7d61e4043a9301e8c0944da9f4e5..f00e4310e16690f7ec10c6f948f60f232134a12b 100644
--- a/Source/core/dom/ContextLifecycleNotifier.cpp
+++ b/Source/core/dom/ContextLifecycleNotifier.cpp
@@ -28,45 +28,37 @@
#include "config.h"
#include "core/dom/ContextLifecycleNotifier.h"
+#include "core/dom/ScriptExecutionContext.h"
#include "wtf/TemporaryChange.h"
namespace WebCore {
ContextLifecycleNotifier::ContextLifecycleNotifier(ScriptExecutionContext* context)
- : m_context(context)
- , m_iterating(IteratingNone)
- , m_inDestructor(false)
+ : LifecycleNotifier(context)
{
}
ContextLifecycleNotifier::~ContextLifecycleNotifier()
{
- m_inDestructor = true;
- for (ContextObserverSet::iterator iter = m_contextObservers.begin(); iter != m_contextObservers.end(); iter = m_contextObservers.begin()) {
- ContextLifecycleObserver* observer = *iter;
- m_contextObservers.remove(observer);
- ASSERT(observer->scriptExecutionContext() == m_context);
- observer->contextDestroyed();
- }
}
-void ContextLifecycleNotifier::addObserver(ContextLifecycleObserver* observer, ContextLifecycleObserver::Type as)
+void ContextLifecycleNotifier::addObserver(LifecycleObserver* observer, LifecycleObserver::Type type)
{
- RELEASE_ASSERT(!m_inDestructor);
+ LifecycleNotifier::addObserver(observer, type);
+
RELEASE_ASSERT(m_iterating != IteratingOverContextObservers);
- m_contextObservers.add(observer);
- if (as == ContextLifecycleObserver::ActiveDOMObjectType) {
+ if (type == LifecycleObserver::ActiveDOMObjectType) {
RELEASE_ASSERT(m_iterating != IteratingOverActiveDOMObjects);
m_activeDOMObjects.add(static_cast<ActiveDOMObject*>(observer));
}
}
-void ContextLifecycleNotifier::removeObserver(ContextLifecycleObserver* observer, ContextLifecycleObserver::Type as)
+void ContextLifecycleNotifier::removeObserver(LifecycleObserver* observer, LifecycleObserver::Type type)
{
- RELEASE_ASSERT(!m_inDestructor);
+ LifecycleNotifier::removeObserver(observer, type);
+
RELEASE_ASSERT(m_iterating != IteratingOverContextObservers);
- m_contextObservers.remove(observer);
- if (as == ContextLifecycleObserver::ActiveDOMObjectType) {
+ if (type == LifecycleObserver::ActiveDOMObjectType) {
RELEASE_ASSERT(m_iterating != IteratingOverActiveDOMObjects);
m_activeDOMObjects.remove(static_cast<ActiveDOMObject*>(observer));
}
@@ -77,7 +69,7 @@ void ContextLifecycleNotifier::notifyResumingActiveDOMObjects()
TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveDOMObjects);
ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end();
for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter != activeObjectsEnd; ++iter) {
- ASSERT((*iter)->scriptExecutionContext() == m_context);
+ ASSERT((*iter)->scriptExecutionContext() == context());
ASSERT((*iter)->suspendIfNeededCalled());
(*iter)->resume();
}
@@ -88,7 +80,7 @@ void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects(ActiveDOMObject:
TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveDOMObjects);
ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end();
for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter != activeObjectsEnd; ++iter) {
- ASSERT((*iter)->scriptExecutionContext() == m_context);
+ ASSERT((*iter)->scriptExecutionContext() == context());
ASSERT((*iter)->suspendIfNeededCalled());
(*iter)->suspend(why);
}
@@ -99,7 +91,7 @@ void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects()
TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveDOMObjects);
ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end();
for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter != activeObjectsEnd; ++iter) {
- ASSERT((*iter)->scriptExecutionContext() == m_context);
+ ASSERT((*iter)->scriptExecutionContext() == context());
ASSERT((*iter)->suspendIfNeededCalled());
(*iter)->stop();
}
@@ -110,7 +102,7 @@ bool ContextLifecycleNotifier::canSuspendActiveDOMObjects()
TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveDOMObjects);
ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end();
for (ActiveDOMObjectSet::const_iterator iter = m_activeDOMObjects.begin(); iter != activeObjectsEnd; ++iter) {
- ASSERT((*iter)->scriptExecutionContext() == m_context);
+ ASSERT((*iter)->scriptExecutionContext() == context());
ASSERT((*iter)->suspendIfNeededCalled());
if (!(*iter)->canSuspend())
return false;
« no previous file with comments | « Source/core/dom/ContextLifecycleNotifier.h ('k') | Source/core/dom/ContextLifecycleObserver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698