| 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 16 matching lines...) Expand all  Loading... | 
| 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  Loading... | 
| 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 | 
| OLD | NEW | 
|---|