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

Side by Side Diff: Source/platform/LifecycleObserver.h

Issue 1006253002: Oilpan: have LifetimeNotifier<T> track its observers weakly. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebased Created 5 years, 9 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/platform/LifecycleNotifier.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 16 matching lines...) Expand all
27 #ifndef LifecycleObserver_h 27 #ifndef LifecycleObserver_h
28 #define LifecycleObserver_h 28 #define LifecycleObserver_h
29 29
30 #include "platform/heap/Handle.h" 30 #include "platform/heap/Handle.h"
31 #include "wtf/Assertions.h" 31 #include "wtf/Assertions.h"
32 32
33 namespace blink { 33 namespace blink {
34 34
35 template<typename T, typename Observer, typename Notifier> 35 template<typename T, typename Observer, typename Notifier>
36 class LifecycleObserver : public WillBeGarbageCollectedMixin { 36 class LifecycleObserver : public WillBeGarbageCollectedMixin {
37 // FIXME: Oilpan: Remove the pre-finalizer by moving LifecycleNotifier
38 // to Oilpan's heap and making LifecycleNotifier::m_observers
39 // a hash set of weak members.
40 WILL_BE_USING_PRE_FINALIZER(LifecycleObserver, dispose);
41 public: 37 public:
42 using Context = T; 38 using Context = T;
43 39
44 explicit LifecycleObserver(Context* context) 40 explicit LifecycleObserver(Context* context)
45 : m_lifecycleContext(nullptr) 41 : m_lifecycleContext(nullptr)
46 { 42 {
47 #if ENABLE(OILPAN)
48 ThreadState::current()->registerPreFinalizer(*this);
49 #endif
50 } 43 }
51 44
52 virtual ~LifecycleObserver() 45 virtual ~LifecycleObserver()
53 { 46 {
54 #if !ENABLE(OILPAN) 47 #if !ENABLE(OILPAN)
55 dispose(); 48 dispose();
56 #endif 49 #endif
57 } 50 }
58 51
59 DEFINE_INLINE_VIRTUAL_TRACE() 52 DEFINE_INLINE_VIRTUAL_TRACE()
60 { 53 {
61 visitor->trace(m_lifecycleContext); 54 visitor->trace(m_lifecycleContext);
62 } 55 }
63 virtual void contextDestroyed() { } 56 virtual void contextDestroyed() { }
57
64 void dispose() 58 void dispose()
65 { 59 {
66 setContext(nullptr); 60 setContext(nullptr);
67 } 61 }
68 62
69 Context* lifecycleContext() const { return m_lifecycleContext; } 63 Context* lifecycleContext() const { return m_lifecycleContext; }
70 void clearLifecycleContext() { m_lifecycleContext = nullptr; } 64 void clearLifecycleContext() { m_lifecycleContext = nullptr; }
71 65
72 protected: 66 protected:
73 void setContext(Context*); 67 void setContext(Context*);
(...skipping 10 matching lines...) Expand all
84 78
85 m_lifecycleContext = context; 79 m_lifecycleContext = context;
86 80
87 if (m_lifecycleContext) 81 if (m_lifecycleContext)
88 static_cast<Notifier*>(m_lifecycleContext.get())->addObserver(static_cas t<Observer*>(this)); 82 static_cast<Notifier*>(m_lifecycleContext.get())->addObserver(static_cas t<Observer*>(this));
89 } 83 }
90 84
91 } // namespace blink 85 } // namespace blink
92 86
93 #endif // LifecycleObserver_h 87 #endif // LifecycleObserver_h
OLDNEW
« no previous file with comments | « Source/platform/LifecycleNotifier.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698