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

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

Issue 2014533002: Move FontResourceClient to Oilpan heap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « third_party/WebKit/Source/core/fetch/FontResource.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) 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 14 matching lines...) Expand all
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/Resource.h" 34 #include "core/fetch/Resource.h"
35 #include <type_traits>
35 36
36 namespace blink { 37 namespace blink {
37 38
39 template <typename Client, bool isClientGarbageCollectedMixin>
40 class ResourceOwnerBase;
41
42 template <typename Client>
43 class ResourceOwnerBase<Client, true> : public Client {
44 public:
45 DEFINE_INLINE_VIRTUAL_TRACE()
46 {
47 Client::trace(visitor);
48 }
49 };
50
51 // TODO(yhirano): Remove this template once all ResourceClients become
52 // GarbageCollectedMixin.
53 template <typename Client>
54 class ResourceOwnerBase<Client, false> : public GarbageCollectedMixin, public Cl ient {
55 public:
56 DEFINE_INLINE_VIRTUAL_TRACE() {}
57 };
58
38 template<class R, class C = typename R::ClientType> 59 template<class R, class C = typename R::ClientType>
39 class ResourceOwner : public GarbageCollectedMixin, public C { 60 class ResourceOwner : public ResourceOwnerBase<C, std::is_base_of<GarbageCollect edMixin, C>::value> {
40 USING_PRE_FINALIZER(ResourceOwner, clearResource); 61 USING_PRE_FINALIZER(ResourceOwner, clearResource);
41 public: 62 public:
42 using ResourceType = R; 63 using ResourceType = R;
64 ~ResourceOwner() override {}
65 ResourceType* resource() const { return m_resource; }
43 66
44 virtual ~ResourceOwner(); 67 DEFINE_INLINE_TRACE()
45 ResourceType* resource() const { return m_resource.get(); } 68 {
46 69 visitor->trace(m_resource);
47 DEFINE_INLINE_VIRTUAL_TRACE() { visitor->trace(m_resource); } 70 ResourceOwnerBase<C, std::is_base_of<GarbageCollectedMixin, C>::value>:: trace(visitor);
71 }
48 72
49 protected: 73 protected:
50 ResourceOwner(); 74 ResourceOwner()
75 {
76 ThreadState::current()->registerPreFinalizer(this);
77 }
51 78
52 void setResource(ResourceType*); 79 void setResource(ResourceType*);
53 void clearResource() { setResource(nullptr); } 80 void clearResource() { setResource(nullptr); }
54 81
55 private: 82 private:
56 Member<ResourceType> m_resource; 83 Member<ResourceType> m_resource;
57 }; 84 };
58 85
59 template<class R, class C> 86 template<class R, class C>
60 inline ResourceOwner<R, C>::ResourceOwner()
61 {
62 ThreadState::current()->registerPreFinalizer(this);
63 }
64
65 template<class R, class C>
66 inline ResourceOwner<R, C>::~ResourceOwner()
67 {
68 }
69
70 template<class R, class C>
71 inline void ResourceOwner<R, C>::setResource(R* newResource) 87 inline void ResourceOwner<R, C>::setResource(R* newResource)
72 { 88 {
73 if (newResource == m_resource) 89 if (newResource == m_resource)
74 return; 90 return;
75 91
76 // Some ResourceClient implementations reenter this so 92 // Some ResourceClient implementations reenter this so
77 // we need to prevent double removal. 93 // we need to prevent double removal.
78 if (ResourceType* oldResource = m_resource.release()) 94 if (ResourceType* oldResource = m_resource.release())
79 oldResource->removeClient(this); 95 oldResource->removeClient(this);
80 96
81 if (newResource) { 97 if (newResource) {
82 m_resource = newResource; 98 m_resource = newResource;
83 m_resource->addClient(this); 99 m_resource->addClient(this);
84 } 100 }
85 } 101 }
86 102
87 } // namespace blink 103 } // namespace blink
88 104
89 #endif 105 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/FontResource.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698