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

Unified Diff: Source/platform/LifecycleContextTest.cpp

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
Index: Source/platform/LifecycleContextTest.cpp
diff --git a/Source/platform/LifecycleContextTest.cpp b/Source/platform/LifecycleContextTest.cpp
index 15a912c2954d87f3f230a3c3c99116539e0956d4..eae437e48afbd5e7510c266afbf87dc6f9bd9feb 100644
--- a/Source/platform/LifecycleContextTest.cpp
+++ b/Source/platform/LifecycleContextTest.cpp
@@ -34,46 +34,50 @@ using namespace blink;
namespace blink {
-class DummyContext final : public NoBaseWillBeGarbageCollectedFinalized<DummyContext>, public LifecycleNotifier<DummyContext> {
+class TestingObserver;
+
+class DummyContext final : public NoBaseWillBeGarbageCollectedFinalized<DummyContext>, public LifecycleNotifier<DummyContext, TestingObserver> {
public:
DummyContext()
- : LifecycleNotifier<DummyContext>(this)
+ : LifecycleNotifier<DummyContext, TestingObserver>(this)
{
}
- DEFINE_INLINE_TRACE()
+ void addObserver(TestingObserver* observer)
{
- LifecycleNotifier<DummyContext>::trace(visitor);
+ LifecycleNotifier<DummyContext, TestingObserver>::addObserver(observer);
}
-};
-template<> void observeContext(DummyContext* context, LifecycleObserver<DummyContext>* observer)
-{
- context->addObserver(observer);
-}
+ void removeObserver(TestingObserver* observer)
+ {
+ LifecycleNotifier<DummyContext, TestingObserver>::removeObserver(observer);
+ }
-template<> void unobserveContext(DummyContext* context, LifecycleObserver<DummyContext>* observer)
-{
- context->removeObserver(observer);
-}
+ DEFINE_INLINE_TRACE()
+ {
+ LifecycleNotifier<DummyContext, TestingObserver>::trace(visitor);
+ }
+};
-class TestingObserver final : public GarbageCollectedFinalized<TestingObserver>, public LifecycleObserver<DummyContext> {
+class TestingObserver final : public NoBaseWillBeGarbageCollectedFinalized<TestingObserver>, public LifecycleObserver<DummyContext, TestingObserver, DummyContext> {
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(TestingObserver);
public:
explicit TestingObserver(DummyContext* context)
- : LifecycleObserver<DummyContext>(context)
+ : LifecycleObserver<DummyContext, TestingObserver, DummyContext>(context)
, m_contextDestroyedCalled(false)
- { }
+ {
+ setContext(context);
+ }
virtual void contextDestroyed() override
{
- LifecycleObserver<DummyContext>::contextDestroyed();
+ LifecycleObserver<DummyContext, TestingObserver, DummyContext>::contextDestroyed();
m_contextDestroyedCalled = true;
}
DEFINE_INLINE_TRACE()
{
- LifecycleObserver<DummyContext>::trace(visitor);
+ LifecycleObserver<DummyContext, TestingObserver, DummyContext>::trace(visitor);
}
bool m_contextDestroyedCalled;
@@ -84,7 +88,7 @@ public:
TEST(LifecycleContextTest, shouldObserveContextDestroyed)
{
OwnPtrWillBeRawPtr<DummyContext> context = adoptPtrWillBeNoop(new DummyContext());
- Persistent<TestingObserver> observer = new TestingObserver(context.get());
+ OwnPtrWillBePersistent<TestingObserver> observer = adoptPtrWillBeNoop(new TestingObserver(context.get()));
EXPECT_EQ(observer->lifecycleContext(), context.get());
EXPECT_FALSE(observer->m_contextDestroyedCalled);
@@ -98,7 +102,7 @@ TEST(LifecycleContextTest, shouldObserveContextDestroyed)
TEST(LifecycleContextTest, shouldNotObserveContextDestroyedIfUnobserve)
{
OwnPtrWillBeRawPtr<DummyContext> context = adoptPtrWillBeNoop(new DummyContext());
- Persistent<TestingObserver> observer = new TestingObserver(context.get());
+ OwnPtrWillBePersistent<TestingObserver> observer = adoptPtrWillBeNoop(new TestingObserver(context.get()));
observer->unobserve();
context->notifyContextDestroyed();
context = nullptr;

Powered by Google App Engine
This is Rietveld 408576698