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

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

Issue 1410313002: Revert of Revalidate using the same Resource, attempt #3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org> 3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org>
4 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 4 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 117
118 void setIdentifier(unsigned long identifier) { m_identifier = identifier; } 118 void setIdentifier(unsigned long identifier) { m_identifier = identifier; }
119 unsigned long identifier() const { return m_identifier; } 119 unsigned long identifier() const { return m_identifier; }
120 120
121 virtual bool shouldIgnoreHTTPStatusCodeErrors() const { return false; } 121 virtual bool shouldIgnoreHTTPStatusCodeErrors() const { return false; }
122 122
123 ResourceRequest& mutableResourceRequest() { return m_resourceRequest; } 123 ResourceRequest& mutableResourceRequest() { return m_resourceRequest; }
124 const ResourceRequest& resourceRequest() const { return m_resourceRequest; } 124 const ResourceRequest& resourceRequest() const { return m_resourceRequest; }
125 const ResourceRequest& lastResourceRequest() const; 125 const ResourceRequest& lastResourceRequest() const;
126 126
127 void setRevalidatingRequest(const ResourceRequest& request) { m_revalidating Request = request; }
128
129 const KURL& url() const { return m_resourceRequest.url();} 127 const KURL& url() const { return m_resourceRequest.url();}
130 Type type() const { return static_cast<Type>(m_type); } 128 Type type() const { return static_cast<Type>(m_type); }
131 const ResourceLoaderOptions& options() const { return m_options; } 129 const ResourceLoaderOptions& options() const { return m_options; }
132 void setOptions(const ResourceLoaderOptions& options) { m_options = options; } 130 void setOptions(const ResourceLoaderOptions& options) { m_options = options; }
133 131
134 void didChangePriority(ResourceLoadPriority, int intraPriorityValue); 132 void didChangePriority(ResourceLoadPriority, int intraPriorityValue);
135 ResourcePriority priorityFromClients(); 133 ResourcePriority priorityFromClients();
136 134
137 void addClient(ResourceClient*); 135 void addClient(ResourceClient*);
138 void removeClient(ResourceClient*); 136 void removeClient(ResourceClient*);
139 bool hasClients() const { return !m_clients.isEmpty() || !m_clientsAwaitingC allback.isEmpty() || !m_finishedClients.isEmpty(); } 137 bool hasClients() const { return !m_clients.isEmpty() || !m_clientsAwaitingC allback.isEmpty(); }
140 bool deleteIfPossible(); 138 bool deleteIfPossible();
141 139
142 enum PreloadResult { 140 enum PreloadResult {
143 PreloadNotReferenced, 141 PreloadNotReferenced,
144 PreloadReferenced, 142 PreloadReferenced,
145 PreloadReferencedWhileLoading, 143 PreloadReferencedWhileLoading,
146 PreloadReferencedWhileComplete 144 PreloadReferencedWhileComplete
147 }; 145 };
148 PreloadResult preloadResult() const { return static_cast<PreloadResult>(m_pr eloadResult); } 146 PreloadResult preloadResult() const { return static_cast<PreloadResult>(m_pr eloadResult); }
149 147
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 bool isPreloaded() const { return m_preloadCount; } 227 bool isPreloaded() const { return m_preloadCount; }
230 void increasePreloadCount() { ++m_preloadCount; } 228 void increasePreloadCount() { ++m_preloadCount; }
231 void decreasePreloadCount() { ASSERT(m_preloadCount); --m_preloadCount; } 229 void decreasePreloadCount() { ASSERT(m_preloadCount); --m_preloadCount; }
232 230
233 void registerHandle(ResourcePtrBase* h); 231 void registerHandle(ResourcePtrBase* h);
234 void unregisterHandle(ResourcePtrBase* h); 232 void unregisterHandle(ResourcePtrBase* h);
235 233
236 bool canReuseRedirectChain(); 234 bool canReuseRedirectChain();
237 bool mustRevalidateDueToCacheHeaders(); 235 bool mustRevalidateDueToCacheHeaders();
238 bool canUseCacheValidator(); 236 bool canUseCacheValidator();
239 bool isCacheValidator() const { return !m_revalidatingRequest.isNull(); } 237 bool isCacheValidator() const { return m_resourceToRevalidate; }
238 Resource* resourceToRevalidate() const { return m_resourceToRevalidate; }
239 void setResourceToRevalidate(Resource*);
240 bool hasCacheControlNoStoreHeader(); 240 bool hasCacheControlNoStoreHeader();
241 bool hasVaryHeader() const; 241 bool hasVaryHeader() const;
242 virtual bool mustRefetchDueToIntegrityMetadata(const FetchRequest& request) const { return false; } 242 virtual bool mustRefetchDueToIntegrityMetadata(const FetchRequest& request) const { return false; }
243 243
244 double currentAge() const; 244 double currentAge() const;
245 double freshnessLifetime(); 245 double freshnessLifetime();
246 double stalenessLifetime(); 246 double stalenessLifetime();
247 247
248 bool isPurgeable() const; 248 bool isPurgeable() const;
249 bool wasPurged() const; 249 bool wasPurged() const;
(...skipping 17 matching lines...) Expand all
267 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK 267 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK
268 void assertAlive() const { RELEASE_ASSERT(!m_deleted); } 268 void assertAlive() const { RELEASE_ASSERT(!m_deleted); }
269 #else 269 #else
270 void assertAlive() const { } 270 void assertAlive() const { }
271 #endif 271 #endif
272 272
273 protected: 273 protected:
274 virtual void checkNotify(); 274 virtual void checkNotify();
275 virtual void finishOnePart(); 275 virtual void finishOnePart();
276 276
277 virtual void destroyDecodedDataForFailedRevalidation() { }
278
279 // Normal resource pointers will silently switch what Resource* they referen ce when we 277 // Normal resource pointers will silently switch what Resource* they referen ce when we
280 // successfully revalidated the resource. We need a way to guarantee that th e Resource 278 // successfully revalidated the resource. We need a way to guarantee that th e Resource
281 // that received the 304 response survives long enough to switch everything over to the 279 // that received the 304 response survives long enough to switch everything over to the
282 // revalidatedresource. The normal mechanisms for keeping a Resource alive e xternally 280 // revalidatedresource. The normal mechanisms for keeping a Resource alive e xternally
283 // (ResourcePtrs and ResourceClients registering themselves) don't work in t his case, so 281 // (ResourcePtrs and ResourceClients registering themselves) don't work in t his case, so
284 // have a separate internal protector). 282 // have a separate internal protector).
285 class InternalResourcePtr { 283 class InternalResourcePtr {
286 public: 284 public:
287 explicit InternalResourcePtr(Resource* resource) 285 explicit InternalResourcePtr(Resource* resource)
288 : m_resource(resource) 286 : m_resource(resource)
(...skipping 10 matching lines...) Expand all
299 Resource* m_resource; 297 Resource* m_resource;
300 }; 298 };
301 299
302 void incrementProtectorCount() { m_protectorCount++; } 300 void incrementProtectorCount() { m_protectorCount++; }
303 void decrementProtectorCount() { m_protectorCount--; } 301 void decrementProtectorCount() { m_protectorCount--; }
304 302
305 void setEncodedSize(size_t); 303 void setEncodedSize(size_t);
306 void setDecodedSize(size_t); 304 void setDecodedSize(size_t);
307 void didAccessDecodedData(); 305 void didAccessDecodedData();
308 306
307 void clearResourceToRevalidate();
308 void updateResponseAfterRevalidation(const ResourceResponse& validatingRespo nse);
309
309 void finishPendingClients(); 310 void finishPendingClients();
310 311
311 HashCountedSet<ResourceClient*> m_clients; 312 HashCountedSet<ResourceClient*> m_clients;
312 HashCountedSet<ResourceClient*> m_clientsAwaitingCallback; 313 HashCountedSet<ResourceClient*> m_clientsAwaitingCallback;
313 HashCountedSet<ResourceClient*> m_finishedClients;
314 314
315 class ResourceCallback : public NoBaseWillBeGarbageCollectedFinalized<Resour ceCallback> { 315 class ResourceCallback : public NoBaseWillBeGarbageCollectedFinalized<Resour ceCallback> {
316 public: 316 public:
317 static ResourceCallback* callbackHandler(); 317 static ResourceCallback* callbackHandler();
318 DECLARE_TRACE(); 318 DECLARE_TRACE();
319 void schedule(Resource*); 319 void schedule(Resource*);
320 void cancel(Resource*); 320 void cancel(Resource*);
321 bool isScheduled(Resource*) const; 321 bool isScheduled(Resource*) const;
322 private: 322 private:
323 ResourceCallback(); 323 ResourceCallback();
324 void runTask(); 324 void runTask();
325 OwnPtr<CancellableTaskFactory> m_callbackTaskFactory; 325 OwnPtr<CancellableTaskFactory> m_callbackTaskFactory;
326 WillBeHeapHashSet<RawPtrWillBeMember<Resource>> m_resourcesWithPendingCl ients; 326 WillBeHeapHashSet<RawPtrWillBeMember<Resource>> m_resourcesWithPendingCl ients;
327 }; 327 };
328 328
329 bool hasClient(ResourceClient* client) { return m_clients.contains(client) | | m_clientsAwaitingCallback.contains(client) || m_finishedClients.contains(clien t); } 329 bool hasClient(ResourceClient* client) { return m_clients.contains(client) | | m_clientsAwaitingCallback.contains(client); }
330 330
331 struct RedirectPair { 331 struct RedirectPair {
332 ALLOW_ONLY_INLINE_ALLOCATION(); 332 ALLOW_ONLY_INLINE_ALLOCATION();
333 public: 333 public:
334 explicit RedirectPair(const ResourceRequest& request, const ResourceResp onse& redirectResponse) 334 explicit RedirectPair(const ResourceRequest& request, const ResourceResp onse& redirectResponse)
335 : m_request(request) 335 : m_request(request)
336 , m_redirectResponse(redirectResponse) 336 , m_redirectResponse(redirectResponse)
337 { 337 {
338 } 338 }
339 339
340 ResourceRequest m_request; 340 ResourceRequest m_request;
341 ResourceResponse m_redirectResponse; 341 ResourceResponse m_redirectResponse;
342 }; 342 };
343 const Vector<RedirectPair>& redirectChain() const { return m_redirectChain; } 343 const Vector<RedirectPair>& redirectChain() const { return m_redirectChain; }
344 344
345 virtual bool isSafeToUnlock() const { return false; } 345 virtual bool isSafeToUnlock() const { return false; }
346 virtual void destroyDecodedDataIfPossible() { } 346 virtual void destroyDecodedDataIfPossible() { }
347 347
348 void markClientsFinished();
349
350 ResourceRequest m_resourceRequest; 348 ResourceRequest m_resourceRequest;
351 ResourceRequest m_revalidatingRequest;
352 AtomicString m_accept; 349 AtomicString m_accept;
353 PersistentWillBeMember<ResourceLoader> m_loader; 350 PersistentWillBeMember<ResourceLoader> m_loader;
354 ResourceLoaderOptions m_options; 351 ResourceLoaderOptions m_options;
355 352
356 ResourceResponse m_response; 353 ResourceResponse m_response;
357 double m_responseTimestamp; 354 double m_responseTimestamp;
358 355
359 RefPtr<SharedBuffer> m_data; 356 RefPtr<SharedBuffer> m_data;
360 Timer<Resource> m_cancelTimer; 357 Timer<Resource> m_cancelTimer;
361 358
362 private: 359 private:
363 class CacheHandler; 360 class CacheHandler;
361 bool addClientToSet(ResourceClient*);
364 void cancelTimerFired(Timer<Resource>*); 362 void cancelTimerFired(Timer<Resource>*);
365 363
366 void switchClientsToRevalidatedResource(); 364 void switchClientsToRevalidatedResource();
367 void revalidationSucceeded(const ResourceResponse&); 365 void revalidationSucceeded(const ResourceResponse&);
368 void revalidationFailed(); 366 void revalidationFailed();
369 367
370 bool unlock(); 368 bool unlock();
371 369
372 bool hasRightHandleCountApartFromCache(unsigned targetCount) const; 370 bool hasRightHandleCountApartFromCache(unsigned targetCount) const;
373 371
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 unsigned m_status : 3; // Status 403 unsigned m_status : 3; // Status
406 404
407 unsigned m_wasPurged : 1; 405 unsigned m_wasPurged : 1;
408 406
409 unsigned m_needsSynchronousCacheHit : 1; 407 unsigned m_needsSynchronousCacheHit : 1;
410 408
411 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK 409 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK
412 bool m_deleted; 410 bool m_deleted;
413 #endif 411 #endif
414 412
413 // If this field is non-null we are using the resource as a proxy for checki ng whether an existing resource is still up to date
414 // using HTTP If-Modified-Since/If-None-Match headers. If the response is 30 4 all clients of this resource are moved
415 // to to be clients of m_resourceToRevalidate and the resource is deleted. I f not, the field is zeroed and this
416 // resources becomes normal resource load.
417 RawPtrWillBeMember<Resource> m_resourceToRevalidate;
418
419 // If this field is non-null, the resource has a proxy for checking whether it is still up to date (see m_resourceToRevalidate).
420 RawPtrWillBeMember<Resource> m_proxyResource;
421
422 // These handles will need to be updated to point to the m_resourceToRevalid ate in case we get 304 response.
423 HashSet<ResourcePtrBase*> m_handlesToRevalidate;
424
415 // Ordered list of all redirects followed while fetching this resource. 425 // Ordered list of all redirects followed while fetching this resource.
416 Vector<RedirectPair> m_redirectChain; 426 Vector<RedirectPair> m_redirectChain;
417 }; 427 };
418 428
419 class ResourceFactory { 429 class ResourceFactory {
420 STACK_ALLOCATED(); 430 STACK_ALLOCATED();
421 public: 431 public:
422 virtual Resource* create(const ResourceRequest&, const String&) const = 0; 432 virtual Resource* create(const ResourceRequest&, const String&) const = 0;
423 Resource::Type type() const { return m_type; } 433 Resource::Type type() const { return m_type; }
424 434
425 protected: 435 protected:
426 ResourceFactory(Resource::Type type) : m_type(type) { } 436 ResourceFactory(Resource::Type type) : m_type(type) { }
427 437
428 Resource::Type m_type; 438 Resource::Type m_type;
429 }; 439 };
430 440
431 #if !LOG_DISABLED 441 #if !LOG_DISABLED
432 // Intended to be used in LOG statements. 442 // Intended to be used in LOG statements.
433 const char* ResourceTypeName(Resource::Type); 443 const char* ResourceTypeName(Resource::Type);
434 #endif 444 #endif
435 445
436 #define DEFINE_RESOURCE_TYPE_CASTS(typeName) \ 446 #define DEFINE_RESOURCE_TYPE_CASTS(typeName) \
437 DEFINE_TYPE_CASTS(typeName##Resource, Resource, resource, resource->type() = = Resource::typeName, resource.type() == Resource::typeName); \ 447 DEFINE_TYPE_CASTS(typeName##Resource, Resource, resource, resource->type() = = Resource::typeName, resource.type() == Resource::typeName); \
438 inline typeName##Resource* to##typeName##Resource(const ResourcePtr<Resource >& ptr) { return to##typeName##Resource(ptr.get()); } 448 inline typeName##Resource* to##typeName##Resource(const ResourcePtr<Resource >& ptr) { return to##typeName##Resource(ptr.get()); }
439 449
440 } 450 }
441 451
442 #endif 452 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/RawResourceTest.cpp ('k') | third_party/WebKit/Source/core/fetch/Resource.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698