| 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 FetchParameters; | 52 class FetchParameters; |
| 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 kMarkAsReferenced, | 93 kMarkAsReferenced, |
| 93 kDontMarkAsReferenced, | 94 kDontMarkAsReferenced, |
| 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 GetError(const ResourceError&); | 118 virtual void GetError(const ResourceError&); |
| 110 virtual void SetCORSFailed() {} | 119 virtual void SetCORSFailed() {} |
| 111 | 120 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 // If this Resource is ImageResource and has the Lo-Fi response headers or is | 338 // If this Resource is ImageResource and has the Lo-Fi response headers or is |
| 330 // a placeholder, reload the full original image with the Lo-Fi state set to | 339 // a placeholder, reload the full original image with the Lo-Fi state set to |
| 331 // off and optionally bypassing the cache. | 340 // off and optionally bypassing the cache. |
| 332 virtual void ReloadIfLoFiOrPlaceholderImage(ResourceFetcher*, | 341 virtual void ReloadIfLoFiOrPlaceholderImage(ResourceFetcher*, |
| 333 ReloadLoFiOrPlaceholderPolicy) {} | 342 ReloadLoFiOrPlaceholderPolicy) {} |
| 334 | 343 |
| 335 static const char* ResourceTypeToString( | 344 static const char* ResourceTypeToString( |
| 336 Type, | 345 Type, |
| 337 const AtomicString& fetch_initiator_name); | 346 const AtomicString& fetch_initiator_name); |
| 338 | 347 |
| 348 void FinishPendingClients(); |
| 349 |
| 339 protected: | 350 protected: |
| 340 Resource(const ResourceRequest&, Type, const ResourceLoaderOptions&); | 351 Resource(const ResourceRequest&, |
| 352 Type, |
| 353 const ResourceLoaderOptions&, |
| 354 FetchContext* = nullptr); |
| 341 | 355 |
| 342 virtual void CheckNotify(); | 356 virtual void CheckNotify(); |
| 343 | 357 |
| 344 void MarkClientFinished(ResourceClient*); | 358 void MarkClientFinished(ResourceClient*); |
| 345 | 359 |
| 346 virtual bool HasClientsOrObservers() const { | 360 virtual bool HasClientsOrObservers() const { |
| 347 return !clients_.IsEmpty() || !clients_awaiting_callback_.IsEmpty() || | 361 return !clients_.IsEmpty() || !clients_awaiting_callback_.IsEmpty() || |
| 348 !finished_clients_.IsEmpty(); | 362 !finished_clients_.IsEmpty(); |
| 349 } | 363 } |
| 350 virtual void DestroyDecodedDataForFailedRevalidation() {} | 364 virtual void DestroyDecodedDataForFailedRevalidation() {} |
| 351 | 365 |
| 352 void SetEncodedSize(size_t); | 366 void SetEncodedSize(size_t); |
| 353 void SetDecodedSize(size_t); | 367 void SetDecodedSize(size_t); |
| 354 | 368 |
| 355 void FinishPendingClients(); | |
| 356 | |
| 357 virtual void DidAddClient(ResourceClient*); | 369 virtual void DidAddClient(ResourceClient*); |
| 358 void WillAddClientOrObserver(PreloadReferencePolicy); | 370 void WillAddClientOrObserver(PreloadReferencePolicy); |
| 359 | 371 |
| 360 void DidRemoveClientOrObserver(); | 372 void DidRemoveClientOrObserver(); |
| 361 virtual void AllClientsAndObserversRemoved(); | 373 virtual void AllClientsAndObserversRemoved(); |
| 362 | 374 |
| 363 bool HasClient(ResourceClient* client) const { | 375 bool HasClient(ResourceClient* client) const { |
| 364 return clients_.Contains(client) || | 376 return clients_.Contains(client) || |
| 365 clients_awaiting_callback_.Contains(client) || | 377 clients_awaiting_callback_.Contains(client) || |
| 366 finished_clients_.Contains(client); | 378 finished_clients_.Contains(client); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 : AutoReset(&resource->is_add_remove_client_prohibited_, true) {} | 413 : AutoReset(&resource->is_add_remove_client_prohibited_, true) {} |
| 402 }; | 414 }; |
| 403 | 415 |
| 404 class RevalidationStartForbiddenScope : public AutoReset<bool> { | 416 class RevalidationStartForbiddenScope : public AutoReset<bool> { |
| 405 public: | 417 public: |
| 406 RevalidationStartForbiddenScope(Resource* resource) | 418 RevalidationStartForbiddenScope(Resource* resource) |
| 407 : AutoReset(&resource->is_revalidation_start_forbidden_, true) {} | 419 : AutoReset(&resource->is_revalidation_start_forbidden_, true) {} |
| 408 }; | 420 }; |
| 409 | 421 |
| 410 private: | 422 private: |
| 411 class ResourceCallback; | |
| 412 class CachedMetadataHandlerImpl; | 423 class CachedMetadataHandlerImpl; |
| 413 class ServiceWorkerResponseCachedMetadataHandler; | 424 class ServiceWorkerResponseCachedMetadataHandler; |
| 414 | 425 |
| 415 void CancelTimerFired(TimerBase*); | 426 void CancelTimerFired(TimerBase*); |
| 416 | 427 |
| 417 void RevalidationSucceeded(const ResourceResponse&); | 428 void RevalidationSucceeded(const ResourceResponse&); |
| 418 void RevalidationFailed(); | 429 void RevalidationFailed(); |
| 419 | 430 |
| 420 size_t CalculateOverheadSize() const; | 431 size_t CalculateOverheadSize() const; |
| 421 | 432 |
| 422 String ReasonNotDeletable() const; | 433 String ReasonNotDeletable() const; |
| 423 | 434 |
| 435 ResourceCallback& GetResourceCallback(); |
| 436 |
| 424 // MemoryCoordinatorClient overrides: | 437 // MemoryCoordinatorClient overrides: |
| 425 void OnPurgeMemory() override; | 438 void OnPurgeMemory() override; |
| 426 | 439 |
| 427 Member<CachedMetadataHandlerImpl> cache_handler_; | 440 Member<CachedMetadataHandlerImpl> cache_handler_; |
| 428 RefPtr<SecurityOrigin> fetcher_security_origin_; | 441 RefPtr<SecurityOrigin> fetcher_security_origin_; |
| 429 | 442 |
| 430 ResourceError error_; | 443 ResourceError error_; |
| 431 | 444 |
| 432 double load_finish_time_; | 445 double load_finish_time_; |
| 433 | 446 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 | 481 |
| 469 HeapHashCountedSet<WeakMember<ResourceClient>> clients_; | 482 HeapHashCountedSet<WeakMember<ResourceClient>> clients_; |
| 470 HeapHashCountedSet<WeakMember<ResourceClient>> clients_awaiting_callback_; | 483 HeapHashCountedSet<WeakMember<ResourceClient>> clients_awaiting_callback_; |
| 471 HeapHashCountedSet<WeakMember<ResourceClient>> finished_clients_; | 484 HeapHashCountedSet<WeakMember<ResourceClient>> finished_clients_; |
| 472 | 485 |
| 473 ResourceLoaderOptions options_; | 486 ResourceLoaderOptions options_; |
| 474 | 487 |
| 475 double response_timestamp_; | 488 double response_timestamp_; |
| 476 | 489 |
| 477 TaskRunnerTimer<Resource> cancel_timer_; | 490 TaskRunnerTimer<Resource> cancel_timer_; |
| 491 Member<FetchContext> fetch_context_; |
| 478 | 492 |
| 479 ResourceRequest resource_request_; | 493 ResourceRequest resource_request_; |
| 480 Member<ResourceLoader> loader_; | 494 Member<ResourceLoader> loader_; |
| 481 ResourceResponse response_; | 495 ResourceResponse response_; |
| 482 | 496 |
| 483 RefPtr<SharedBuffer> data_; | 497 RefPtr<SharedBuffer> data_; |
| 484 }; | 498 }; |
| 485 | 499 |
| 486 class ResourceFactory { | 500 class ResourceFactory { |
| 487 STACK_ALLOCATED(); | 501 STACK_ALLOCATED(); |
| 488 | 502 |
| 489 public: | 503 public: |
| 490 virtual Resource* Create(const ResourceRequest&, | 504 virtual Resource* Create(const ResourceRequest&, |
| 491 const ResourceLoaderOptions&, | 505 const ResourceLoaderOptions&, |
| 492 const String&) const = 0; | 506 const String&, |
| 507 FetchContext*) const = 0; |
| 493 Resource::Type GetType() const { return type_; } | 508 Resource::Type GetType() const { return type_; } |
| 494 | 509 |
| 495 protected: | 510 protected: |
| 496 explicit ResourceFactory(Resource::Type type) : type_(type) {} | 511 explicit ResourceFactory(Resource::Type type) : type_(type) {} |
| 497 | 512 |
| 498 Resource::Type type_; | 513 Resource::Type type_; |
| 499 }; | 514 }; |
| 500 | 515 |
| 501 #define DEFINE_RESOURCE_TYPE_CASTS(typeName) \ | 516 #define DEFINE_RESOURCE_TYPE_CASTS(typeName) \ |
| 502 DEFINE_TYPE_CASTS(typeName##Resource, Resource, resource, \ | 517 DEFINE_TYPE_CASTS(typeName##Resource, Resource, resource, \ |
| 503 resource->GetType() == Resource::k##typeName, \ | 518 resource->GetType() == Resource::k##typeName, \ |
| 504 resource.GetType() == Resource::k##typeName); | 519 resource.GetType() == Resource::k##typeName); |
| 505 | 520 |
| 506 } // namespace blink | 521 } // namespace blink |
| 507 | 522 |
| 508 #endif | 523 #endif |
| OLD | NEW |