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

Side by Side Diff: sky/engine/core/fetch/RawResource.cpp

Issue 1223793006: Delete sky/engine/core/fetch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 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 | « sky/engine/core/fetch/RawResource.h ('k') | sky/engine/core/fetch/Resource.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2011 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
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "sky/engine/core/fetch/RawResource.h"
27
28 #include "sky/engine/core/fetch/ResourceClientWalker.h"
29 #include "sky/engine/core/fetch/ResourceFetcher.h"
30 #include "sky/engine/core/fetch/ResourceLoader.h"
31 #include "sky/engine/platform/SharedBuffer.h"
32
33 namespace blink {
34
35 RawResource::RawResource(const ResourceRequest& resourceRequest, Type type)
36 : Resource(resourceRequest, type)
37 {
38 }
39
40 void RawResource::appendData(const char* data, int length)
41 {
42 Resource::appendData(data, length);
43
44 ResourcePtr<RawResource> protect(this);
45 ResourceClientWalker<RawResourceClient> w(m_clients);
46 while (RawResourceClient* c = w.next())
47 c->dataReceived(this, data, length);
48 }
49
50 void RawResource::didAddClient(ResourceClient* c)
51 {
52 if (!hasClient(c))
53 return;
54 // The calls to the client can result in events running, potentially causing
55 // this resource to be evicted from the cache and all clients to be removed,
56 // so a protector is necessary.
57 ResourcePtr<RawResource> protect(this);
58 RawResourceClient* client = static_cast<RawResourceClient*>(c);
59
60 if (!m_response.isNull())
61 client->responseReceived(this, m_response);
62 if (!hasClient(c))
63 return;
64 if (m_data)
65 client->dataReceived(this, m_data->data(), m_data->size());
66 if (!hasClient(c))
67 return;
68 Resource::didAddClient(client);
69 }
70
71 void RawResource::willSendRequest(ResourceRequest& request, const ResourceRespon se& response)
72 {
73 Resource::willSendRequest(request, response);
74 }
75
76 void RawResource::updateRequest(const ResourceRequest& request)
77 {
78 ResourcePtr<RawResource> protect(this);
79 ResourceClientWalker<RawResourceClient> w(m_clients);
80 while (RawResourceClient* c = w.next())
81 c->updateRequest(this, request);
82 }
83
84 void RawResource::responseReceived(const ResourceResponse& response)
85 {
86 InternalResourcePtr protect(this);
87 Resource::responseReceived(response);
88 ResourceClientWalker<RawResourceClient> w(m_clients);
89 while (RawResourceClient* c = w.next())
90 c->responseReceived(this, m_response);
91 }
92
93 void RawResource::didSendData(unsigned long long bytesSent, unsigned long long t otalBytesToBeSent)
94 {
95 ResourceClientWalker<RawResourceClient> w(m_clients);
96 while (RawResourceClient* c = w.next())
97 c->dataSent(this, bytesSent, totalBytesToBeSent);
98 }
99
100 void RawResource::didDownloadData(int dataLength)
101 {
102 ResourceClientWalker<RawResourceClient> w(m_clients);
103 while (RawResourceClient* c = w.next())
104 c->dataDownloaded(this, dataLength);
105 }
106
107 static bool shouldIgnoreHeaderForCacheReuse(AtomicString headerName)
108 {
109 // FIXME: This list of headers that don't affect cache policy almost certain ly isn't complete.
110 DEFINE_STATIC_LOCAL(HashSet<AtomicString>, m_headers, ());
111 if (m_headers.isEmpty()) {
112 m_headers.add("Cache-Control");
113 m_headers.add("If-Modified-Since");
114 m_headers.add("If-None-Match");
115 m_headers.add("Origin");
116 m_headers.add("Pragma");
117 m_headers.add("Purpose");
118 m_headers.add("Referer");
119 m_headers.add("User-Agent");
120 }
121 return m_headers.contains(headerName);
122 }
123
124 static bool isCacheableHTTPMethod(const AtomicString& method)
125 {
126 // Per http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.10,
127 // these methods always invalidate the cache entry.
128 return method != "POST" && method != "PUT" && method != "DELETE";
129 }
130
131 bool RawResource::canReuse(const ResourceRequest& newRequest) const
132 {
133 if (m_options.dataBufferingPolicy == DoNotBufferData)
134 return false;
135
136 if (!isCacheableHTTPMethod(m_resourceRequest.httpMethod()))
137 return false;
138 if (m_resourceRequest.httpMethod() != newRequest.httpMethod())
139 return false;
140
141 if (m_resourceRequest.httpBody() != newRequest.httpBody())
142 return false;
143
144 if (m_resourceRequest.allowStoredCredentials() != newRequest.allowStoredCred entials())
145 return false;
146
147 // Ensure most headers match the existing headers before continuing.
148 // Note that the list of ignored headers includes some headers explicitly re lated to caching.
149 // A more detailed check of caching policy will be performed later, this is simply a list of
150 // headers that we might permit to be different and still reuse the existing Resource.
151 const HTTPHeaderMap& newHeaders = newRequest.httpHeaderFields();
152 const HTTPHeaderMap& oldHeaders = m_resourceRequest.httpHeaderFields();
153
154 HTTPHeaderMap::const_iterator end = newHeaders.end();
155 for (HTTPHeaderMap::const_iterator i = newHeaders.begin(); i != end; ++i) {
156 AtomicString headerName = i->key;
157 if (!shouldIgnoreHeaderForCacheReuse(headerName) && i->value != oldHeade rs.get(headerName))
158 return false;
159 }
160
161 end = oldHeaders.end();
162 for (HTTPHeaderMap::const_iterator i = oldHeaders.begin(); i != end; ++i) {
163 AtomicString headerName = i->key;
164 if (!shouldIgnoreHeaderForCacheReuse(headerName) && i->value != newHeade rs.get(headerName))
165 return false;
166 }
167
168 return true;
169 }
170
171 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/fetch/RawResource.h ('k') | sky/engine/core/fetch/Resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698