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

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

Issue 1160253006: Rename LifecycleObserver<T>::dispose() as clearContext() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rename as clearContext() Created 5 years, 6 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/inspector/AsyncCallTracker.cpp ('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 * 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 22 matching lines...) Expand all
33 namespace blink { 33 namespace blink {
34 34
35 template<typename T, typename Observer, typename Notifier> 35 template<typename T, typename Observer, typename Notifier>
36 class LifecycleObserver : public WillBeGarbageCollectedMixin { 36 class LifecycleObserver : public WillBeGarbageCollectedMixin {
37 public: 37 public:
38 using Context = T; 38 using Context = T;
39 39
40 #if !ENABLE(OILPAN) 40 #if !ENABLE(OILPAN)
41 virtual ~LifecycleObserver() 41 virtual ~LifecycleObserver()
42 { 42 {
43 dispose(); 43 clearContext();
44 } 44 }
45 #endif 45 #endif
46 46
47 EAGERLY_FINALIZE_WILL_BE_REMOVED(); 47 EAGERLY_FINALIZE_WILL_BE_REMOVED();
48 DEFINE_INLINE_VIRTUAL_TRACE() 48 DEFINE_INLINE_VIRTUAL_TRACE()
49 { 49 {
50 visitor->trace(m_lifecycleContext); 50 visitor->trace(m_lifecycleContext);
51 } 51 }
52 52
53 virtual void contextDestroyed() { } 53 virtual void contextDestroyed() { }
54 54
55 void dispose()
56 {
57 setContext(nullptr);
58 }
59
60 Context* lifecycleContext() const { return m_lifecycleContext; } 55 Context* lifecycleContext() const { return m_lifecycleContext; }
61 void clearLifecycleContext() { m_lifecycleContext = nullptr; } 56 void clearLifecycleContext() { m_lifecycleContext = nullptr; }
62 57
63 protected: 58 protected:
64 explicit LifecycleObserver(Context* context) 59 explicit LifecycleObserver(Context* context)
65 : m_lifecycleContext(nullptr) 60 : m_lifecycleContext(nullptr)
66 { 61 {
67 setContext(context); 62 setContext(context);
68 } 63 }
69 64
70 void setContext(Context*); 65 void setContext(Context*);
71 66
67 void clearContext()
68 {
69 setContext(nullptr);
70 }
71
72 private: 72 private:
73 RawPtrWillBeWeakMember<Context> m_lifecycleContext; 73 RawPtrWillBeWeakMember<Context> m_lifecycleContext;
74 }; 74 };
75 75
76 template<typename T, typename Observer, typename Notifier> 76 template<typename T, typename Observer, typename Notifier>
77 inline void LifecycleObserver<T, Observer, Notifier>::setContext(typename Lifecy cleObserver<T, Observer, Notifier>::Context* context) 77 inline void LifecycleObserver<T, Observer, Notifier>::setContext(typename Lifecy cleObserver<T, Observer, Notifier>::Context* context)
78 { 78 {
79 if (m_lifecycleContext) 79 if (m_lifecycleContext)
80 static_cast<Notifier*>(m_lifecycleContext.get())->removeObserver(static_ cast<Observer*>(this)); 80 static_cast<Notifier*>(m_lifecycleContext.get())->removeObserver(static_ cast<Observer*>(this));
81 81
82 m_lifecycleContext = context; 82 m_lifecycleContext = context;
83 83
84 if (m_lifecycleContext) 84 if (m_lifecycleContext)
85 static_cast<Notifier*>(m_lifecycleContext.get())->addObserver(static_cas t<Observer*>(this)); 85 static_cast<Notifier*>(m_lifecycleContext.get())->addObserver(static_cas t<Observer*>(this));
86 } 86 }
87 87
88 } // namespace blink 88 } // namespace blink
89 89
90 #endif // LifecycleObserver_h 90 #endif // LifecycleObserver_h
OLDNEW
« no previous file with comments | « Source/core/inspector/AsyncCallTracker.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698