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) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) |
5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
rights reserved. | 6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 95 |
96 Resource::Resource(const ResourceRequest& request, Type type) | 96 Resource::Resource(const ResourceRequest& request, Type type) |
97 : m_resourceRequest(request) | 97 : m_resourceRequest(request) |
98 , m_responseTimestamp(currentTime()) | 98 , m_responseTimestamp(currentTime()) |
99 , m_cancelTimer(this, &Resource::cancelTimerFired) | 99 , m_cancelTimer(this, &Resource::cancelTimerFired) |
100 , m_lastDecodedAccessTime(0) | 100 , m_lastDecodedAccessTime(0) |
101 , m_loadFinishTime(0) | 101 , m_loadFinishTime(0) |
102 , m_identifier(0) | 102 , m_identifier(0) |
103 , m_encodedSize(0) | 103 , m_encodedSize(0) |
104 , m_decodedSize(0) | 104 , m_decodedSize(0) |
105 , m_accessCount(0) | |
106 , m_handleCount(0) | 105 , m_handleCount(0) |
107 , m_preloadCount(0) | 106 , m_preloadCount(0) |
108 , m_protectorCount(0) | 107 , m_protectorCount(0) |
109 , m_preloadResult(PreloadNotReferenced) | 108 , m_preloadResult(PreloadNotReferenced) |
110 , m_cacheLiveResourcePriority(CacheLiveResourcePriorityLow) | 109 , m_cacheLiveResourcePriority(CacheLiveResourcePriorityLow) |
111 , m_requestedFromNetworkingLayer(false) | 110 , m_requestedFromNetworkingLayer(false) |
112 , m_inCache(false) | |
113 , m_loading(false) | 111 , m_loading(false) |
114 , m_switchingClientsToRevalidatedResource(false) | 112 , m_switchingClientsToRevalidatedResource(false) |
115 , m_type(type) | 113 , m_type(type) |
116 , m_status(Pending) | 114 , m_status(Pending) |
117 , m_wasPurged(false) | 115 , m_wasPurged(false) |
118 , m_needsSynchronousCacheHit(false) | 116 , m_needsSynchronousCacheHit(false) |
119 #ifndef NDEBUG | 117 #ifndef NDEBUG |
120 , m_deleted(false) | 118 , m_deleted(false) |
121 #endif | 119 #endif |
122 , m_resourceToRevalidate(0) | 120 , m_resourceToRevalidate(0) |
(...skipping 10 matching lines...) Expand all Loading... |
133 if (urlForCache.hasFragmentIdentifier()) | 131 if (urlForCache.hasFragmentIdentifier()) |
134 return; | 132 return; |
135 m_fragmentIdentifierForRequest = m_resourceRequest.url().fragmentIdentifier(
); | 133 m_fragmentIdentifierForRequest = m_resourceRequest.url().fragmentIdentifier(
); |
136 m_resourceRequest.setURL(urlForCache); | 134 m_resourceRequest.setURL(urlForCache); |
137 } | 135 } |
138 | 136 |
139 Resource::~Resource() | 137 Resource::~Resource() |
140 { | 138 { |
141 ASSERT(!m_resourceToRevalidate); // Should be true because canDelete() check
s this. | 139 ASSERT(!m_resourceToRevalidate); // Should be true because canDelete() check
s this. |
142 ASSERT(canDelete()); | 140 ASSERT(canDelete()); |
143 RELEASE_ASSERT(!inCache()); | 141 RELEASE_ASSERT(!memoryCache()->contains(this)); |
144 RELEASE_ASSERT(!ResourceCallback::callbackHandler()->isScheduled(this)); | 142 RELEASE_ASSERT(!ResourceCallback::callbackHandler()->isScheduled(this)); |
145 ASSERT(!m_deleted); | 143 ASSERT(!m_deleted); |
146 ASSERT(url().isNull() || memoryCache()->resourceForURL(KURL(ParsedURLString,
url())) != this); | 144 ASSERT(url().isNull() || memoryCache()->resourceForURL(KURL(ParsedURLString,
url())) != this); |
147 | 145 |
148 #ifndef NDEBUG | 146 #ifndef NDEBUG |
149 m_deleted = true; | 147 m_deleted = true; |
150 cachedResourceLeakCounter.decrement(); | 148 cachedResourceLeakCounter.decrement(); |
151 #endif | 149 #endif |
152 } | 150 } |
153 | 151 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 } | 341 } |
344 | 342 |
345 bool Resource::unlock() | 343 bool Resource::unlock() |
346 { | 344 { |
347 if (!m_data) | 345 if (!m_data) |
348 return false; | 346 return false; |
349 | 347 |
350 if (!m_data->isLocked()) | 348 if (!m_data->isLocked()) |
351 return true; | 349 return true; |
352 | 350 |
353 if (!inCache() || hasClients() || m_handleCount > 1 || m_proxyResource || m_
resourceToRevalidate || !m_loadFinishTime || !isSafeToUnlock()) | 351 if (!memoryCache()->contains(this) || hasClients() || m_handleCount > 1 || m
_proxyResource || m_resourceToRevalidate || !m_loadFinishTime || !isSafeToUnlock
()) |
354 return false; | 352 return false; |
355 | 353 |
356 m_data->unlock(); | 354 m_data->unlock(); |
357 return true; | 355 return true; |
358 } | 356 } |
359 | 357 |
360 void Resource::responseReceived(const ResourceResponse& response) | 358 void Resource::responseReceived(const ResourceResponse& response) |
361 { | 359 { |
362 setResponse(response); | 360 setResponse(response); |
363 m_responseTimestamp = currentTime(); | 361 m_responseTimestamp = currentTime(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 396 |
399 CachedMetadata* Resource::cachedMetadata(unsigned dataTypeID) const | 397 CachedMetadata* Resource::cachedMetadata(unsigned dataTypeID) const |
400 { | 398 { |
401 if (!m_cachedMetadata || m_cachedMetadata->dataTypeID() != dataTypeID) | 399 if (!m_cachedMetadata || m_cachedMetadata->dataTypeID() != dataTypeID) |
402 return 0; | 400 return 0; |
403 return m_cachedMetadata.get(); | 401 return m_cachedMetadata.get(); |
404 } | 402 } |
405 | 403 |
406 void Resource::setCacheLiveResourcePriority(CacheLiveResourcePriority priority) | 404 void Resource::setCacheLiveResourcePriority(CacheLiveResourcePriority priority) |
407 { | 405 { |
408 if (inCache() && memoryCache()->isInLiveDecodedResourcesList(this) && cacheL
iveResourcePriority() != static_cast<unsigned>(priority)) { | 406 if (memoryCache()->contains(this) && memoryCache()->isInLiveDecodedResources
List(this) && cacheLiveResourcePriority() != static_cast<unsigned>(priority)) { |
409 memoryCache()->removeFromLiveDecodedResourcesList(this); | 407 memoryCache()->removeFromLiveDecodedResourcesList(this); |
410 m_cacheLiveResourcePriority = priority; | 408 m_cacheLiveResourcePriority = priority; |
411 memoryCache()->insertInLiveDecodedResourcesList(this); | 409 memoryCache()->insertInLiveDecodedResourcesList(this); |
412 memoryCache()->prune(); | 410 memoryCache()->prune(); |
413 } | 411 } |
414 } | 412 } |
415 | 413 |
416 void Resource::clearLoader() | 414 void Resource::clearLoader() |
417 { | 415 { |
418 m_loader = nullptr; | 416 m_loader = nullptr; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 ASSERT(!isPurgeable()); | 452 ASSERT(!isPurgeable()); |
455 | 453 |
456 if (m_preloadResult == PreloadNotReferenced) { | 454 if (m_preloadResult == PreloadNotReferenced) { |
457 if (isLoaded()) | 455 if (isLoaded()) |
458 m_preloadResult = PreloadReferencedWhileComplete; | 456 m_preloadResult = PreloadReferencedWhileComplete; |
459 else if (m_requestedFromNetworkingLayer) | 457 else if (m_requestedFromNetworkingLayer) |
460 m_preloadResult = PreloadReferencedWhileLoading; | 458 m_preloadResult = PreloadReferencedWhileLoading; |
461 else | 459 else |
462 m_preloadResult = PreloadReferenced; | 460 m_preloadResult = PreloadReferenced; |
463 } | 461 } |
464 if (!hasClients() && inCache()) | 462 if (!hasClients() && memoryCache()->contains(this)) |
465 memoryCache()->addToLiveResourcesSize(this); | 463 memoryCache()->addToLiveResourcesSize(this); |
466 | 464 |
467 // If we have existing data to send to the new client and the resource type
supprts it, send it asynchronously. | 465 // If we have existing data to send to the new client and the resource type
supprts it, send it asynchronously. |
468 if (!m_response.isNull() && !m_proxyResource && !shouldSendCachedDataSynchro
nouslyForType(type()) && !m_needsSynchronousCacheHit) { | 466 if (!m_response.isNull() && !m_proxyResource && !shouldSendCachedDataSynchro
nouslyForType(type()) && !m_needsSynchronousCacheHit) { |
469 m_clientsAwaitingCallback.add(client); | 467 m_clientsAwaitingCallback.add(client); |
470 ResourceCallback::callbackHandler()->schedule(this); | 468 ResourceCallback::callbackHandler()->schedule(this); |
471 return false; | 469 return false; |
472 } | 470 } |
473 | 471 |
474 m_clients.add(client); | 472 m_clients.add(client); |
475 return true; | 473 return true; |
476 } | 474 } |
477 | 475 |
478 void Resource::removeClient(ResourceClient* client) | 476 void Resource::removeClient(ResourceClient* client) |
479 { | 477 { |
480 if (m_clientsAwaitingCallback.contains(client)) { | 478 if (m_clientsAwaitingCallback.contains(client)) { |
481 ASSERT(!m_clients.contains(client)); | 479 ASSERT(!m_clients.contains(client)); |
482 m_clientsAwaitingCallback.remove(client); | 480 m_clientsAwaitingCallback.remove(client); |
483 if (m_clientsAwaitingCallback.isEmpty()) | 481 if (m_clientsAwaitingCallback.isEmpty()) |
484 ResourceCallback::callbackHandler()->cancel(this); | 482 ResourceCallback::callbackHandler()->cancel(this); |
485 } else { | 483 } else { |
486 ASSERT(m_clients.contains(client)); | 484 ASSERT(m_clients.contains(client)); |
487 m_clients.remove(client); | 485 m_clients.remove(client); |
488 didRemoveClient(client); | 486 didRemoveClient(client); |
489 } | 487 } |
490 | 488 |
491 bool deleted = deleteIfPossible(); | 489 bool deleted = deleteIfPossible(); |
492 if (!deleted && !hasClients()) { | 490 if (!deleted && !hasClients()) { |
493 if (inCache()) { | 491 if (memoryCache()->contains(this)) { |
494 memoryCache()->removeFromLiveResourcesSize(this); | 492 memoryCache()->removeFromLiveResourcesSize(this); |
495 memoryCache()->removeFromLiveDecodedResourcesList(this); | 493 memoryCache()->removeFromLiveDecodedResourcesList(this); |
496 } | 494 } |
497 if (!m_switchingClientsToRevalidatedResource) | 495 if (!m_switchingClientsToRevalidatedResource) |
498 allClientsRemoved(); | 496 allClientsRemoved(); |
499 | 497 |
500 // RFC2616 14.9.2: | 498 // RFC2616 14.9.2: |
501 // "no-store: ... MUST make a best-effort attempt to remove the informat
ion from volatile storage as promptly as possible" | 499 // "no-store: ... MUST make a best-effort attempt to remove the informat
ion from volatile storage as promptly as possible" |
502 // "... History buffers MAY store such responses as part of their normal
operation." | 500 // "... History buffers MAY store such responses as part of their normal
operation." |
503 // We allow non-secure content to be reused in history, but we do not al
low secure content to be reused. | 501 // We allow non-secure content to be reused in history, but we do not al
low secure content to be reused. |
(...skipping 25 matching lines...) Expand all Loading... |
529 if (hasClients() || !m_loader) | 527 if (hasClients() || !m_loader) |
530 return; | 528 return; |
531 ResourcePtr<Resource> protect(this); | 529 ResourcePtr<Resource> protect(this); |
532 m_loader->cancelIfNotFinishing(); | 530 m_loader->cancelIfNotFinishing(); |
533 if (m_status != Cached) | 531 if (m_status != Cached) |
534 memoryCache()->remove(this); | 532 memoryCache()->remove(this); |
535 } | 533 } |
536 | 534 |
537 bool Resource::deleteIfPossible() | 535 bool Resource::deleteIfPossible() |
538 { | 536 { |
539 if (canDelete() && !inCache()) { | 537 if (canDelete() && !memoryCache()->contains(this)) { |
540 InspectorInstrumentation::willDestroyResource(this); | 538 InspectorInstrumentation::willDestroyResource(this); |
541 delete this; | 539 delete this; |
542 return true; | 540 return true; |
543 } | 541 } |
544 return false; | 542 return false; |
545 } | 543 } |
546 | 544 |
547 void Resource::setDecodedSize(size_t size) | 545 void Resource::setDecodedSize(size_t decodedSize) |
548 { | 546 { |
549 if (size == m_decodedSize) | 547 if (decodedSize == m_decodedSize) |
550 return; | 548 return; |
| 549 size_t oldSize = size(); |
| 550 m_decodedSize = decodedSize; |
551 | 551 |
552 ptrdiff_t delta = size - m_decodedSize; | 552 if (memoryCache()->contains(this)) { |
553 | |
554 // The object must now be moved to a different queue, since its size has bee
n changed. | |
555 // We have to remove explicitly before updating m_decodedSize, so that we fi
nd the correct previous | |
556 // queue. | |
557 if (inCache()) | |
558 memoryCache()->removeFromLRUList(this); | |
559 | |
560 m_decodedSize = size; | |
561 | |
562 if (inCache()) { | |
563 // Now insert into the new LRU list. | |
564 memoryCache()->insertInLRUList(this); | |
565 | |
566 // Insert into or remove from the live decoded list if necessary. | 553 // Insert into or remove from the live decoded list if necessary. |
567 // When inserting into the LiveDecodedResourcesList it is possible | 554 // When inserting into the LiveDecodedResourcesList it is possible |
568 // that the m_lastDecodedAccessTime is still zero or smaller than | 555 // that the m_lastDecodedAccessTime is still zero or smaller than |
569 // the m_lastDecodedAccessTime of the current list head. This is a | 556 // the m_lastDecodedAccessTime of the current list head. This is a |
570 // violation of the invariant that the list is to be kept sorted | 557 // violation of the invariant that the list is to be kept sorted |
571 // by access time. The weakening of the invariant does not pose | 558 // by access time. The weakening of the invariant does not pose |
572 // a problem. For more details please see: https://bugs.webkit.org/show_
bug.cgi?id=30209 | 559 // a problem. For more details please see: https://bugs.webkit.org/show_
bug.cgi?id=30209 |
573 if (m_decodedSize && !memoryCache()->isInLiveDecodedResourcesList(this)
&& hasClients()) | 560 if (m_decodedSize && !memoryCache()->isInLiveDecodedResourcesList(this)
&& hasClients()) |
574 memoryCache()->insertInLiveDecodedResourcesList(this); | 561 memoryCache()->insertInLiveDecodedResourcesList(this); |
575 else if (!m_decodedSize && memoryCache()->isInLiveDecodedResourcesList(t
his)) | 562 else if (!m_decodedSize && memoryCache()->isInLiveDecodedResourcesList(t
his)) |
576 memoryCache()->removeFromLiveDecodedResourcesList(this); | 563 memoryCache()->removeFromLiveDecodedResourcesList(this); |
577 | 564 |
578 // Update the cache's size totals. | 565 // Update the cache's size totals. |
579 memoryCache()->adjustSize(hasClients(), delta); | 566 memoryCache()->update(this, oldSize, size()); |
580 } | 567 } |
581 } | 568 } |
582 | 569 |
583 void Resource::setEncodedSize(size_t size) | 570 void Resource::setEncodedSize(size_t encodedSize) |
584 { | 571 { |
585 if (size == m_encodedSize) | 572 if (encodedSize == m_encodedSize) |
586 return; | 573 return; |
587 | 574 size_t oldSize = size(); |
588 ptrdiff_t delta = size - m_encodedSize; | 575 m_encodedSize = encodedSize; |
589 | 576 if (memoryCache()->contains(this)) |
590 // The object must now be moved to a different queue, since its size has bee
n changed. | 577 memoryCache()->update(this, oldSize, size()); |
591 // We have to remove explicitly before updating m_encodedSize, so that we fi
nd the correct previous | |
592 // queue. | |
593 if (inCache()) | |
594 memoryCache()->removeFromLRUList(this); | |
595 | |
596 m_encodedSize = size; | |
597 | |
598 if (inCache()) { | |
599 // Now insert into the new LRU list. | |
600 memoryCache()->insertInLRUList(this); | |
601 | |
602 // Update the cache's size totals. | |
603 memoryCache()->adjustSize(hasClients(), delta); | |
604 } | |
605 } | 578 } |
606 | 579 |
607 void Resource::didAccessDecodedData(double timeStamp) | 580 void Resource::didAccessDecodedData(double timeStamp) |
608 { | 581 { |
609 m_lastDecodedAccessTime = timeStamp; | 582 m_lastDecodedAccessTime = timeStamp; |
610 if (inCache()) { | 583 if (memoryCache()->contains(this)) { |
611 if (memoryCache()->isInLiveDecodedResourcesList(this)) { | 584 if (memoryCache()->isInLiveDecodedResourcesList(this)) { |
612 memoryCache()->removeFromLiveDecodedResourcesList(this); | 585 memoryCache()->removeFromLiveDecodedResourcesList(this); |
613 memoryCache()->insertInLiveDecodedResourcesList(this); | 586 memoryCache()->insertInLiveDecodedResourcesList(this); |
614 } | 587 } |
615 memoryCache()->prune(); | 588 memoryCache()->prune(); |
616 } | 589 } |
617 } | 590 } |
618 | 591 |
619 void Resource::finishPendingClients() | 592 void Resource::finishPendingClients() |
620 { | 593 { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 m_resourceToRevalidate->deleteIfPossible(); | 636 m_resourceToRevalidate->deleteIfPossible(); |
664 } | 637 } |
665 m_handlesToRevalidate.clear(); | 638 m_handlesToRevalidate.clear(); |
666 m_resourceToRevalidate = 0; | 639 m_resourceToRevalidate = 0; |
667 deleteIfPossible(); | 640 deleteIfPossible(); |
668 } | 641 } |
669 | 642 |
670 void Resource::switchClientsToRevalidatedResource() | 643 void Resource::switchClientsToRevalidatedResource() |
671 { | 644 { |
672 ASSERT(m_resourceToRevalidate); | 645 ASSERT(m_resourceToRevalidate); |
673 ASSERT(m_resourceToRevalidate->inCache()); | 646 ASSERT(memoryCache()->contains(m_resourceToRevalidate)); |
674 ASSERT(!inCache()); | 647 ASSERT(!memoryCache()->contains(this)); |
675 | 648 |
676 WTF_LOG(ResourceLoading, "Resource %p switchClientsToRevalidatedResource %p"
, this, m_resourceToRevalidate); | 649 WTF_LOG(ResourceLoading, "Resource %p switchClientsToRevalidatedResource %p"
, this, m_resourceToRevalidate); |
677 | 650 |
678 m_resourceToRevalidate->m_identifier = m_identifier; | 651 m_resourceToRevalidate->m_identifier = m_identifier; |
679 | 652 |
680 m_switchingClientsToRevalidatedResource = true; | 653 m_switchingClientsToRevalidatedResource = true; |
681 HashSet<ResourcePtrBase*>::iterator end = m_handlesToRevalidate.end(); | 654 HashSet<ResourcePtrBase*>::iterator end = m_handlesToRevalidate.end(); |
682 for (HashSet<ResourcePtrBase*>::iterator it = m_handlesToRevalidate.begin();
it != end; ++it) { | 655 for (HashSet<ResourcePtrBase*>::iterator it = m_handlesToRevalidate.begin();
it != end; ++it) { |
683 ResourcePtrBase* handle = *it; | 656 ResourcePtrBase* handle = *it; |
684 handle->m_resource = m_resourceToRevalidate; | 657 handle->m_resource = m_resourceToRevalidate; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 // we care about. | 706 // we care about. |
734 if (!shouldUpdateHeaderAfterRevalidation(it->key)) | 707 if (!shouldUpdateHeaderAfterRevalidation(it->key)) |
735 continue; | 708 continue; |
736 m_response.setHTTPHeaderField(it->key, it->value); | 709 m_response.setHTTPHeaderField(it->key, it->value); |
737 } | 710 } |
738 } | 711 } |
739 | 712 |
740 void Resource::revalidationSucceeded(const ResourceResponse& response) | 713 void Resource::revalidationSucceeded(const ResourceResponse& response) |
741 { | 714 { |
742 ASSERT(m_resourceToRevalidate); | 715 ASSERT(m_resourceToRevalidate); |
743 ASSERT(!m_resourceToRevalidate->inCache()); | 716 ASSERT(!memoryCache()->contains(m_resourceToRevalidate)); |
744 ASSERT(m_resourceToRevalidate->isLoaded()); | 717 ASSERT(m_resourceToRevalidate->isLoaded()); |
745 ASSERT(inCache()); | 718 ASSERT(memoryCache()->contains(this)); |
746 | 719 |
747 // Calling evict() can potentially delete revalidatingResource, which we use | 720 // Calling evict() can potentially delete revalidatingResource, which we use |
748 // below. This mustn't be the case since revalidation means it is loaded | 721 // below. This mustn't be the case since revalidation means it is loaded |
749 // and so canDelete() is false. | 722 // and so canDelete() is false. |
750 ASSERT(!canDelete()); | 723 ASSERT(!canDelete()); |
751 | 724 |
752 m_resourceToRevalidate->updateResponseAfterRevalidation(response); | 725 m_resourceToRevalidate->updateResponseAfterRevalidation(response); |
753 memoryCache()->replace(m_resourceToRevalidate, this); | 726 memoryCache()->replace(m_resourceToRevalidate, this); |
754 | 727 |
755 switchClientsToRevalidatedResource(); | 728 switchClientsToRevalidatedResource(); |
756 ASSERT(!m_deleted); | 729 ASSERT(!m_deleted); |
757 // clearResourceToRevalidate deletes this. | 730 // clearResourceToRevalidate deletes this. |
758 clearResourceToRevalidate(); | 731 clearResourceToRevalidate(); |
759 } | 732 } |
760 | 733 |
761 void Resource::revalidationFailed() | 734 void Resource::revalidationFailed() |
762 { | 735 { |
763 ASSERT(WTF::isMainThread()); | 736 ASSERT(WTF::isMainThread()); |
764 WTF_LOG(ResourceLoading, "Revalidation failed for %p", this); | 737 WTF_LOG(ResourceLoading, "Revalidation failed for %p", this); |
765 ASSERT(resourceToRevalidate()); | 738 ASSERT(resourceToRevalidate()); |
766 clearResourceToRevalidate(); | 739 clearResourceToRevalidate(); |
767 } | 740 } |
768 | 741 |
769 void Resource::updateForAccess() | |
770 { | |
771 ASSERT(inCache()); | |
772 | |
773 // Need to make sure to remove before we increase the access count, since | |
774 // the queue will possibly change. | |
775 memoryCache()->removeFromLRUList(this); | |
776 | |
777 // If this is the first time the resource has been accessed, adjust the size
of the cache to account for its initial size. | |
778 if (!m_accessCount) | |
779 memoryCache()->adjustSize(hasClients(), size()); | |
780 | |
781 m_accessCount++; | |
782 memoryCache()->insertInLRUList(this); | |
783 } | |
784 | |
785 void Resource::registerHandle(ResourcePtrBase* h) | 742 void Resource::registerHandle(ResourcePtrBase* h) |
786 { | 743 { |
787 ++m_handleCount; | 744 ++m_handleCount; |
788 if (m_resourceToRevalidate) | 745 if (m_resourceToRevalidate) |
789 m_handlesToRevalidate.add(h); | 746 m_handlesToRevalidate.add(h); |
790 } | 747 } |
791 | 748 |
792 void Resource::unregisterHandle(ResourcePtrBase* h) | 749 void Resource::unregisterHandle(ResourcePtrBase* h) |
793 { | 750 { |
794 ASSERT(m_handleCount > 0); | 751 ASSERT(m_handleCount > 0); |
795 --m_handleCount; | 752 --m_handleCount; |
796 | 753 |
797 if (m_resourceToRevalidate) | 754 if (m_resourceToRevalidate) |
798 m_handlesToRevalidate.remove(h); | 755 m_handlesToRevalidate.remove(h); |
799 | 756 |
800 if (!m_handleCount) { | 757 if (!m_handleCount) { |
801 if (deleteIfPossible()) | 758 if (deleteIfPossible()) |
802 return; | 759 return; |
803 unlock(); | 760 unlock(); |
804 } else if (m_handleCount == 1 && inCache()) { | 761 } else if (m_handleCount == 1 && memoryCache()->contains(this)) { |
805 unlock(); | 762 unlock(); |
806 } | 763 } |
807 } | 764 } |
808 | 765 |
809 bool Resource::canReuseRedirectChain() const | 766 bool Resource::canReuseRedirectChain() const |
810 { | 767 { |
811 for (size_t i = 0; i < m_redirectChain.size(); ++i) { | 768 for (size_t i = 0; i < m_redirectChain.size(); ++i) { |
812 if (!canUseResponse(m_redirectChain[i].m_redirectResponse, m_responseTim
estamp)) | 769 if (!canUseResponse(m_redirectChain[i].m_redirectResponse, m_responseTim
estamp)) |
813 return false; | 770 return false; |
814 } | 771 } |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 return "Shader"; | 954 return "Shader"; |
998 case Resource::ImportResource: | 955 case Resource::ImportResource: |
999 return "ImportResource"; | 956 return "ImportResource"; |
1000 } | 957 } |
1001 ASSERT_NOT_REACHED(); | 958 ASSERT_NOT_REACHED(); |
1002 return "Unknown"; | 959 return "Unknown"; |
1003 } | 960 } |
1004 #endif // !LOG_DISABLED | 961 #endif // !LOG_DISABLED |
1005 | 962 |
1006 } | 963 } |
OLD | NEW |