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

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

Issue 901663005: Revert r189385 "Remove LifecycleContext" and r189391, r189530, r189456 that block it (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 10 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/LifecycleNotifier.h ('k') | Source/platform/blink_platform.gypi » ('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 * 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 DOMWindowLifecycleObserverType 49 DOMWindowLifecycleObserverType
50 }; 50 };
51 51
52 explicit LifecycleObserver(Context* context, Type type = GenericType) 52 explicit LifecycleObserver(Context* context, Type type = GenericType)
53 : m_lifecycleContext(nullptr) 53 : m_lifecycleContext(nullptr)
54 , m_observerType(type) 54 , m_observerType(type)
55 { 55 {
56 #if ENABLE(OILPAN) 56 #if ENABLE(OILPAN)
57 ThreadState::current()->registerPreFinalizer(*this); 57 ThreadState::current()->registerPreFinalizer(*this);
58 #endif 58 #endif
59 setContext(context); 59 observeContext(context);
60 } 60 }
61 virtual ~LifecycleObserver() 61 virtual ~LifecycleObserver()
62 { 62 {
63 #if !ENABLE(OILPAN) 63 #if !ENABLE(OILPAN)
64 dispose(); 64 dispose();
65 #endif 65 #endif
66 } 66 }
67 67
68 virtual void trace(Visitor* visitor) 68 virtual void trace(Visitor* visitor)
69 { 69 {
70 visitor->trace(m_lifecycleContext); 70 visitor->trace(m_lifecycleContext);
71 } 71 }
72 virtual void contextDestroyed() { } 72 virtual void contextDestroyed() { }
73 void dispose() 73 void dispose()
74 { 74 {
75 setContext(nullptr); 75 observeContext(nullptr);
76 } 76 }
77 77
78 Context* lifecycleContext() const { return m_lifecycleContext; } 78 Context* lifecycleContext() const { return m_lifecycleContext; }
79 void clearLifecycleContext() { m_lifecycleContext = nullptr; } 79 void clearLifecycleContext() { m_lifecycleContext = nullptr; }
80 Type observerType() const { return m_observerType; } 80 Type observerType() const { return m_observerType; }
81 81
82 protected: 82 protected:
83 void setContext(Context*); 83 void observeContext(Context*);
84 84
85 RawPtrWillBeWeakMember<Context> m_lifecycleContext; 85 RawPtrWillBeWeakMember<Context> m_lifecycleContext;
86 Type m_observerType; 86 Type m_observerType;
87 }; 87 };
88 88
89 // 89 //
90 // These functions should be specialized for each LifecycleObserver instances. 90 // These functions should be specialized for each LifecycleObserver instances.
91 // 91 //
92 template<typename T> void observeContext(T*, LifecycleObserver<T>*) { ASSERT_NOT _REACHED(); } 92 template<typename T> void observerContext(T*, LifecycleObserver<T>*) { ASSERT_NO T_REACHED(); }
93 template<typename T> void unobserveContext(T*, LifecycleObserver<T>*) { ASSERT_N OT_REACHED(); } 93 template<typename T> void unobserverContext(T*, LifecycleObserver<T>*) { ASSERT_ NOT_REACHED(); }
94 94
95 95
96 template<typename T> 96 template<typename T>
97 inline void LifecycleObserver<T>::setContext(typename LifecycleObserver<T>::Cont ext* context) 97 inline void LifecycleObserver<T>::observeContext(typename LifecycleObserver<T>:: Context* context)
98 { 98 {
99 if (m_lifecycleContext) 99 if (m_lifecycleContext)
100 unobserveContext(m_lifecycleContext.get(), this); 100 unobserverContext(m_lifecycleContext.get(), this);
101 101
102 m_lifecycleContext = context; 102 m_lifecycleContext = context;
103 103
104 if (m_lifecycleContext) 104 if (m_lifecycleContext)
105 observeContext(m_lifecycleContext.get(), this); 105 observerContext(m_lifecycleContext.get(), this);
106 } 106 }
107 107
108 } // namespace blink 108 } // namespace blink
109 109
110 #endif // LifecycleObserver_h 110 #endif // LifecycleObserver_h
OLDNEW
« no previous file with comments | « Source/platform/LifecycleNotifier.h ('k') | Source/platform/blink_platform.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698