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

Side by Side Diff: third_party/WebKit/Source/platform/loader/fetch/RawResource.cpp

Issue 2845513002: [WIP] Add Resource::IsShareable
Patch Set: fix Created 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All Rights Reserved. 2 * Copyright (C) 2011 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 10 matching lines...) Expand all
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "platform/loader/fetch/RawResource.h" 26 #include "platform/loader/fetch/RawResource.h"
27 27
28 #include <memory> 28 #include <memory>
29 #include "platform/HTTPNames.h" 29 #include "platform/HTTPNames.h"
30 #include "platform/loader/fetch/FetchParameters.h" 30 #include "platform/loader/fetch/FetchParameters.h"
31 #include "platform/loader/fetch/MemoryCache.h"
32 #include "platform/loader/fetch/ResourceClientWalker.h" 31 #include "platform/loader/fetch/ResourceClientWalker.h"
33 #include "platform/loader/fetch/ResourceFetcher.h" 32 #include "platform/loader/fetch/ResourceFetcher.h"
34 #include "platform/loader/fetch/ResourceLoader.h" 33 #include "platform/loader/fetch/ResourceLoader.h"
35 34
36 namespace blink { 35 namespace blink {
37 36
38 RawResource* RawResource::FetchSynchronously(FetchParameters& params, 37 RawResource* RawResource::FetchSynchronously(FetchParameters& params,
39 ResourceFetcher* fetcher) { 38 ResourceFetcher* fetcher) {
40 params.MakeSynchronous(); 39 params.MakeSynchronous();
41 return ToRawResource( 40 return ToRawResource(
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 175
177 void RawResource::WillNotFollowRedirect() { 176 void RawResource::WillNotFollowRedirect() {
178 ResourceClientWalker<RawResourceClient> w(Clients()); 177 ResourceClientWalker<RawResourceClient> w(Clients());
179 while (RawResourceClient* c = w.Next()) 178 while (RawResourceClient* c = w.Next())
180 c->RedirectBlocked(); 179 c->RedirectBlocked();
181 } 180 }
182 181
183 void RawResource::ResponseReceived( 182 void RawResource::ResponseReceived(
184 const ResourceResponse& response, 183 const ResourceResponse& response,
185 std::unique_ptr<WebDataConsumerHandle> handle) { 184 std::unique_ptr<WebDataConsumerHandle> handle) {
186 if (response.WasFallbackRequiredByServiceWorker()) {
187 // The ServiceWorker asked us to re-fetch the request. This resource must
188 // not be reused.
189 // Note: This logic is needed here because DocumentThreadableLoader handles
190 // CORS independently from ResourceLoader. Fix it.
191 GetMemoryCache()->Remove(this);
192 }
193
194 bool is_successful_revalidation =
195 IsCacheValidator() && response.HttpStatusCode() == 304;
196 Resource::ResponseReceived(response, nullptr); 185 Resource::ResponseReceived(response, nullptr);
197 186
198 ResourceClientWalker<RawResourceClient> w(Clients()); 187 ResourceClientWalker<RawResourceClient> w(Clients());
199 DCHECK(Clients().size() <= 1 || !handle); 188 DCHECK(Clients().size() <= 1 || !handle);
200 while (RawResourceClient* c = w.Next()) { 189 while (RawResourceClient* c = w.Next()) {
201 // |handle| is cleared when passed, but it's not a problem because |handle| 190 // |handle| is cleared when passed, but it's not a problem because |handle|
202 // is null when there are two or more clients, as asserted. 191 // is null when there are two or more clients, as asserted.
203 c->ResponseReceived(this, this->GetResponse(), std::move(handle)); 192 c->ResponseReceived(this, this->GetResponse(), std::move(handle));
204 } 193 }
205
206 // If we successfully revalidated, we won't get appendData() calls. Forward
207 // the data to clients now instead. Note: |m_data| can be null when no data is
208 // appended to the original resource.
209 if (is_successful_revalidation && Data()) {
210 ResourceClientWalker<RawResourceClient> w(Clients());
211 while (RawResourceClient* c = w.Next())
212 c->DataReceived(this, Data()->Data(), Data()->size());
213 }
214 } 194 }
215 195
216 void RawResource::SetSerializedCachedMetadata(const char* data, size_t size) { 196 void RawResource::SetSerializedCachedMetadata(const char* data, size_t size) {
217 Resource::SetSerializedCachedMetadata(data, size); 197 Resource::SetSerializedCachedMetadata(data, size);
218 ResourceClientWalker<RawResourceClient> w(Clients()); 198 ResourceClientWalker<RawResourceClient> w(Clients());
219 while (RawResourceClient* c = w.Next()) 199 while (RawResourceClient* c = w.Next())
220 c->SetSerializedCachedMetadata(this, data, size); 200 c->SetSerializedCachedMetadata(this, data, size);
221 } 201 }
222 202
223 void RawResource::DidSendData(unsigned long long bytes_sent, 203 void RawResource::DidSendData(unsigned long long bytes_sent,
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 SECURITY_CHECK(state_ != kNotAddedAsClient); 343 SECURITY_CHECK(state_ != kNotAddedAsClient);
364 SECURITY_CHECK(state_ != kNotifyFinished); 344 SECURITY_CHECK(state_ != kNotifyFinished);
365 SECURITY_CHECK(resource->ErrorOccurred() || 345 SECURITY_CHECK(resource->ErrorOccurred() ||
366 (state_ == kResponseReceived || 346 (state_ == kResponseReceived ||
367 state_ == kSetSerializedCachedMetadata || 347 state_ == kSetSerializedCachedMetadata ||
368 state_ == kDataReceived || state_ == kDataDownloaded)); 348 state_ == kDataReceived || state_ == kDataDownloaded));
369 state_ = kNotifyFinished; 349 state_ = kNotifyFinished;
370 } 350 }
371 351
372 } // namespace blink 352 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698