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

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

Issue 2584423002: Loading: move core/fetch to platform/loader/fetch (Closed)
Patch Set: another try Created 3 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
(Empty)
1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
29 */
30
31 #ifndef ResourceOwner_h
32 #define ResourceOwner_h
33
34 #include "core/fetch/Resource.h"
35 #include "platform/heap/Handle.h"
36
37 namespace blink {
38
39 template <class R, class C>
40 class GC_PLUGIN_IGNORE("https://crbug.com/652966") ResourceOwner;
41
42 template <class R, class C = typename R::ClientType>
43 class ResourceOwner : public C {
44 USING_PRE_FINALIZER(ResourceOwner, clearResource);
45
46 public:
47 using ResourceType = R;
48 ~ResourceOwner() override {}
49 ResourceType* resource() const { return m_resource; }
50
51 DEFINE_INLINE_TRACE() {
52 visitor->trace(m_resource);
53 C::trace(visitor);
54 }
55
56 protected:
57 ResourceOwner() {}
58
59 void setResource(
60 ResourceType*,
61 Resource::PreloadReferencePolicy = Resource::MarkAsReferenced);
62 void clearResource() { setResource(nullptr); }
63
64 private:
65 Member<ResourceType> m_resource;
66 };
67
68 template <class R, class C>
69 inline void ResourceOwner<R, C>::setResource(
70 R* newResource,
71 Resource::PreloadReferencePolicy preloadReferencePolicy) {
72 if (newResource == m_resource)
73 return;
74
75 // Some ResourceClient implementations reenter this so
76 // we need to prevent double removal.
77 if (ResourceType* oldResource = m_resource.release())
78 oldResource->removeClient(this);
79
80 if (newResource) {
81 m_resource = newResource;
82 m_resource->addClient(this, preloadReferencePolicy);
83 }
84 }
85
86 } // namespace blink
87
88 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ResourceLoadingLog.h ('k') | third_party/WebKit/Source/core/fetch/ResourceStatus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698