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 24 matching lines...) Expand all Loading... |
35 namespace blink { | 35 namespace blink { |
36 | 36 |
37 template<typename T, typename Observer> | 37 template<typename T, typename Observer> |
38 class LifecycleNotifier { | 38 class LifecycleNotifier { |
39 public: | 39 public: |
40 typedef T Context; | 40 typedef T Context; |
41 | 41 |
42 virtual ~LifecycleNotifier(); | 42 virtual ~LifecycleNotifier(); |
43 virtual bool isContextThread() const { return true; } | 43 virtual bool isContextThread() const { return true; } |
44 | 44 |
| 45 void addObserver(Observer*); |
| 46 void removeObserver(Observer*); |
| 47 |
45 // notifyContextDestroyed() should be explicitly dispatched from an | 48 // notifyContextDestroyed() should be explicitly dispatched from an |
46 // observed context to notify observers that contextDestroyed(). | 49 // observed context to notify observers that contextDestroyed(). |
47 // | 50 // |
48 // When contextDestroyed() is called, m_context is still | 51 // When contextDestroyed() is called, m_context is still |
49 // valid and safe to use m_context during the notification. | 52 // valid and safe to use m_context during the notification. |
50 virtual void notifyContextDestroyed(); | 53 virtual void notifyContextDestroyed(); |
51 | 54 |
52 DEFINE_INLINE_VIRTUAL_TRACE() { } | 55 DEFINE_INLINE_VIRTUAL_TRACE() { } |
53 | 56 |
54 bool isIteratingOverObservers() const { return m_iterating != IteratingNone;
} | 57 bool isIteratingOverObservers() const { return m_iterating != IteratingNone;
} |
55 | 58 |
56 protected: | 59 protected: |
57 explicit LifecycleNotifier(Context* context) | 60 explicit LifecycleNotifier(Context* context) |
58 : m_iterating(IteratingNone) | 61 : m_iterating(IteratingNone) |
59 , m_context(context) | 62 , m_context(context) |
60 , m_didCallContextDestroyed(false) | 63 , m_didCallContextDestroyed(false) |
61 { | 64 { |
62 } | 65 } |
63 | 66 |
64 void addObserver(Observer*); | |
65 void removeObserver(Observer*); | |
66 | |
67 Context* context() const { return m_context; } | 67 Context* context() const { return m_context; } |
68 | 68 |
69 enum IterationType { | 69 enum IterationType { |
70 IteratingNone, | 70 IteratingNone, |
71 IteratingOverAll, | 71 IteratingOverAll, |
72 IteratingOverActiveDOMObjects, | 72 IteratingOverActiveDOMObjects, |
73 }; | 73 }; |
74 | 74 |
75 IterationType m_iterating; | 75 IterationType m_iterating; |
76 | 76 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 132 |
133 template<typename T, typename Observer> | 133 template<typename T, typename Observer> |
134 inline void LifecycleNotifier<T, Observer>::removeObserver(Observer* observer) | 134 inline void LifecycleNotifier<T, Observer>::removeObserver(Observer* observer) |
135 { | 135 { |
136 m_observers.remove(observer); | 136 m_observers.remove(observer); |
137 } | 137 } |
138 | 138 |
139 } // namespace blink | 139 } // namespace blink |
140 | 140 |
141 #endif // LifecycleNotifier_h | 141 #endif // LifecycleNotifier_h |
OLD | NEW |