Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Side by Side Diff: Source/platform/LifecycleNotifier.h

Issue 822863003: LifecycleObserver::contextDestroyed should be explicitly dispatched promptly when a context is dest… (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/platform/LifecycleContext.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 27 matching lines...) Expand all
38 class LifecycleNotifier { 38 class LifecycleNotifier {
39 public: 39 public:
40 typedef LifecycleObserver<T> Observer; 40 typedef LifecycleObserver<T> Observer;
41 typedef T Context; 41 typedef T Context;
42 42
43 static PassOwnPtr<LifecycleNotifier> create(Context* context) 43 static PassOwnPtr<LifecycleNotifier> create(Context* context)
44 { 44 {
45 return adoptPtr(new LifecycleNotifier(context)); 45 return adoptPtr(new LifecycleNotifier(context));
46 } 46 }
47 47
48 virtual ~LifecycleNotifier()
49 {
50 ASSERT(!m_observers.size());
51 }
48 52
49 virtual ~LifecycleNotifier(); 53 void contextDestroyed();
50
51 54
52 // FIXME: this won't need to be virtual anymore. 55 // FIXME: this won't need to be virtual anymore.
53 virtual void addObserver(Observer*); 56 virtual void addObserver(Observer*);
54 virtual void removeObserver(Observer*); 57 virtual void removeObserver(Observer*);
55 58
56 bool isIteratingOverObservers() const { return m_iterating != IteratingNone; } 59 bool isIteratingOverObservers() const { return m_iterating != IteratingNone; }
57 60
58 protected: 61 protected:
59 explicit LifecycleNotifier(Context* context) 62 explicit LifecycleNotifier(Context* context)
60 : m_iterating(IteratingNone) 63 : m_iterating(IteratingNone)
(...skipping 16 matching lines...) Expand all
77 IterationType m_iterating; 80 IterationType m_iterating;
78 81
79 private: 82 private:
80 typedef HashSet<Observer*> ObserverSet; 83 typedef HashSet<Observer*> ObserverSet;
81 84
82 ObserverSet m_observers; 85 ObserverSet m_observers;
83 Context* m_context; 86 Context* m_context;
84 }; 87 };
85 88
86 template<typename T> 89 template<typename T>
87 inline LifecycleNotifier<T>::~LifecycleNotifier() 90 inline void LifecycleNotifier<T>::contextDestroyed()
88 { 91 {
89 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverAll); 92 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverAll);
90 for (typename ObserverSet::iterator it = m_observers.begin(); it != m_observ ers.end(); it = m_observers.begin()) { 93 for (typename ObserverSet::iterator it = m_observers.begin(); it != m_observ ers.end(); it = m_observers.begin()) {
91 Observer* observer = *it; 94 Observer* observer = *it;
92 m_observers.remove(observer); 95 m_observers.remove(observer);
93 ASSERT(observer->lifecycleContext() == m_context); 96 ASSERT(observer->lifecycleContext() == m_context);
94 observer->contextDestroyed(); 97 observer->contextDestroyed();
95 } 98 }
96 } 99 }
97 100
98 template<typename T> 101 template<typename T>
99 inline void LifecycleNotifier<T>::addObserver(typename LifecycleNotifier<T>::Obs erver* observer) 102 inline void LifecycleNotifier<T>::addObserver(typename LifecycleNotifier<T>::Obs erver* observer)
100 { 103 {
101 RELEASE_ASSERT(m_iterating != IteratingOverAll); 104 RELEASE_ASSERT(m_iterating != IteratingOverAll);
102 m_observers.add(observer); 105 m_observers.add(observer);
103 } 106 }
104 107
105 template<typename T> 108 template<typename T>
106 inline void LifecycleNotifier<T>::removeObserver(typename LifecycleNotifier<T>:: Observer* observer) 109 inline void LifecycleNotifier<T>::removeObserver(typename LifecycleNotifier<T>:: Observer* observer)
107 { 110 {
108 RELEASE_ASSERT(m_iterating != IteratingOverAll); 111 RELEASE_ASSERT(m_iterating != IteratingOverAll);
109 m_observers.remove(observer); 112 m_observers.remove(observer);
110 } 113 }
111 114
112 115
113 116
114 } // namespace blink 117 } // namespace blink
115 118
116 #endif // LifecycleNotifier_h 119 #endif // LifecycleNotifier_h
OLDNEW
« no previous file with comments | « Source/platform/LifecycleContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698