| 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 25 matching lines...) Expand all Loading... |
| 36 public: | 36 public: |
| 37 DEFINE_INLINE_VIRTUAL_TRACE() | 37 DEFINE_INLINE_VIRTUAL_TRACE() |
| 38 { | 38 { |
| 39 visitor->trace(m_lifecycleContext); | 39 visitor->trace(m_lifecycleContext); |
| 40 } | 40 } |
| 41 | 41 |
| 42 virtual void contextDestroyed() { } | 42 virtual void contextDestroyed() { } |
| 43 | 43 |
| 44 Context* lifecycleContext() const { return m_lifecycleContext; } | 44 Context* lifecycleContext() const { return m_lifecycleContext; } |
| 45 | 45 |
| 46 void clearContext() |
| 47 { |
| 48 setContext(nullptr); |
| 49 } |
| 50 |
| 46 protected: | 51 protected: |
| 47 explicit LifecycleObserver(Context* context) | 52 explicit LifecycleObserver(Context* context) |
| 48 : m_lifecycleContext(nullptr) | 53 : m_lifecycleContext(nullptr) |
| 49 { | 54 { |
| 50 setContext(context); | 55 setContext(context); |
| 51 } | 56 } |
| 52 | 57 |
| 53 void setContext(Context*); | 58 void setContext(Context*); |
| 54 | 59 |
| 55 void clearContext() | |
| 56 { | |
| 57 setContext(nullptr); | |
| 58 } | |
| 59 | |
| 60 private: | 60 private: |
| 61 WeakMember<Context> m_lifecycleContext; | 61 WeakMember<Context> m_lifecycleContext; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 template<typename Context, typename Observer> | 64 template<typename Context, typename Observer> |
| 65 inline void LifecycleObserver<Context, Observer>::setContext(Context* context) | 65 inline void LifecycleObserver<Context, Observer>::setContext(Context* context) |
| 66 { | 66 { |
| 67 if (m_lifecycleContext) | 67 if (m_lifecycleContext) |
| 68 m_lifecycleContext->removeObserver(static_cast<Observer*>(this)); | 68 m_lifecycleContext->removeObserver(static_cast<Observer*>(this)); |
| 69 | 69 |
| 70 m_lifecycleContext = context; | 70 m_lifecycleContext = context; |
| 71 | 71 |
| 72 if (m_lifecycleContext) | 72 if (m_lifecycleContext) |
| 73 m_lifecycleContext->addObserver(static_cast<Observer*>(this)); | 73 m_lifecycleContext->addObserver(static_cast<Observer*>(this)); |
| 74 } | 74 } |
| 75 | 75 |
| 76 } // namespace blink | 76 } // namespace blink |
| 77 | 77 |
| 78 #endif // LifecycleObserver_h | 78 #endif // LifecycleObserver_h |
| OLD | NEW |