| OLD | NEW |
| 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 18 matching lines...) Expand all Loading... |
| 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 | 35 |
| 36 namespace blink { | 36 namespace blink { |
| 37 | 37 |
| 38 template<class R, class C = typename R::ClientType> | 38 template<class R, class C = typename R::ClientType> |
| 39 class ResourceOwner : public WillBeGarbageCollectedMixin, public C { | 39 class ResourceOwner : public GarbageCollectedMixin, public C { |
| 40 WILL_BE_USING_PRE_FINALIZER(ResourceOwner, clearResource); | 40 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() { visitor->trace(m_resource); } | 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 PassRefPtrWillBeRawPtr<ResourceType>&); | 52 void setResource(const RawPtr<ResourceType>&); |
| 53 void clearResource() { setResource(nullptr); } | 53 void clearResource() { setResource(nullptr); } |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 RefPtrWillBeMember<ResourceType> m_resource; | 56 Member<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) | 62 #if ENABLE(OILPAN) |
| 63 ThreadState::current()->registerPreFinalizer(this); | 63 ThreadState::current()->registerPreFinalizer(this); |
| 64 #endif | 64 #endif |
| 65 } | 65 } |
| 66 | 66 |
| 67 template<class R, class C> | 67 template<class R, class C> |
| 68 inline ResourceOwner<R, C>::~ResourceOwner() | 68 inline ResourceOwner<R, C>::~ResourceOwner() |
| 69 { | 69 { |
| 70 #if !ENABLE(OILPAN) | 70 #if !ENABLE(OILPAN) |
| 71 clearResource(); | 71 clearResource(); |
| 72 #endif | 72 #endif |
| 73 } | 73 } |
| 74 | 74 |
| 75 template<class R, class C> | 75 template<class R, class C> |
| 76 inline void ResourceOwner<R, C>::setResource(const PassRefPtrWillBeRawPtr<R>& ne
wResource) | 76 inline void ResourceOwner<R, C>::setResource(const RawPtr<R>& newResource) |
| 77 { | 77 { |
| 78 if (newResource == m_resource) | 78 if (newResource == m_resource) |
| 79 return; | 79 return; |
| 80 | 80 |
| 81 // Some ResourceClient implementations reenter this so | 81 // Some ResourceClient implementations reenter this so |
| 82 // we need to prevent double removal. | 82 // we need to prevent double removal. |
| 83 if (RefPtrWillBeRawPtr<ResourceType> oldResource = m_resource.release()) | 83 if (RawPtr<ResourceType> oldResource = m_resource.release()) |
| 84 oldResource->removeClient(this); | 84 oldResource->removeClient(this); |
| 85 | 85 |
| 86 if (newResource) { | 86 if (newResource) { |
| 87 m_resource = newResource; | 87 m_resource = newResource; |
| 88 m_resource->addClient(this); | 88 m_resource->addClient(this); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 } // namespace blink | 92 } // namespace blink |
| 93 | 93 |
| 94 #endif | 94 #endif |
| OLD | NEW |