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

Side by Side Diff: Source/platform/LifecycleContext.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/core/workers/WorkerGlobalScope.cpp ('k') | Source/platform/LifecycleNotifier.h » ('j') | 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 /* 2 /*
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 26 matching lines...) Expand all
37 namespace blink { 37 namespace blink {
38 38
39 class Visitor; 39 class Visitor;
40 40
41 template <typename T> 41 template <typename T>
42 class LifecycleContext { 42 class LifecycleContext {
43 public: 43 public:
44 typedef LifecycleNotifier<T> Notifier; 44 typedef LifecycleNotifier<T> Notifier;
45 typedef LifecycleObserver<T> Observer; 45 typedef LifecycleObserver<T> Observer;
46 46
47 LifecycleContext() { } 47 LifecycleContext()
48 virtual ~LifecycleContext() { } 48 #if ENABLE(ASSERT)
49 : m_contextDestroyed(false)
50 #endif
51 {
52 }
53 virtual ~LifecycleContext()
54 {
55 ASSERT(m_contextDestroyed);
56 }
49 57
50 virtual bool isContextThread() const { return true; } 58 virtual bool isContextThread() const { return true; }
51 59
52 // Called from the constructor of observers. 60 // Called from the constructor of observers.
53 void wasObservedBy(Observer*); 61 void wasObservedBy(Observer*);
54 62
55 // Called from the destructor of observers. 63 // Called from the destructor of observers.
56 void wasUnobservedBy(Observer*); 64 void wasUnobservedBy(Observer*);
57 65
58 virtual void trace(Visitor*) { } 66 virtual void trace(Visitor*) { }
59 67
60 protected: 68 protected:
61 Notifier& lifecycleNotifier(); 69 Notifier& lifecycleNotifier();
70 void contextDestroyed()
71 {
72 #if ENABLE(ASSERT)
73 ASSERT(!m_contextDestroyed);
74 m_contextDestroyed = true;
75 #endif
76 if (m_lifecycleNotifier)
77 m_lifecycleNotifier->contextDestroyed();
78 }
62 79
63 private: 80 private:
64 PassOwnPtr<Notifier> createLifecycleNotifier(); 81 PassOwnPtr<Notifier> createLifecycleNotifier();
65 82
66 OwnPtr<Notifier> m_lifecycleNotifier; 83 OwnPtr<Notifier> m_lifecycleNotifier;
84 bool m_contextDestroyed;
67 }; 85 };
68 86
69 template<typename T> 87 template<typename T>
70 inline void LifecycleContext<T>::wasObservedBy(typename LifecycleContext<T>::Obs erver* observer) 88 inline void LifecycleContext<T>::wasObservedBy(typename LifecycleContext<T>::Obs erver* observer)
71 { 89 {
72 ASSERT(isContextThread()); 90 ASSERT(isContextThread());
73 lifecycleNotifier().addObserver(observer); 91 lifecycleNotifier().addObserver(observer);
74 } 92 }
75 93
76 template<typename T> 94 template<typename T>
(...skipping 13 matching lines...) Expand all
90 108
91 template<typename T> 109 template<typename T>
92 inline PassOwnPtr<typename LifecycleContext<T>::Notifier> LifecycleContext<T>::c reateLifecycleNotifier() 110 inline PassOwnPtr<typename LifecycleContext<T>::Notifier> LifecycleContext<T>::c reateLifecycleNotifier()
93 { 111 {
94 return LifecycleContext<T>::Notifier::create(static_cast<T*>(this)); 112 return LifecycleContext<T>::Notifier::create(static_cast<T*>(this));
95 } 113 }
96 114
97 } // namespace blink 115 } // namespace blink
98 116
99 #endif // LifecycleContext_h 117 #endif // LifecycleContext_h
OLDNEW
« no previous file with comments | « Source/core/workers/WorkerGlobalScope.cpp ('k') | Source/platform/LifecycleNotifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698