OLD | NEW |
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 | 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All |
6 rights reserved. | 6 rights reserved. |
7 | 7 |
8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or |
9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public |
10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either |
(...skipping 30 matching lines...) Expand all Loading... |
41 #include "platform/wtf/Allocator.h" | 41 #include "platform/wtf/Allocator.h" |
42 #include "platform/wtf/AutoReset.h" | 42 #include "platform/wtf/AutoReset.h" |
43 #include "platform/wtf/HashCountedSet.h" | 43 #include "platform/wtf/HashCountedSet.h" |
44 #include "platform/wtf/HashSet.h" | 44 #include "platform/wtf/HashSet.h" |
45 #include "platform/wtf/text/AtomicString.h" | 45 #include "platform/wtf/text/AtomicString.h" |
46 #include "platform/wtf/text/WTFString.h" | 46 #include "platform/wtf/text/WTFString.h" |
47 #include "public/platform/WebDataConsumerHandle.h" | 47 #include "public/platform/WebDataConsumerHandle.h" |
48 | 48 |
49 namespace blink { | 49 namespace blink { |
50 | 50 |
| 51 class FetchContext; |
51 class FetchRequest; | 52 class FetchRequest; |
52 class ResourceClient; | 53 class ResourceClient; |
53 class ResourceFetcher; | 54 class ResourceFetcher; |
54 class ResourceTimingInfo; | 55 class ResourceTimingInfo; |
55 class ResourceLoader; | 56 class ResourceLoader; |
56 class SecurityOrigin; | 57 class SecurityOrigin; |
57 | 58 |
58 // A resource that is held in the cache. Classes who want to use this object | 59 // A resource that is held in the cache. Classes who want to use this object |
59 // should derive from ResourceClient, to get the function calls in case the | 60 // should derive from ResourceClient, to get the function calls in case the |
60 // requested data has arrived. This class also does the actual communication | 61 // requested data has arrived. This class also does the actual communication |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 MarkAsReferenced, | 93 MarkAsReferenced, |
93 DontMarkAsReferenced, | 94 DontMarkAsReferenced, |
94 }; | 95 }; |
95 | 96 |
96 // Used by reloadIfLoFiOrPlaceholderImage(). | 97 // Used by reloadIfLoFiOrPlaceholderImage(). |
97 enum ReloadLoFiOrPlaceholderPolicy { | 98 enum ReloadLoFiOrPlaceholderPolicy { |
98 kReloadIfNeeded, | 99 kReloadIfNeeded, |
99 kReloadAlways, | 100 kReloadAlways, |
100 }; | 101 }; |
101 | 102 |
| 103 class ResourceCallback { |
| 104 public: |
| 105 virtual ~ResourceCallback() {} |
| 106 virtual void schedule(Resource*) = 0; |
| 107 virtual void cancel(Resource*) = 0; |
| 108 virtual bool isScheduled(Resource*) const = 0; |
| 109 }; |
| 110 |
102 virtual ~Resource(); | 111 virtual ~Resource(); |
103 | 112 |
104 DECLARE_VIRTUAL_TRACE(); | 113 DECLARE_VIRTUAL_TRACE(); |
105 | 114 |
106 virtual void setEncoding(const String&) {} | 115 virtual void setEncoding(const String&) {} |
107 virtual String encoding() const { return String(); } | 116 virtual String encoding() const { return String(); } |
108 virtual void appendData(const char*, size_t); | 117 virtual void appendData(const char*, size_t); |
109 virtual void error(const ResourceError&); | 118 virtual void error(const ResourceError&); |
110 virtual void setCORSFailed() {} | 119 virtual void setCORSFailed() {} |
111 | 120 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 // If this Resource is ImageResource and has the Lo-Fi response headers or is | 339 // If this Resource is ImageResource and has the Lo-Fi response headers or is |
331 // a placeholder, reload the full original image with the Lo-Fi state set to | 340 // a placeholder, reload the full original image with the Lo-Fi state set to |
332 // off and optionally bypassing the cache. | 341 // off and optionally bypassing the cache. |
333 virtual void reloadIfLoFiOrPlaceholderImage(ResourceFetcher*, | 342 virtual void reloadIfLoFiOrPlaceholderImage(ResourceFetcher*, |
334 ReloadLoFiOrPlaceholderPolicy) {} | 343 ReloadLoFiOrPlaceholderPolicy) {} |
335 | 344 |
336 static const char* resourceTypeToString( | 345 static const char* resourceTypeToString( |
337 Type, | 346 Type, |
338 const AtomicString& fetchInitiatorName); | 347 const AtomicString& fetchInitiatorName); |
339 | 348 |
| 349 void finishPendingClients(); |
| 350 |
340 protected: | 351 protected: |
341 Resource(const ResourceRequest&, Type, const ResourceLoaderOptions&); | 352 Resource(const ResourceRequest&, |
| 353 Type, |
| 354 const ResourceLoaderOptions&, |
| 355 FetchContext* = nullptr); |
342 | 356 |
343 virtual void checkNotify(); | 357 virtual void checkNotify(); |
344 | 358 |
345 void markClientFinished(ResourceClient*); | 359 void markClientFinished(ResourceClient*); |
346 | 360 |
347 virtual bool hasClientsOrObservers() const { | 361 virtual bool hasClientsOrObservers() const { |
348 return !m_clients.isEmpty() || !m_clientsAwaitingCallback.isEmpty() || | 362 return !m_clients.isEmpty() || !m_clientsAwaitingCallback.isEmpty() || |
349 !m_finishedClients.isEmpty(); | 363 !m_finishedClients.isEmpty(); |
350 } | 364 } |
351 virtual void destroyDecodedDataForFailedRevalidation() {} | 365 virtual void destroyDecodedDataForFailedRevalidation() {} |
352 | 366 |
353 void setEncodedSize(size_t); | 367 void setEncodedSize(size_t); |
354 void setDecodedSize(size_t); | 368 void setDecodedSize(size_t); |
355 | 369 |
356 void finishPendingClients(); | |
357 | |
358 virtual void didAddClient(ResourceClient*); | 370 virtual void didAddClient(ResourceClient*); |
359 void willAddClientOrObserver(PreloadReferencePolicy); | 371 void willAddClientOrObserver(PreloadReferencePolicy); |
360 | 372 |
361 void didRemoveClientOrObserver(); | 373 void didRemoveClientOrObserver(); |
362 virtual void allClientsAndObserversRemoved(); | 374 virtual void allClientsAndObserversRemoved(); |
363 | 375 |
364 bool hasClient(ResourceClient* client) const { | 376 bool hasClient(ResourceClient* client) const { |
365 return m_clients.contains(client) || | 377 return m_clients.contains(client) || |
366 m_clientsAwaitingCallback.contains(client) || | 378 m_clientsAwaitingCallback.contains(client) || |
367 m_finishedClients.contains(client); | 379 m_finishedClients.contains(client); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 : AutoReset(&resource->m_isAddRemoveClientProhibited, true) {} | 414 : AutoReset(&resource->m_isAddRemoveClientProhibited, true) {} |
403 }; | 415 }; |
404 | 416 |
405 class RevalidationStartForbiddenScope : public AutoReset<bool> { | 417 class RevalidationStartForbiddenScope : public AutoReset<bool> { |
406 public: | 418 public: |
407 RevalidationStartForbiddenScope(Resource* resource) | 419 RevalidationStartForbiddenScope(Resource* resource) |
408 : AutoReset(&resource->m_isRevalidationStartForbidden, true) {} | 420 : AutoReset(&resource->m_isRevalidationStartForbidden, true) {} |
409 }; | 421 }; |
410 | 422 |
411 private: | 423 private: |
412 class ResourceCallback; | |
413 class CachedMetadataHandlerImpl; | 424 class CachedMetadataHandlerImpl; |
414 class ServiceWorkerResponseCachedMetadataHandler; | 425 class ServiceWorkerResponseCachedMetadataHandler; |
415 | 426 |
416 void cancelTimerFired(TimerBase*); | 427 void cancelTimerFired(TimerBase*); |
417 | 428 |
418 void revalidationSucceeded(const ResourceResponse&); | 429 void revalidationSucceeded(const ResourceResponse&); |
419 void revalidationFailed(); | 430 void revalidationFailed(); |
420 | 431 |
421 size_t calculateOverheadSize() const; | 432 size_t calculateOverheadSize() const; |
422 | 433 |
423 String reasonNotDeletable() const; | 434 String reasonNotDeletable() const; |
424 | 435 |
| 436 ResourceCallback& resourceCallback(); |
| 437 |
425 // MemoryCoordinatorClient overrides: | 438 // MemoryCoordinatorClient overrides: |
426 void onPurgeMemory() override; | 439 void onPurgeMemory() override; |
427 | 440 |
428 Member<CachedMetadataHandlerImpl> m_cacheHandler; | 441 Member<CachedMetadataHandlerImpl> m_cacheHandler; |
429 RefPtr<SecurityOrigin> m_fetcherSecurityOrigin; | 442 RefPtr<SecurityOrigin> m_fetcherSecurityOrigin; |
430 | 443 |
431 ResourceError m_error; | 444 ResourceError m_error; |
432 | 445 |
433 double m_loadFinishTime; | 446 double m_loadFinishTime; |
434 | 447 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 | 482 |
470 HeapHashCountedSet<WeakMember<ResourceClient>> m_clients; | 483 HeapHashCountedSet<WeakMember<ResourceClient>> m_clients; |
471 HeapHashCountedSet<WeakMember<ResourceClient>> m_clientsAwaitingCallback; | 484 HeapHashCountedSet<WeakMember<ResourceClient>> m_clientsAwaitingCallback; |
472 HeapHashCountedSet<WeakMember<ResourceClient>> m_finishedClients; | 485 HeapHashCountedSet<WeakMember<ResourceClient>> m_finishedClients; |
473 | 486 |
474 ResourceLoaderOptions m_options; | 487 ResourceLoaderOptions m_options; |
475 | 488 |
476 double m_responseTimestamp; | 489 double m_responseTimestamp; |
477 | 490 |
478 TaskRunnerTimer<Resource> m_cancelTimer; | 491 TaskRunnerTimer<Resource> m_cancelTimer; |
| 492 Member<FetchContext> m_fetchContext; |
479 | 493 |
480 ResourceRequest m_resourceRequest; | 494 ResourceRequest m_resourceRequest; |
481 Member<ResourceLoader> m_loader; | 495 Member<ResourceLoader> m_loader; |
482 ResourceResponse m_response; | 496 ResourceResponse m_response; |
483 | 497 |
484 RefPtr<SharedBuffer> m_data; | 498 RefPtr<SharedBuffer> m_data; |
485 }; | 499 }; |
486 | 500 |
487 class ResourceFactory { | 501 class ResourceFactory { |
488 STACK_ALLOCATED(); | 502 STACK_ALLOCATED(); |
489 | 503 |
490 public: | 504 public: |
491 virtual Resource* create(const ResourceRequest&, | 505 virtual Resource* create(const ResourceRequest&, |
492 const ResourceLoaderOptions&, | 506 const ResourceLoaderOptions&, |
493 const String&) const = 0; | 507 const String&, |
| 508 FetchContext*) const = 0; |
494 Resource::Type type() const { return m_type; } | 509 Resource::Type type() const { return m_type; } |
495 | 510 |
496 protected: | 511 protected: |
497 explicit ResourceFactory(Resource::Type type) : m_type(type) {} | 512 explicit ResourceFactory(Resource::Type type) : m_type(type) {} |
498 | 513 |
499 Resource::Type m_type; | 514 Resource::Type m_type; |
500 }; | 515 }; |
501 | 516 |
502 #define DEFINE_RESOURCE_TYPE_CASTS(typeName) \ | 517 #define DEFINE_RESOURCE_TYPE_CASTS(typeName) \ |
503 DEFINE_TYPE_CASTS(typeName##Resource, Resource, resource, \ | 518 DEFINE_TYPE_CASTS(typeName##Resource, Resource, resource, \ |
504 resource->getType() == Resource::typeName, \ | 519 resource->getType() == Resource::typeName, \ |
505 resource.getType() == Resource::typeName); | 520 resource.getType() == Resource::typeName); |
506 | 521 |
507 } // namespace blink | 522 } // namespace blink |
508 | 523 |
509 #endif | 524 #endif |
OLD | NEW |