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

Unified Diff: Source/platform/LifecycleObserver.h

Issue 968633002: Simplify lifecycle notifiers and observers. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 10 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
« Source/platform/LifecycleNotifier.h ('K') | « Source/platform/LifecycleNotifier.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/LifecycleObserver.h
diff --git a/Source/platform/LifecycleObserver.h b/Source/platform/LifecycleObserver.h
index 43dc6f45d9941f9881682e6bd3f4e9656c62d443..d60981bf8a6d60671462d04f7d587b7af363087e 100644
--- a/Source/platform/LifecycleObserver.h
+++ b/Source/platform/LifecycleObserver.h
@@ -32,32 +32,23 @@
namespace blink {
-template<typename T>
+template<typename T, typename Observer, typename Notifier>
class LifecycleObserver : public WillBeGarbageCollectedMixin {
// FIXME: Oilpan: Remove the pre-finalizer by moving LifecycleNotifier
// to Oilpan's heap and making LifecycleNotifier::m_observers
// a hash set of weak members.
WILL_BE_USING_PRE_FINALIZER(LifecycleObserver, dispose);
public:
- typedef T Context;
+ using Context = T;
- enum Type {
- ActiveDOMObjectType,
- DocumentLifecycleObserverType,
- GenericType,
- PageLifecycleObserverType,
- DOMWindowLifecycleObserverType
- };
-
- explicit LifecycleObserver(Context* context, Type type = GenericType)
+ explicit LifecycleObserver(Context* context)
: m_lifecycleContext(nullptr)
- , m_observerType(type)
{
#if ENABLE(OILPAN)
ThreadState::current()->registerPreFinalizer(*this);
#endif
- setContext(context);
}
+
virtual ~LifecycleObserver()
{
#if !ENABLE(OILPAN)
@@ -77,32 +68,24 @@ public:
Context* lifecycleContext() const { return m_lifecycleContext; }
void clearLifecycleContext() { m_lifecycleContext = nullptr; }
- Type observerType() const { return m_observerType; }
protected:
void setContext(Context*);
+private:
RawPtrWillBeWeakMember<Context> m_lifecycleContext;
- Type m_observerType;
};
-//
-// These functions should be specialized for each LifecycleObserver instances.
-//
-template<typename T> void observeContext(T*, LifecycleObserver<T>*) { ASSERT_NOT_REACHED(); }
-template<typename T> void unobserveContext(T*, LifecycleObserver<T>*) { ASSERT_NOT_REACHED(); }
-
-
-template<typename T>
-inline void LifecycleObserver<T>::setContext(typename LifecycleObserver<T>::Context* context)
+template<typename T, typename Observer, typename Notifier>
+inline void LifecycleObserver<T, Observer, Notifier>::setContext(typename LifecycleObserver<T, Observer, Notifier>::Context* context)
{
if (m_lifecycleContext)
- unobserveContext(m_lifecycleContext.get(), this);
+ static_cast<Notifier*>(m_lifecycleContext.get())->removeObserver(static_cast<Observer*>(this));
m_lifecycleContext = context;
if (m_lifecycleContext)
- observeContext(m_lifecycleContext.get(), this);
+ static_cast<Notifier*>(m_lifecycleContext.get())->addObserver(static_cast<Observer*>(this));
}
} // namespace blink
« Source/platform/LifecycleNotifier.h ('K') | « Source/platform/LifecycleNotifier.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698