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

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

Issue 2637063002: Use MockResource as much as possibler in MemoryCacheCorrectnessTest (Closed)
Patch Set: Created 3 years, 11 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 17 matching lines...) Expand all
28 #include "core/fetch/FetchRequest.h" 28 #include "core/fetch/FetchRequest.h"
29 #include "core/fetch/MemoryCache.h" 29 #include "core/fetch/MemoryCache.h"
30 #include "core/fetch/ResourceClientWalker.h" 30 #include "core/fetch/ResourceClientWalker.h"
31 #include "core/fetch/ResourceFetcher.h" 31 #include "core/fetch/ResourceFetcher.h"
32 #include "core/fetch/ResourceLoader.h" 32 #include "core/fetch/ResourceLoader.h"
33 #include "platform/HTTPNames.h" 33 #include "platform/HTTPNames.h"
34 #include <memory> 34 #include <memory>
35 35
36 namespace blink { 36 namespace blink {
37 37
38 Resource* RawResource::fetchSynchronously(FetchRequest& request, 38 RawResource* RawResource::fetchSynchronously(FetchRequest& request,
39 ResourceFetcher* fetcher) { 39 ResourceFetcher* fetcher) {
40 request.makeSynchronous(); 40 request.makeSynchronous();
41 return fetcher->requestResource(request, RawResourceFactory(Resource::Raw)); 41 return toRawResource(
42 fetcher->requestResource(request, RawResourceFactory(Resource::Raw)));
42 } 43 }
43 44
44 RawResource* RawResource::fetchImport(FetchRequest& request, 45 RawResource* RawResource::fetchImport(FetchRequest& request,
45 ResourceFetcher* fetcher) { 46 ResourceFetcher* fetcher) {
46 DCHECK_EQ(request.resourceRequest().frameType(), 47 DCHECK_EQ(request.resourceRequest().frameType(),
47 WebURLRequest::FrameTypeNone); 48 WebURLRequest::FrameTypeNone);
48 request.mutableResourceRequest().setRequestContext( 49 request.mutableResourceRequest().setRequestContext(
49 WebURLRequest::RequestContextImport); 50 WebURLRequest::RequestContextImport);
50 return toRawResource(fetcher->requestResource( 51 return toRawResource(fetcher->requestResource(
51 request, RawResourceFactory(Resource::ImportResource))); 52 request, RawResourceFactory(Resource::ImportResource)));
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 client->responseReceived(this, response(), nullptr); 150 client->responseReceived(this, response(), nullptr);
150 if (!hasClient(c)) 151 if (!hasClient(c))
151 return; 152 return;
152 if (data()) 153 if (data())
153 client->dataReceived(this, data()->data(), data()->size()); 154 client->dataReceived(this, data()->data(), data()->size());
154 if (!hasClient(c)) 155 if (!hasClient(c))
155 return; 156 return;
156 Resource::didAddClient(client); 157 Resource::didAddClient(client);
157 } 158 }
158 159
159 bool RawResource::willFollowRedirect(const ResourceRequest& newRequest,
160 const ResourceResponse& redirectResponse) {
161 bool follow = Resource::willFollowRedirect(newRequest, redirectResponse);
162 // The base class method takes a non const reference of a ResourceRequest
163 // and returns bool just for allowing RawResource to reject redirect. It
164 // must always return true.
165 DCHECK(follow);
166
167 DCHECK(!redirectResponse.isNull());
168 ResourceClientWalker<RawResourceClient> w(clients());
169 while (RawResourceClient* c = w.next()) {
170 if (!c->redirectReceived(this, newRequest, redirectResponse))
171 follow = false;
172 }
173
174 return follow;
175 }
176
177 void RawResource::willNotFollowRedirect() { 160 void RawResource::willNotFollowRedirect() {
178 ResourceClientWalker<RawResourceClient> w(clients()); 161 ResourceClientWalker<RawResourceClient> w(clients());
179 while (RawResourceClient* c = w.next()) 162 while (RawResourceClient* c = w.next())
180 c->redirectBlocked(); 163 c->redirectBlocked();
181 } 164 }
182 165
183 void RawResource::responseReceived( 166 void RawResource::responseReceived(
184 const ResourceResponse& response, 167 const ResourceResponse& response,
185 std::unique_ptr<WebDataConsumerHandle> handle) { 168 std::unique_ptr<WebDataConsumerHandle> handle) {
186 bool isSuccessfulRevalidation = 169 bool isSuccessfulRevalidation =
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 for (const auto& header : oldHeaders) { 273 for (const auto& header : oldHeaders) {
291 AtomicString headerName = header.key; 274 AtomicString headerName = header.key;
292 if (!shouldIgnoreHeaderForCacheReuse(headerName) && 275 if (!shouldIgnoreHeaderForCacheReuse(headerName) &&
293 header.value != newHeaders.get(headerName)) 276 header.value != newHeaders.get(headerName))
294 return false; 277 return false;
295 } 278 }
296 279
297 return true; 280 return true;
298 } 281 }
299 282
283 bool RawResource::willFollowRedirect(const ResourceRequest& newRequest,
hiroshige 2017/01/17 19:28:42 What is the reason for moving this funtion definit
Takashi Toyoshima 2017/01/19 04:08:20 I just prefer to have definitions in the same orde
284 const ResourceResponse& redirectResponse) {
285 bool follow = Resource::willFollowRedirect(newRequest, redirectResponse);
286 // The base class method takes a const reference of a ResourceRequest and
287 // returns bool just for allowing RawResource to reject redirect. It must
288 // always return true.
289 DCHECK(follow);
290
291 DCHECK(!redirectResponse.isNull());
292 ResourceClientWalker<RawResourceClient> w(clients());
293 while (RawResourceClient* c = w.next()) {
294 if (!c->redirectReceived(this, newRequest, redirectResponse))
295 follow = false;
296 }
297
298 return follow;
299 }
300
300 RawResourceClientStateChecker::RawResourceClientStateChecker() 301 RawResourceClientStateChecker::RawResourceClientStateChecker()
301 : m_state(NotAddedAsClient) {} 302 : m_state(NotAddedAsClient) {}
302 303
303 RawResourceClientStateChecker::~RawResourceClientStateChecker() {} 304 RawResourceClientStateChecker::~RawResourceClientStateChecker() {}
304 305
305 NEVER_INLINE void RawResourceClientStateChecker::willAddClient() { 306 NEVER_INLINE void RawResourceClientStateChecker::willAddClient() {
306 SECURITY_CHECK(m_state == NotAddedAsClient); 307 SECURITY_CHECK(m_state == NotAddedAsClient);
307 m_state = Started; 308 m_state = Started;
308 } 309 }
309 310
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 SECURITY_CHECK(m_state != NotAddedAsClient); 355 SECURITY_CHECK(m_state != NotAddedAsClient);
355 SECURITY_CHECK(m_state != NotifyFinished); 356 SECURITY_CHECK(m_state != NotifyFinished);
356 SECURITY_CHECK(resource->errorOccurred() || 357 SECURITY_CHECK(resource->errorOccurred() ||
357 (m_state == ResponseReceived || 358 (m_state == ResponseReceived ||
358 m_state == SetSerializedCachedMetadata || 359 m_state == SetSerializedCachedMetadata ||
359 m_state == DataReceived || m_state == DataDownloaded)); 360 m_state == DataReceived || m_state == DataDownloaded));
360 m_state = NotifyFinished; 361 m_state = NotifyFinished;
361 } 362 }
362 363
363 } // namespace blink 364 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698