Chromium Code Reviews

Side by Side Diff: trunk/Source/core/fetch/ResourceOwner.h

Issue 283333002: Revert 174019 "Make ScriptLoader into a ResourceOwner" (Closed) Base URL: svn://svn.chromium.org/blink/
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
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 28 matching lines...)
39 template<class R, class C = typename R::ClientType> 39 template<class R, class C = typename R::ClientType>
40 class ResourceOwner : public C { 40 class ResourceOwner : public C {
41 public: 41 public:
42 typedef R ResourceType; 42 typedef R ResourceType;
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 protected: 47 protected:
48 ResourceOwner(); 48 ResourceOwner();
49 ResourceOwner(const ResourceOwner& other) { setResource(other.resource(), ot her.m_subscribing); } 49 ResourceOwner(const ResourceOwner& other) { setResource(other.resource()); }
50 explicit ResourceOwner(const ResourcePtr<ResourceType>&); 50 explicit ResourceOwner(const ResourcePtr<ResourceType>&);
51 51
52 void setResource(const ResourcePtr<ResourceType>&, bool subscribing = true); 52 void setResource(const ResourcePtr<ResourceType>&);
53 void clearResource(); 53 void clearResource();
54 54
55 ResourceOwner& operator=(const ResourceOwner& other); 55 ResourceOwner& operator=(const ResourceOwner& other);
56 56
57 private: 57 private:
58 ResourcePtr<ResourceType> m_resource; 58 ResourcePtr<ResourceType> m_resource;
59 bool m_subscribing;
60 }; 59 };
61 60
62 template<class R, class C> 61 template<class R, class C>
63 inline ResourceOwner<R, C>::ResourceOwner() 62 inline ResourceOwner<R, C>::ResourceOwner()
64 : m_subscribing(false)
65 { 63 {
66 } 64 }
67 65
68 template<class R, class C> 66 template<class R, class C>
69 inline ResourceOwner<R, C>::~ResourceOwner() 67 inline ResourceOwner<R, C>::~ResourceOwner()
70 { 68 {
71 clearResource(); 69 clearResource();
72 } 70 }
73 71
74 template<class R, class C> 72 template<class R, class C>
75 inline ResourceOwner<R, C>::ResourceOwner(const ResourcePtr<R>& resource) 73 inline ResourceOwner<R, C>::ResourceOwner(const ResourcePtr<R>& resource)
76 : m_resource(resource) 74 : m_resource(resource)
77 { 75 {
78 if (m_resource) 76 if (m_resource)
79 m_resource->addClient(this); 77 m_resource->addClient(this);
80 } 78 }
81 79
82 template<class R, class C> 80 template<class R, class C>
83 inline void ResourceOwner<R, C>::setResource(const ResourcePtr<R>& newResource, bool subscribe) 81 inline void ResourceOwner<R, C>::setResource(const ResourcePtr<R>& newResource)
84 { 82 {
85 if (newResource == m_resource) 83 if (newResource == m_resource)
86 return; 84 return;
87 85
88 // Some ResourceClient implementations reenter this so 86 // Some ResourceClient implementations reenter this so
89 // we need to prevent double removal. 87 // we need to prevent double removal.
90 if (ResourcePtr<ResourceType> oldResource = m_resource) { 88 if (ResourcePtr<ResourceType> oldResource = m_resource) {
91 m_resource.clear(); 89 m_resource.clear();
92 if (m_subscribing) 90 oldResource->removeClient(this);
93 oldResource->removeClient(this);
94 } 91 }
95 92
96 if (newResource) { 93 if (newResource) {
97 m_subscribing = subscribe;
98 m_resource = newResource; 94 m_resource = newResource;
99 if (m_subscribing) 95 m_resource->addClient(this);
100 m_resource->addClient(this);
101 } 96 }
102 } 97 }
103 98
104 template<class R, class C> 99 template<class R, class C>
105 inline void ResourceOwner<R, C>::clearResource() 100 inline void ResourceOwner<R, C>::clearResource()
106 { 101 {
107 setResource(0); 102 setResource(0);
108 } 103 }
109 104
110 template<class R, class C> 105 template<class R, class C>
111 inline ResourceOwner<R, C>& ResourceOwner<R, C>::operator=(const ResourceOwner<R , C>& other) 106 inline ResourceOwner<R, C>& ResourceOwner<R, C>::operator=(const ResourceOwner<R , C>& other)
112 { 107 {
113 if (this == &other) 108 if (this == &other)
114 return *this; 109 return *this;
115 setResource(other.resource(), other.m_subscribing); 110 setResource(other.resource());
116 return *this; 111 return *this;
117 } 112 }
118 113
119 } // namespace WebCore 114 } // namespace WebCore
120 115
121 #endif 116 #endif
OLDNEW
« no previous file with comments | « trunk/Source/core/dom/ScriptLoader.cpp ('k') | trunk/Source/core/html/parser/HTMLScriptRunner.h » ('j') | no next file with comments »

Powered by Google App Engine