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

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

Issue 288673002: Make ScriptLoader into a ResourceOwner (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 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/core/dom/ScriptLoader.cpp ('k') | Source/core/html/parser/HTMLScriptRunner.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) 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...) Expand all
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()); } 49 ResourceOwner(const ResourceOwner& other) { setResource(other.resource(), ot her.m_subscribing); }
50 explicit ResourceOwner(const ResourcePtr<ResourceType>&); 50 explicit ResourceOwner(const ResourcePtr<ResourceType>&);
51 51
52 void setResource(const ResourcePtr<ResourceType>&); 52 void setResource(const ResourcePtr<ResourceType>&, bool subscribing = true);
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;
59 }; 60 };
60 61
61 template<class R, class C> 62 template<class R, class C>
62 inline ResourceOwner<R, C>::ResourceOwner() 63 inline ResourceOwner<R, C>::ResourceOwner()
64 : m_subscribing(false)
63 { 65 {
64 } 66 }
65 67
66 template<class R, class C> 68 template<class R, class C>
67 inline ResourceOwner<R, C>::~ResourceOwner() 69 inline ResourceOwner<R, C>::~ResourceOwner()
68 { 70 {
69 clearResource(); 71 clearResource();
70 } 72 }
71 73
72 template<class R, class C> 74 template<class R, class C>
73 inline ResourceOwner<R, C>::ResourceOwner(const ResourcePtr<R>& resource) 75 inline ResourceOwner<R, C>::ResourceOwner(const ResourcePtr<R>& resource)
74 : m_resource(resource) 76 : m_resource(resource)
75 { 77 {
76 if (m_resource) 78 if (m_resource)
77 m_resource->addClient(this); 79 m_resource->addClient(this);
78 } 80 }
79 81
80 template<class R, class C> 82 template<class R, class C>
81 inline void ResourceOwner<R, C>::setResource(const ResourcePtr<R>& newResource) 83 inline void ResourceOwner<R, C>::setResource(const ResourcePtr<R>& newResource, bool subscribe)
82 { 84 {
83 if (newResource == m_resource) 85 if (newResource == m_resource)
84 return; 86 return;
85 87
86 // Some ResourceClient implementations reenter this so 88 // Some ResourceClient implementations reenter this so
87 // we need to prevent double removal. 89 // we need to prevent double removal.
88 if (ResourcePtr<ResourceType> oldResource = m_resource) { 90 if (ResourcePtr<ResourceType> oldResource = m_resource) {
89 m_resource.clear(); 91 m_resource.clear();
90 oldResource->removeClient(this); 92 if (m_subscribing)
93 oldResource->removeClient(this);
91 } 94 }
92 95
93 if (newResource) { 96 if (newResource) {
97 m_subscribing = subscribe;
94 m_resource = newResource; 98 m_resource = newResource;
95 m_resource->addClient(this); 99 if (m_subscribing)
100 m_resource->addClient(this);
96 } 101 }
97 } 102 }
98 103
99 template<class R, class C> 104 template<class R, class C>
100 inline void ResourceOwner<R, C>::clearResource() 105 inline void ResourceOwner<R, C>::clearResource()
101 { 106 {
102 setResource(0); 107 setResource(0);
103 } 108 }
104 109
105 template<class R, class C> 110 template<class R, class C>
106 inline ResourceOwner<R, C>& ResourceOwner<R, C>::operator=(const ResourceOwner<R , C>& other) 111 inline ResourceOwner<R, C>& ResourceOwner<R, C>::operator=(const ResourceOwner<R , C>& other)
107 { 112 {
108 if (this == &other) 113 if (this == &other)
109 return *this; 114 return *this;
110 setResource(other.resource()); 115 setResource(other.resource(), other.m_subscribing);
111 return *this; 116 return *this;
112 } 117 }
113 118
114 } // namespace WebCore 119 } // namespace WebCore
115 120
116 #endif 121 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/ScriptLoader.cpp ('k') | Source/core/html/parser/HTMLScriptRunner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698