OLD | NEW |
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 10 matching lines...) Expand all Loading... |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 * | 24 * |
25 */ | 25 */ |
26 | 26 |
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" | |
32 | 31 |
33 namespace blink { | 32 namespace blink { |
34 | 33 |
35 template<typename T, typename Observer, typename Notifier> | 34 template<typename T, typename Observer, typename Notifier> |
36 class LifecycleObserver : public GarbageCollectedMixin { | 35 class LifecycleObserver : public GarbageCollectedMixin { |
37 public: | 36 public: |
38 using Context = T; | 37 using Context = T; |
39 | 38 |
40 #if !ENABLE(OILPAN) | |
41 virtual ~LifecycleObserver() | |
42 { | |
43 clearContext(); | |
44 } | |
45 #endif | |
46 | |
47 DEFINE_INLINE_VIRTUAL_TRACE() | 39 DEFINE_INLINE_VIRTUAL_TRACE() |
48 { | 40 { |
49 visitor->trace(m_lifecycleContext); | 41 visitor->trace(m_lifecycleContext); |
50 } | 42 } |
51 | 43 |
52 virtual void contextDestroyed() { } | 44 virtual void contextDestroyed() { } |
53 | 45 |
54 Context* lifecycleContext() const { return m_lifecycleContext; } | 46 Context* lifecycleContext() const { return m_lifecycleContext; } |
55 void clearLifecycleContext() { m_lifecycleContext = nullptr; } | |
56 | 47 |
57 protected: | 48 protected: |
58 explicit LifecycleObserver(Context* context) | 49 explicit LifecycleObserver(Context* context) |
59 : m_lifecycleContext(nullptr) | 50 : m_lifecycleContext(nullptr) |
60 { | 51 { |
61 setContext(context); | 52 setContext(context); |
62 } | 53 } |
63 | 54 |
64 void setContext(Context*); | 55 void setContext(Context*); |
65 | 56 |
(...skipping 14 matching lines...) Expand all Loading... |
80 | 71 |
81 m_lifecycleContext = context; | 72 m_lifecycleContext = context; |
82 | 73 |
83 if (m_lifecycleContext) | 74 if (m_lifecycleContext) |
84 static_cast<Notifier*>(m_lifecycleContext.get())->addObserver(static_cas
t<Observer*>(this)); | 75 static_cast<Notifier*>(m_lifecycleContext.get())->addObserver(static_cas
t<Observer*>(this)); |
85 } | 76 } |
86 | 77 |
87 } // namespace blink | 78 } // namespace blink |
88 | 79 |
89 #endif // LifecycleObserver_h | 80 #endif // LifecycleObserver_h |
OLD | NEW |