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

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

Issue 916033002: Oilpan: Move LifecycleNotifier's hierarchy to Oilpan's heap 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/Supplementable.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 * 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 16 matching lines...) Expand all
27 #ifndef LifecycleObserver_h 27 #ifndef LifecycleObserver_h
28 #define LifecycleObserver_h 28 #define LifecycleObserver_h
29 29
30 #include "platform/heap/Handle.h" 30 #include "platform/heap/Handle.h"
31 #include "wtf/Assertions.h" 31 #include "wtf/Assertions.h"
32 32
33 namespace blink { 33 namespace blink {
34 34
35 template<typename T> 35 template<typename T>
36 class LifecycleObserver : public WillBeGarbageCollectedMixin { 36 class LifecycleObserver : public WillBeGarbageCollectedMixin {
37 // FIXME: Oilpan: Remove the pre-finalizer by moving LifecycleNotifier
38 // to Oilpan's heap and making LifecycleNotifier::m_observers
39 // a hash set of weak members.
40 WILL_BE_USING_PRE_FINALIZER(LifecycleObserver, dispose);
41 public: 37 public:
42 typedef T Context; 38 typedef T Context;
43 39
44 enum Type { 40 enum Type {
45 ActiveDOMObjectType, 41 ActiveDOMObjectType,
46 DocumentLifecycleObserverType, 42 DocumentLifecycleObserverType,
47 GenericType, 43 GenericType,
48 PageLifecycleObserverType, 44 PageLifecycleObserverType,
49 DOMWindowLifecycleObserverType 45 DOMWindowLifecycleObserverType
50 }; 46 };
51 47
52 explicit LifecycleObserver(Context* context, Type type = GenericType) 48 explicit LifecycleObserver(Context* context, Type type = GenericType)
53 : m_lifecycleContext(nullptr) 49 : m_lifecycleContext(nullptr)
54 , m_observerType(type) 50 , m_observerType(type)
55 { 51 {
56 #if ENABLE(OILPAN)
57 ThreadState::current()->registerPreFinalizer(*this);
58 #endif
59 setContext(context); 52 setContext(context);
60 } 53 }
61 virtual ~LifecycleObserver() 54 virtual ~LifecycleObserver()
62 { 55 {
63 #if !ENABLE(OILPAN) 56 #if !ENABLE(OILPAN)
64 dispose(); 57 setContext(nullptr);
65 #endif 58 #endif
66 } 59 }
67 60
68 virtual void trace(Visitor* visitor) 61 virtual void trace(Visitor* visitor)
69 { 62 {
70 visitor->trace(m_lifecycleContext); 63 visitor->trace(m_lifecycleContext);
71 } 64 }
72 virtual void contextDestroyed() { } 65 virtual void contextDestroyed() { }
73 void dispose()
74 {
75 setContext(nullptr);
76 }
77 66
78 Context* lifecycleContext() const { return m_lifecycleContext; } 67 Context* lifecycleContext() const { return m_lifecycleContext; }
79 void clearLifecycleContext() { m_lifecycleContext = nullptr; } 68 void clearLifecycleContext() { m_lifecycleContext = nullptr; }
80 Type observerType() const { return m_observerType; } 69 Type observerType() const { return m_observerType; }
81 70
82 protected: 71 protected:
83 void setContext(Context*); 72 void setContext(Context*);
84 73
85 RawPtrWillBeWeakMember<Context> m_lifecycleContext; 74 RawPtrWillBeWeakMember<Context> m_lifecycleContext;
86 Type m_observerType; 75 Type m_observerType;
(...skipping 14 matching lines...) Expand all
101 90
102 m_lifecycleContext = context; 91 m_lifecycleContext = context;
103 92
104 if (m_lifecycleContext) 93 if (m_lifecycleContext)
105 observeContext(m_lifecycleContext.get(), this); 94 observeContext(m_lifecycleContext.get(), this);
106 } 95 }
107 96
108 } // namespace blink 97 } // namespace blink
109 98
110 #endif // LifecycleObserver_h 99 #endif // LifecycleObserver_h
OLDNEW
« no previous file with comments | « Source/platform/LifecycleNotifier.h ('k') | Source/platform/Supplementable.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698