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

Side by Side Diff: third_party/WebKit/Source/core/fetch/ResourceOwner.h

Issue 1667843003: Make Resource RefCountedWillBeGarbageCollectedFinalized, attempt #2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + address review comments Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef ResourceOwner_h 31 #ifndef ResourceOwner_h
32 #define ResourceOwner_h 32 #define ResourceOwner_h
33 33
34 #include "core/fetch/ResourcePtr.h" 34 #include "core/fetch/Resource.h"
35 35
36 namespace blink { 36 namespace blink {
37 37
38
39 template<class R, class C = typename R::ClientType> 38 template<class R, class C = typename R::ClientType>
40 class ResourceOwner : public WillBeGarbageCollectedMixin, public C { 39 class ResourceOwner : public WillBeGarbageCollectedMixin, public C {
40 WILL_BE_USING_PRE_FINALIZER(ResourceOwner, clearResource);
41 public: 41 public:
42 using ResourceType = R; 42 using ResourceType = R;
43 43
44 virtual ~ResourceOwner(); 44 virtual ~ResourceOwner();
45 ResourceType* resource() const { return m_resource.get(); } 45 ResourceType* resource() const { return m_resource.get(); }
46 46
47 DEFINE_INLINE_VIRTUAL_TRACE() {} 47 DEFINE_INLINE_VIRTUAL_TRACE() { visitor->trace(m_resource); }
48 48
49 protected: 49 protected:
50 ResourceOwner(); 50 ResourceOwner();
51 51
52 void setResource(const ResourcePtr<ResourceType>&); 52 void setResource(const PassRefPtrWillBeRawPtr<ResourceType>&);
53 void clearResource() { setResource(nullptr); } 53 void clearResource() { setResource(nullptr); }
54 54
55 private: 55 private:
56 ResourcePtr<ResourceType> m_resource; 56 RefPtrWillBeMember<ResourceType> m_resource;
57 }; 57 };
58 58
59 template<class R, class C> 59 template<class R, class C>
60 inline ResourceOwner<R, C>::ResourceOwner() 60 inline ResourceOwner<R, C>::ResourceOwner()
61 { 61 {
62 #if ENABLE(OILPAN)
63 ThreadState::current()->registerPreFinalizer(this);
64 #endif
62 } 65 }
63 66
64 template<class R, class C> 67 template<class R, class C>
65 inline ResourceOwner<R, C>::~ResourceOwner() 68 inline ResourceOwner<R, C>::~ResourceOwner()
66 { 69 {
70 #if !ENABLE(OILPAN)
67 clearResource(); 71 clearResource();
72 #endif
68 } 73 }
69 74
70 template<class R, class C> 75 template<class R, class C>
71 inline void ResourceOwner<R, C>::setResource(const ResourcePtr<R>& newResource) 76 inline void ResourceOwner<R, C>::setResource(const PassRefPtrWillBeRawPtr<R>& ne wResource)
72 { 77 {
73 if (newResource == m_resource) 78 if (newResource == m_resource)
74 return; 79 return;
75 80
76 // Some ResourceClient implementations reenter this so 81 // Some ResourceClient implementations reenter this so
77 // we need to prevent double removal. 82 // we need to prevent double removal.
78 if (ResourcePtr<ResourceType> oldResource = m_resource) { 83 if (RefPtrWillBeRawPtr<ResourceType> oldResource = m_resource.release())
79 m_resource.clear();
80 oldResource->removeClient(this); 84 oldResource->removeClient(this);
81 }
82 85
83 if (newResource) { 86 if (newResource) {
84 m_resource = newResource; 87 m_resource = newResource;
85 m_resource->addClient(this); 88 m_resource->addClient(this);
86 } 89 }
87 } 90 }
88 91
89 } // namespace blink 92 } // namespace blink
90 93
91 #endif 94 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ResourceLoader.cpp ('k') | third_party/WebKit/Source/core/fetch/ResourcePtr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698