| 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 15 matching lines...) Expand all Loading... |
| 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" | 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 GarbageCollectedMixin { |
| 37 public: | 37 public: |
| 38 using Context = T; | 38 using Context = T; |
| 39 | 39 |
| 40 #if !ENABLE(OILPAN) | 40 #if !ENABLE(OILPAN) |
| 41 virtual ~LifecycleObserver() | 41 virtual ~LifecycleObserver() |
| 42 { | 42 { |
| 43 clearContext(); | 43 clearContext(); |
| 44 } | 44 } |
| 45 #endif | 45 #endif |
| 46 | 46 |
| 47 EAGERLY_FINALIZE_WILL_BE_REMOVED(); | |
| 48 DEFINE_INLINE_VIRTUAL_TRACE() | 47 DEFINE_INLINE_VIRTUAL_TRACE() |
| 49 { | 48 { |
| 50 visitor->trace(m_lifecycleContext); | 49 visitor->trace(m_lifecycleContext); |
| 51 } | 50 } |
| 52 | 51 |
| 53 virtual void contextDestroyed() { } | 52 virtual void contextDestroyed() { } |
| 54 | 53 |
| 55 Context* lifecycleContext() const { return m_lifecycleContext; } | 54 Context* lifecycleContext() const { return m_lifecycleContext; } |
| 56 void clearLifecycleContext() { m_lifecycleContext = nullptr; } | 55 void clearLifecycleContext() { m_lifecycleContext = nullptr; } |
| 57 | 56 |
| 58 protected: | 57 protected: |
| 59 explicit LifecycleObserver(Context* context) | 58 explicit LifecycleObserver(Context* context) |
| 60 : m_lifecycleContext(nullptr) | 59 : m_lifecycleContext(nullptr) |
| 61 { | 60 { |
| 62 setContext(context); | 61 setContext(context); |
| 63 } | 62 } |
| 64 | 63 |
| 65 void setContext(Context*); | 64 void setContext(Context*); |
| 66 | 65 |
| 67 void clearContext() | 66 void clearContext() |
| 68 { | 67 { |
| 69 setContext(nullptr); | 68 setContext(nullptr); |
| 70 } | 69 } |
| 71 | 70 |
| 72 private: | 71 private: |
| 73 RawPtrWillBeWeakMember<Context> m_lifecycleContext; | 72 WeakMember<Context> m_lifecycleContext; |
| 74 }; | 73 }; |
| 75 | 74 |
| 76 template<typename T, typename Observer, typename Notifier> | 75 template<typename T, typename Observer, typename Notifier> |
| 77 inline void LifecycleObserver<T, Observer, Notifier>::setContext(typename Lifecy
cleObserver<T, Observer, Notifier>::Context* context) | 76 inline void LifecycleObserver<T, Observer, Notifier>::setContext(typename Lifecy
cleObserver<T, Observer, Notifier>::Context* context) |
| 78 { | 77 { |
| 79 if (m_lifecycleContext) | 78 if (m_lifecycleContext) |
| 80 static_cast<Notifier*>(m_lifecycleContext.get())->removeObserver(static_
cast<Observer*>(this)); | 79 static_cast<Notifier*>(m_lifecycleContext.get())->removeObserver(static_
cast<Observer*>(this)); |
| 81 | 80 |
| 82 m_lifecycleContext = context; | 81 m_lifecycleContext = context; |
| 83 | 82 |
| 84 if (m_lifecycleContext) | 83 if (m_lifecycleContext) |
| 85 static_cast<Notifier*>(m_lifecycleContext.get())->addObserver(static_cas
t<Observer*>(this)); | 84 static_cast<Notifier*>(m_lifecycleContext.get())->addObserver(static_cas
t<Observer*>(this)); |
| 86 } | 85 } |
| 87 | 86 |
| 88 } // namespace blink | 87 } // namespace blink |
| 89 | 88 |
| 90 #endif // LifecycleObserver_h | 89 #endif // LifecycleObserver_h |
| OLD | NEW |