Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * Copyright (C) 2013 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2013 Google Inc. All Rights Reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #ifndef LifecycleNotifier_h | 27 #ifndef LifecycleNotifier_h |
| 28 #define LifecycleNotifier_h | 28 #define LifecycleNotifier_h |
| 29 | 29 |
| 30 #include "platform/heap/Handle.h" | 30 #include "platform/heap/Handle.h" |
| 31 #include "wtf/HashSet.h" | 31 #include "wtf/HashSet.h" |
| 32 #include "wtf/TemporaryChange.h" | 32 #include "wtf/TemporaryChange.h" |
| 33 | 33 |
| 34 namespace blink { | 34 namespace blink { |
| 35 | 35 |
| 36 template<typename T, typename Observer> | 36 template<typename T, typename Observer> |
| 37 class LifecycleNotifier { | 37 class LifecycleNotifier { |
|
haraken
2015/03/16 23:44:22
Just help me understand: Why is it safe to use Wil
sof
2015/03/17 06:24:06
It's kept safe by not handling LifecycleNotifier<>
haraken
2015/03/17 08:29:36
Thanks for the clarification; makes sense.
haraken
2015/03/17 09:15:36
Just to confirm: The reason it's safe not to make
sof
2015/03/17 09:28:06
Yes, coupled with conservative GCs being locked ou
| |
| 38 public: | 38 public: |
| 39 virtual ~LifecycleNotifier(); | 39 virtual ~LifecycleNotifier(); |
| 40 | 40 |
| 41 void addObserver(Observer*); | 41 void addObserver(Observer*); |
| 42 void removeObserver(Observer*); | 42 void removeObserver(Observer*); |
| 43 | 43 |
| 44 // notifyContextDestroyed() should be explicitly dispatched from an | 44 // notifyContextDestroyed() should be explicitly dispatched from an |
| 45 // observed context to notify observers that contextDestroyed(). | 45 // observed context to notify observers that contextDestroyed(). |
| 46 // | 46 // |
| 47 // When contextDestroyed() is called, the observer's lifecycleContext() | 47 // When contextDestroyed() is called, the observer's lifecycleContext() |
| 48 // is still valid and safe to use during the notification. | 48 // is still valid and safe to use during the notification. |
| 49 virtual void notifyContextDestroyed(); | 49 virtual void notifyContextDestroyed(); |
| 50 | 50 |
| 51 DEFINE_INLINE_VIRTUAL_TRACE() { } | 51 DEFINE_INLINE_VIRTUAL_TRACE() |
| 52 { | |
| 53 #if ENABLE(OILPAN) | |
| 54 visitor->trace(m_observers); | |
| 55 #endif | |
| 56 } | |
| 52 | 57 |
| 53 bool isIteratingOverObservers() const { return m_iterating != IteratingNone; } | 58 bool isIteratingOverObservers() const { return m_iterating != IteratingNone; } |
| 54 | 59 |
| 55 protected: | 60 protected: |
| 56 LifecycleNotifier() | 61 LifecycleNotifier() |
| 57 : m_iterating(IteratingNone) | 62 : m_iterating(IteratingNone) |
| 58 , m_didCallContextDestroyed(false) | 63 , m_didCallContextDestroyed(false) |
| 59 { | 64 { |
| 60 } | 65 } |
| 61 | 66 |
| 62 enum IterationType { | 67 enum IterationType { |
| 63 IteratingNone, | 68 IteratingNone, |
| 64 IteratingOverAll, | 69 IteratingOverAll, |
| 65 IteratingOverActiveDOMObjects, | 70 IteratingOverActiveDOMObjects, |
| 66 }; | 71 }; |
| 67 | 72 |
| 68 IterationType m_iterating; | 73 IterationType m_iterating; |
| 69 | 74 |
| 70 protected: | 75 protected: |
| 71 using ObserverSet = HashSet<Observer*>; | 76 using ObserverSet = WillBeHeapHashSet<RawPtrWillBeWeakMember<Observer>>; |
| 72 | 77 |
| 78 // FIXME: Oilpan: make LifecycleNotifier<> a GC mixin, somehow. ExecutionCon text | |
| 79 // is the problematic case, as it would then be a class with two GC mixin | |
| 80 // bases, but cannot itself derive from a GC base class also. | |
|
haraken
2015/03/16 23:44:22
Regarding the diamond inheritance problem, can we
sof
2015/03/17 06:24:06
A big CL; what are you referring to?
haraken
2015/03/17 08:29:36
The public virtual inheritance in Supplementable.h
sof
2015/03/17 08:51:46
Thanks; virtual inheritance brings overhead and co
| |
| 81 GC_PLUGIN_IGNORE("467502") | |
| 73 ObserverSet m_observers; | 82 ObserverSet m_observers; |
| 74 | 83 |
| 75 #if ENABLE(ASSERT) | 84 #if ENABLE(ASSERT) |
| 76 T* context() { return static_cast<T*>(this); } | 85 T* context() { return static_cast<T*>(this); } |
| 77 #endif | 86 #endif |
| 78 | 87 |
| 79 private: | 88 private: |
| 80 bool m_didCallContextDestroyed; | 89 bool m_didCallContextDestroyed; |
| 81 }; | 90 }; |
| 82 | 91 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 | 137 |
| 129 template<typename T, typename Observer> | 138 template<typename T, typename Observer> |
| 130 inline void LifecycleNotifier<T, Observer>::removeObserver(Observer* observer) | 139 inline void LifecycleNotifier<T, Observer>::removeObserver(Observer* observer) |
| 131 { | 140 { |
| 132 m_observers.remove(observer); | 141 m_observers.remove(observer); |
| 133 } | 142 } |
| 134 | 143 |
| 135 } // namespace blink | 144 } // namespace blink |
| 136 | 145 |
| 137 #endif // LifecycleNotifier_h | 146 #endif // LifecycleNotifier_h |
| OLD | NEW |