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

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

Issue 2365463004: Revert of Clear LifecycleObserver::m_context when LifecycleObserver::contextDestroyed gets called (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « third_party/WebKit/Source/platform/LifecycleNotifier.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 * 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 25 matching lines...) Expand all
36 public: 36 public:
37 DEFINE_INLINE_VIRTUAL_TRACE() 37 DEFINE_INLINE_VIRTUAL_TRACE()
38 { 38 {
39 visitor->trace(m_lifecycleContext); 39 visitor->trace(m_lifecycleContext);
40 } 40 }
41 41
42 virtual void contextDestroyed() { } 42 virtual void contextDestroyed() { }
43 43
44 Context* lifecycleContext() const { return m_lifecycleContext; } 44 Context* lifecycleContext() const { return m_lifecycleContext; }
45 45
46 void clearContext()
47 {
48 setContext(nullptr);
49 }
50
51 protected: 46 protected:
52 explicit LifecycleObserver(Context* context) 47 explicit LifecycleObserver(Context* context)
53 : m_lifecycleContext(nullptr) 48 : m_lifecycleContext(nullptr)
54 { 49 {
55 setContext(context); 50 setContext(context);
56 } 51 }
57 52
58 void setContext(Context*); 53 void setContext(Context*);
59 54
55 void clearContext()
56 {
57 setContext(nullptr);
58 }
59
60 private: 60 private:
61 WeakMember<Context> m_lifecycleContext; 61 WeakMember<Context> m_lifecycleContext;
62 }; 62 };
63 63
64 template<typename Context, typename Observer> 64 template<typename Context, typename Observer>
65 inline void LifecycleObserver<Context, Observer>::setContext(Context* context) 65 inline void LifecycleObserver<Context, Observer>::setContext(Context* context)
66 { 66 {
67 if (m_lifecycleContext) 67 if (m_lifecycleContext)
68 m_lifecycleContext->removeObserver(static_cast<Observer*>(this)); 68 m_lifecycleContext->removeObserver(static_cast<Observer*>(this));
69 69
70 m_lifecycleContext = context; 70 m_lifecycleContext = context;
71 71
72 if (m_lifecycleContext) 72 if (m_lifecycleContext)
73 m_lifecycleContext->addObserver(static_cast<Observer*>(this)); 73 m_lifecycleContext->addObserver(static_cast<Observer*>(this));
74 } 74 }
75 75
76 } // namespace blink 76 } // namespace blink
77 77
78 #endif // LifecycleObserver_h 78 #endif // LifecycleObserver_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/LifecycleNotifier.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698