| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 DOMWindowLifecycleObserverType | 49 DOMWindowLifecycleObserverType |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 explicit LifecycleObserver(Context* context, Type type = GenericType) | 52 explicit LifecycleObserver(Context* context, Type type = GenericType) |
| 53 : m_lifecycleContext(nullptr) | 53 : m_lifecycleContext(nullptr) |
| 54 , m_observerType(type) | 54 , m_observerType(type) |
| 55 { | 55 { |
| 56 #if ENABLE(OILPAN) | 56 #if ENABLE(OILPAN) |
| 57 ThreadState::current()->registerPreFinalizer(*this); | 57 ThreadState::current()->registerPreFinalizer(*this); |
| 58 #endif | 58 #endif |
| 59 setContext(context); | 59 observeContext(context); |
| 60 } | 60 } |
| 61 virtual ~LifecycleObserver() | 61 virtual ~LifecycleObserver() |
| 62 { | 62 { |
| 63 #if !ENABLE(OILPAN) | 63 #if !ENABLE(OILPAN) |
| 64 dispose(); | 64 dispose(); |
| 65 #endif | 65 #endif |
| 66 } | 66 } |
| 67 | 67 |
| 68 virtual void trace(Visitor* visitor) | 68 virtual void trace(Visitor* visitor) |
| 69 { | 69 { |
| 70 visitor->trace(m_lifecycleContext); | 70 visitor->trace(m_lifecycleContext); |
| 71 } | 71 } |
| 72 virtual void contextDestroyed() { } | 72 virtual void contextDestroyed() { } |
| 73 void dispose() | 73 void dispose() |
| 74 { | 74 { |
| 75 setContext(nullptr); | 75 observeContext(nullptr); |
| 76 } | 76 } |
| 77 | 77 |
| 78 Context* lifecycleContext() const { return m_lifecycleContext; } | 78 Context* lifecycleContext() const { return m_lifecycleContext; } |
| 79 void clearLifecycleContext() { m_lifecycleContext = nullptr; } | 79 void clearLifecycleContext() { m_lifecycleContext = nullptr; } |
| 80 Type observerType() const { return m_observerType; } | 80 Type observerType() const { return m_observerType; } |
| 81 | 81 |
| 82 protected: | 82 protected: |
| 83 void setContext(Context*); | 83 void observeContext(Context*); |
| 84 | 84 |
| 85 RawPtrWillBeWeakMember<Context> m_lifecycleContext; | 85 RawPtrWillBeWeakMember<Context> m_lifecycleContext; |
| 86 Type m_observerType; | 86 Type m_observerType; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 // | 89 // |
| 90 // These functions should be specialized for each LifecycleObserver instances. | 90 // These functions should be specialized for each LifecycleObserver instances. |
| 91 // | 91 // |
| 92 template<typename T> void observeContext(T*, LifecycleObserver<T>*) { ASSERT_NOT
_REACHED(); } | 92 template<typename T> void observerContext(T*, LifecycleObserver<T>*) { ASSERT_NO
T_REACHED(); } |
| 93 template<typename T> void unobserveContext(T*, LifecycleObserver<T>*) { ASSERT_N
OT_REACHED(); } | 93 template<typename T> void unobserverContext(T*, LifecycleObserver<T>*) { ASSERT_
NOT_REACHED(); } |
| 94 | 94 |
| 95 | 95 |
| 96 template<typename T> | 96 template<typename T> |
| 97 inline void LifecycleObserver<T>::setContext(typename LifecycleObserver<T>::Cont
ext* context) | 97 inline void LifecycleObserver<T>::observeContext(typename LifecycleObserver<T>::
Context* context) |
| 98 { | 98 { |
| 99 if (m_lifecycleContext) | 99 if (m_lifecycleContext) |
| 100 unobserveContext(m_lifecycleContext.get(), this); | 100 unobserverContext(m_lifecycleContext.get(), this); |
| 101 | 101 |
| 102 m_lifecycleContext = context; | 102 m_lifecycleContext = context; |
| 103 | 103 |
| 104 if (m_lifecycleContext) | 104 if (m_lifecycleContext) |
| 105 observeContext(m_lifecycleContext.get(), this); | 105 observerContext(m_lifecycleContext.get(), this); |
| 106 } | 106 } |
| 107 | 107 |
| 108 } // namespace blink | 108 } // namespace blink |
| 109 | 109 |
| 110 #endif // LifecycleObserver_h | 110 #endif // LifecycleObserver_h |
| OLD | NEW |