| 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 13 matching lines...) Expand all Loading... |
| 24 #include "core/fetch/Resource.h" | 24 #include "core/fetch/Resource.h" |
| 25 | 25 |
| 26 #include "core/fetch/CachedMetadata.h" | 26 #include "core/fetch/CachedMetadata.h" |
| 27 #include "core/fetch/CrossOriginAccessControl.h" | 27 #include "core/fetch/CrossOriginAccessControl.h" |
| 28 #include "core/fetch/FetchInitiatorTypeNames.h" | 28 #include "core/fetch/FetchInitiatorTypeNames.h" |
| 29 #include "core/fetch/MemoryCache.h" | 29 #include "core/fetch/MemoryCache.h" |
| 30 #include "core/fetch/ResourceClient.h" | 30 #include "core/fetch/ResourceClient.h" |
| 31 #include "core/fetch/ResourceClientWalker.h" | 31 #include "core/fetch/ResourceClientWalker.h" |
| 32 #include "core/fetch/ResourceFetcher.h" | 32 #include "core/fetch/ResourceFetcher.h" |
| 33 #include "core/fetch/ResourceLoader.h" | 33 #include "core/fetch/ResourceLoader.h" |
| 34 #include "core/fetch/ResourcePtr.h" | |
| 35 #include "core/inspector/InspectorInstrumentation.h" | 34 #include "core/inspector/InspectorInstrumentation.h" |
| 36 #include "platform/Logging.h" | 35 #include "platform/Logging.h" |
| 37 #include "platform/SharedBuffer.h" | 36 #include "platform/SharedBuffer.h" |
| 38 #include "platform/TraceEvent.h" | 37 #include "platform/TraceEvent.h" |
| 39 #include "platform/weborigin/KURL.h" | 38 #include "platform/weborigin/KURL.h" |
| 40 #include "public/platform/Platform.h" | 39 #include "public/platform/Platform.h" |
| 41 #include "public/platform/WebProcessMemoryDump.h" | 40 #include "public/platform/WebProcessMemoryDump.h" |
| 42 #include "wtf/CurrentTime.h" | 41 #include "wtf/CurrentTime.h" |
| 43 #include "wtf/MathExtras.h" | 42 #include "wtf/MathExtras.h" |
| 44 #include "wtf/StdLibExtras.h" | 43 #include "wtf/StdLibExtras.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 : m_resourceRequest(request) | 147 : m_resourceRequest(request) |
| 149 , m_responseTimestamp(currentTime()) | 148 , m_responseTimestamp(currentTime()) |
| 150 , m_cancelTimer(this, &Resource::cancelTimerFired) | 149 , m_cancelTimer(this, &Resource::cancelTimerFired) |
| 151 #if !ENABLE(OILPAN) | 150 #if !ENABLE(OILPAN) |
| 152 , m_weakPtrFactory(this) | 151 , m_weakPtrFactory(this) |
| 153 #endif | 152 #endif |
| 154 , m_loadFinishTime(0) | 153 , m_loadFinishTime(0) |
| 155 , m_identifier(0) | 154 , m_identifier(0) |
| 156 , m_encodedSize(0) | 155 , m_encodedSize(0) |
| 157 , m_decodedSize(0) | 156 , m_decodedSize(0) |
| 158 , m_handleCount(0) | |
| 159 , m_preloadCount(0) | 157 , m_preloadCount(0) |
| 160 , m_protectorCount(0) | |
| 161 , m_cacheIdentifier(MemoryCache::defaultCacheIdentifier()) | 158 , m_cacheIdentifier(MemoryCache::defaultCacheIdentifier()) |
| 162 , m_preloadResult(PreloadNotReferenced) | 159 , m_preloadResult(PreloadNotReferenced) |
| 163 , m_requestedFromNetworkingLayer(false) | 160 , m_requestedFromNetworkingLayer(false) |
| 164 , m_loading(false) | 161 , m_loading(false) |
| 165 , m_switchingClientsToRevalidatedResource(false) | |
| 166 , m_type(type) | 162 , m_type(type) |
| 167 , m_status(Pending) | 163 , m_status(Pending) |
| 168 , m_wasPurged(false) | |
| 169 , m_needsSynchronousCacheHit(false) | 164 , m_needsSynchronousCacheHit(false) |
| 170 , m_linkPreload(false) | 165 , m_linkPreload(false) |
| 171 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK | 166 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK |
| 172 , m_deleted(false) | 167 , m_deleted(false) |
| 173 #endif | 168 #endif |
| 174 { | 169 { |
| 175 ASSERT(m_type == unsigned(type)); // m_type is a bitfield, so this tests car
eless updates of the enum. | 170 ASSERT(m_type == unsigned(type)); // m_type is a bitfield, so this tests car
eless updates of the enum. |
| 176 InstanceCounters::incrementCounter(InstanceCounters::ResourceCounter); | 171 InstanceCounters::incrementCounter(InstanceCounters::ResourceCounter); |
| 177 memoryCache()->registerLiveResource(*this); | |
| 178 | 172 |
| 179 // Currently we support the metadata caching only for HTTP family. | 173 // Currently we support the metadata caching only for HTTP family. |
| 180 if (m_resourceRequest.url().protocolIsInHTTPFamily()) | 174 if (m_resourceRequest.url().protocolIsInHTTPFamily()) |
| 181 m_cacheHandler = CacheHandler::create(this); | 175 m_cacheHandler = CacheHandler::create(this); |
| 182 | 176 |
| 183 if (!m_resourceRequest.url().hasFragmentIdentifier()) | 177 if (!m_resourceRequest.url().hasFragmentIdentifier()) |
| 184 return; | 178 return; |
| 185 KURL urlForCache = MemoryCache::removeFragmentIdentifierIfNeeded(m_resourceR
equest.url()); | 179 KURL urlForCache = MemoryCache::removeFragmentIdentifierIfNeeded(m_resourceR
equest.url()); |
| 186 if (urlForCache.hasFragmentIdentifier()) | 180 if (urlForCache.hasFragmentIdentifier()) |
| 187 return; | 181 return; |
| 188 m_fragmentIdentifierForRequest = m_resourceRequest.url().fragmentIdentifier(
); | 182 m_fragmentIdentifierForRequest = m_resourceRequest.url().fragmentIdentifier(
); |
| 189 m_resourceRequest.setURL(urlForCache); | 183 m_resourceRequest.setURL(urlForCache); |
| 190 } | 184 } |
| 191 | 185 |
| 192 Resource::~Resource() | 186 Resource::~Resource() |
| 193 { | 187 { |
| 194 ASSERT(canDelete()); | |
| 195 RELEASE_ASSERT(!memoryCache()->contains(this)); | |
| 196 RELEASE_ASSERT(!ResourceCallback::callbackHandler()->isScheduled(this)); | |
| 197 assertAlive(); | 188 assertAlive(); |
| 198 | 189 |
| 199 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK | 190 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK |
| 200 m_deleted = true; | 191 m_deleted = true; |
| 201 #endif | 192 #endif |
| 193 |
| 202 InstanceCounters::decrementCounter(InstanceCounters::ResourceCounter); | 194 InstanceCounters::decrementCounter(InstanceCounters::ResourceCounter); |
| 203 } | 195 } |
| 204 | 196 |
| 205 void Resource::dispose() | 197 void Resource::removedFromMemoryCache() |
| 206 { | 198 { |
| 199 InspectorInstrumentation::removedResourceFromMemoryCache(this); |
| 207 } | 200 } |
| 208 | 201 |
| 209 DEFINE_TRACE(Resource) | 202 DEFINE_TRACE(Resource) |
| 210 { | 203 { |
| 211 visitor->trace(m_loader); | 204 visitor->trace(m_loader); |
| 212 #if ENABLE(OILPAN) | 205 #if ENABLE(OILPAN) |
| 213 visitor->trace(m_cacheHandler); | 206 visitor->trace(m_cacheHandler); |
| 214 #endif | 207 #endif |
| 215 } | 208 } |
| 216 | 209 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 } | 432 } |
| 440 | 433 |
| 441 bool Resource::unlock() | 434 bool Resource::unlock() |
| 442 { | 435 { |
| 443 if (!m_data) | 436 if (!m_data) |
| 444 return false; | 437 return false; |
| 445 | 438 |
| 446 if (!m_data->isLocked()) | 439 if (!m_data->isLocked()) |
| 447 return true; | 440 return true; |
| 448 | 441 |
| 449 if (!memoryCache()->contains(this) || hasClients() || m_handleCount > 1 || !
m_revalidatingRequest.isNull() || !m_loadFinishTime || !isSafeToUnlock()) | 442 if (!memoryCache()->contains(this) || hasClients() || !m_revalidatingRequest
.isNull() || !m_loadFinishTime || !isSafeToUnlock()) |
| 450 return false; | 443 return false; |
| 451 | 444 |
| 452 m_data->unlock(); | 445 m_data->unlock(); |
| 453 return true; | 446 return true; |
| 454 } | 447 } |
| 455 | 448 |
| 456 bool Resource::hasRightHandleCountApartFromCache(unsigned targetCount) const | |
| 457 { | |
| 458 return m_handleCount == targetCount + (memoryCache()->contains(this) ? 1 : 0
); | |
| 459 } | |
| 460 | |
| 461 void Resource::responseReceived(const ResourceResponse& response, PassOwnPtr<Web
DataConsumerHandle>) | 449 void Resource::responseReceived(const ResourceResponse& response, PassOwnPtr<Web
DataConsumerHandle>) |
| 462 { | 450 { |
| 463 m_responseTimestamp = currentTime(); | 451 m_responseTimestamp = currentTime(); |
| 464 | 452 |
| 465 if (!m_revalidatingRequest.isNull()) { | 453 if (!m_revalidatingRequest.isNull()) { |
| 466 if (response.httpStatusCode() == 304) { | 454 if (response.httpStatusCode() == 304) { |
| 467 revalidationSucceeded(response); | 455 revalidationSucceeded(response); |
| 468 return; | 456 return; |
| 469 } | 457 } |
| 470 revalidationFailed(); | 458 revalidationFailed(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 | 510 |
| 523 WeakPtrWillBeRawPtr<Resource> Resource::asWeakPtr() | 511 WeakPtrWillBeRawPtr<Resource> Resource::asWeakPtr() |
| 524 { | 512 { |
| 525 #if ENABLE(OILPAN) | 513 #if ENABLE(OILPAN) |
| 526 return this; | 514 return this; |
| 527 #else | 515 #else |
| 528 return m_weakPtrFactory.createWeakPtr(); | 516 return m_weakPtrFactory.createWeakPtr(); |
| 529 #endif | 517 #endif |
| 530 } | 518 } |
| 531 | 519 |
| 532 bool Resource::canDelete() const | |
| 533 { | |
| 534 return !hasClients() && !m_loader && !m_preloadCount && hasRightHandleCountA
partFromCache(0) | |
| 535 && !m_protectorCount; | |
| 536 } | |
| 537 | |
| 538 String Resource::reasonNotDeletable() const | 520 String Resource::reasonNotDeletable() const |
| 539 { | 521 { |
| 540 StringBuilder builder; | 522 StringBuilder builder; |
| 541 if (hasClients()) { | 523 if (hasClients()) { |
| 542 builder.append("hasClients("); | 524 builder.append("hasClients("); |
| 543 builder.appendNumber(m_clients.size()); | 525 builder.appendNumber(m_clients.size()); |
| 544 if (!m_clientsAwaitingCallback.isEmpty()) { | 526 if (!m_clientsAwaitingCallback.isEmpty()) { |
| 545 builder.append(", AwaitingCallback="); | 527 builder.append(", AwaitingCallback="); |
| 546 builder.appendNumber(m_clientsAwaitingCallback.size()); | 528 builder.appendNumber(m_clientsAwaitingCallback.size()); |
| 547 } | 529 } |
| 548 if (!m_finishedClients.isEmpty()) { | 530 if (!m_finishedClients.isEmpty()) { |
| 549 builder.append(", Finished="); | 531 builder.append(", Finished="); |
| 550 builder.appendNumber(m_finishedClients.size()); | 532 builder.appendNumber(m_finishedClients.size()); |
| 551 } | 533 } |
| 552 builder.append(")"); | 534 builder.append(")"); |
| 553 } | 535 } |
| 554 if (m_loader) { | 536 if (m_loader) { |
| 555 if (!builder.isEmpty()) | 537 if (!builder.isEmpty()) |
| 556 builder.append(' '); | 538 builder.append(' '); |
| 557 builder.append("m_loader"); | 539 builder.append("m_loader"); |
| 558 } | 540 } |
| 559 if (m_preloadCount) { | 541 if (m_preloadCount) { |
| 560 if (!builder.isEmpty()) | 542 if (!builder.isEmpty()) |
| 561 builder.append(' '); | 543 builder.append(' '); |
| 562 builder.append("m_preloadCount("); | 544 builder.append("m_preloadCount("); |
| 563 builder.appendNumber(m_preloadCount); | 545 builder.appendNumber(m_preloadCount); |
| 564 builder.append(")"); | 546 builder.append(")"); |
| 565 } | 547 } |
| 566 if (!hasRightHandleCountApartFromCache(0)) { | |
| 567 if (!builder.isEmpty()) | |
| 568 builder.append(' '); | |
| 569 builder.append("m_handleCount("); | |
| 570 builder.appendNumber(m_handleCount); | |
| 571 builder.append(")"); | |
| 572 } | |
| 573 if (m_protectorCount) { | |
| 574 if (!builder.isEmpty()) | |
| 575 builder.append(' '); | |
| 576 builder.append("m_protectorCount("); | |
| 577 builder.appendNumber(m_protectorCount); | |
| 578 builder.append(")"); | |
| 579 } | |
| 580 if (memoryCache()->contains(this)) { | 548 if (memoryCache()->contains(this)) { |
| 581 if (!builder.isEmpty()) | 549 if (!builder.isEmpty()) |
| 582 builder.append(' '); | 550 builder.append(' '); |
| 583 builder.append("in_memory_cache"); | 551 builder.append("in_memory_cache"); |
| 584 } | 552 } |
| 585 return builder.toString(); | 553 return builder.toString(); |
| 586 } | 554 } |
| 587 | 555 |
| 588 bool Resource::hasOneHandle() const | |
| 589 { | |
| 590 return hasRightHandleCountApartFromCache(1); | |
| 591 } | |
| 592 | |
| 593 CachedMetadata* Resource::cachedMetadata(unsigned dataTypeID) const | 556 CachedMetadata* Resource::cachedMetadata(unsigned dataTypeID) const |
| 594 { | 557 { |
| 595 if (!m_cachedMetadata || m_cachedMetadata->dataTypeID() != dataTypeID) | 558 if (!m_cachedMetadata || m_cachedMetadata->dataTypeID() != dataTypeID) |
| 596 return nullptr; | 559 return nullptr; |
| 597 return m_cachedMetadata.get(); | 560 return m_cachedMetadata.get(); |
| 598 } | 561 } |
| 599 | 562 |
| 600 void Resource::clearLoader() | 563 void Resource::clearLoader() |
| 601 { | 564 { |
| 602 m_loader = nullptr; | 565 m_loader = nullptr; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 else if (m_clientsAwaitingCallback.contains(client)) | 635 else if (m_clientsAwaitingCallback.contains(client)) |
| 673 m_clientsAwaitingCallback.remove(client); | 636 m_clientsAwaitingCallback.remove(client); |
| 674 else | 637 else |
| 675 m_clients.remove(client); | 638 m_clients.remove(client); |
| 676 | 639 |
| 677 didRemoveClient(client); | 640 didRemoveClient(client); |
| 678 | 641 |
| 679 if (m_clientsAwaitingCallback.isEmpty()) | 642 if (m_clientsAwaitingCallback.isEmpty()) |
| 680 ResourceCallback::callbackHandler()->cancel(this); | 643 ResourceCallback::callbackHandler()->cancel(this); |
| 681 | 644 |
| 682 bool deleted = deleteIfPossible(); | 645 if (!hasClients()) { |
| 683 if (!deleted && !hasClients()) { | 646 RefPtrWillBeRawPtr<Resource> protect(this); |
| 684 memoryCache()->makeDead(this); | 647 memoryCache()->makeDead(this); |
| 685 if (!m_switchingClientsToRevalidatedResource) | 648 allClientsRemoved(); |
| 686 allClientsRemoved(); | |
| 687 | 649 |
| 688 // RFC2616 14.9.2: | 650 // RFC2616 14.9.2: |
| 689 // "no-store: ... MUST make a best-effort attempt to remove the informat
ion from volatile storage as promptly as possible" | 651 // "no-store: ... MUST make a best-effort attempt to remove the informat
ion from volatile storage as promptly as possible" |
| 690 // "... History buffers MAY store such responses as part of their normal
operation." | 652 // "... History buffers MAY store such responses as part of their normal
operation." |
| 691 // We allow non-secure content to be reused in history, but we do not al
low secure content to be reused. | 653 // We allow non-secure content to be reused in history, but we do not al
low secure content to be reused. |
| 692 if (hasCacheControlNoStoreHeader() && url().protocolIs("https")) { | 654 if (hasCacheControlNoStoreHeader() && url().protocolIs("https")) { |
| 693 memoryCache()->remove(this); | 655 memoryCache()->remove(this); |
| 694 memoryCache()->prune(); | 656 memoryCache()->prune(); |
| 695 } else { | 657 } else { |
| 696 memoryCache()->prune(this); | 658 memoryCache()->prune(this); |
| 697 } | 659 } |
| 698 } | 660 } |
| 699 // This object may be dead here. | 661 // This object may be dead here. |
| 700 } | 662 } |
| 701 | 663 |
| 702 void Resource::allClientsRemoved() | 664 void Resource::allClientsRemoved() |
| 703 { | 665 { |
| 704 if (!m_loader) | 666 if (!m_loader) |
| 705 return; | 667 return; |
| 706 if (m_type == MainResource || m_type == Raw) | 668 if (m_type == MainResource || m_type == Raw || !memoryCache()->contains(this
)) |
| 707 cancelTimerFired(&m_cancelTimer); | 669 cancelTimerFired(&m_cancelTimer); |
| 708 else if (!m_cancelTimer.isActive()) | 670 else if (!m_cancelTimer.isActive()) |
| 709 m_cancelTimer.startOneShot(0, BLINK_FROM_HERE); | 671 m_cancelTimer.startOneShot(0, BLINK_FROM_HERE); |
| 710 | 672 |
| 711 unlock(); | 673 unlock(); |
| 712 } | 674 } |
| 713 | 675 |
| 714 void Resource::cancelTimerFired(Timer<Resource>* timer) | 676 void Resource::cancelTimerFired(Timer<Resource>* timer) |
| 715 { | 677 { |
| 716 ASSERT_UNUSED(timer, timer == &m_cancelTimer); | 678 ASSERT_UNUSED(timer, timer == &m_cancelTimer); |
| 717 if (hasClients() || !m_loader) | 679 if (hasClients() || !m_loader) |
| 718 return; | 680 return; |
| 719 ResourcePtr<Resource> protect(this); | 681 RefPtrWillBeRawPtr<Resource> protect(this); |
| 720 m_loader->cancelIfNotFinishing(); | 682 m_loader->cancelIfNotFinishing(); |
| 721 if (m_status != Cached) | 683 if (m_status != Cached) |
| 722 memoryCache()->remove(this); | 684 memoryCache()->remove(this); |
| 723 } | 685 } |
| 724 | 686 |
| 725 bool Resource::deleteIfPossible() | |
| 726 { | |
| 727 if (canDelete() && !memoryCache()->contains(this)) { | |
| 728 InspectorInstrumentation::willDestroyResource(this); | |
| 729 dispose(); | |
| 730 memoryCache()->unregisterLiveResource(*this); | |
| 731 #if !ENABLE(OILPAN) | |
| 732 delete this; | |
| 733 #endif | |
| 734 return true; | |
| 735 } | |
| 736 return false; | |
| 737 } | |
| 738 | |
| 739 void Resource::setDecodedSize(size_t decodedSize) | 687 void Resource::setDecodedSize(size_t decodedSize) |
| 740 { | 688 { |
| 741 if (decodedSize == m_decodedSize) | 689 if (decodedSize == m_decodedSize) |
| 742 return; | 690 return; |
| 743 size_t oldSize = size(); | 691 size_t oldSize = size(); |
| 744 m_decodedSize = decodedSize; | 692 m_decodedSize = decodedSize; |
| 745 memoryCache()->update(this, oldSize, size()); | 693 memoryCache()->update(this, oldSize, size()); |
| 746 memoryCache()->updateDecodedResource(this, UpdateForPropertyChange); | 694 memoryCache()->updateDecodedResource(this, UpdateForPropertyChange); |
| 747 } | 695 } |
| 748 | 696 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 } | 748 } |
| 801 | 749 |
| 802 void Resource::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfDetail, WebProcess
MemoryDump* memoryDump) const | 750 void Resource::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfDetail, WebProcess
MemoryDump* memoryDump) const |
| 803 { | 751 { |
| 804 static const size_t kMaxURLReportLength = 128; | 752 static const size_t kMaxURLReportLength = 128; |
| 805 static const int kMaxResourceClientToShowInMemoryInfra = 10; | 753 static const int kMaxResourceClientToShowInMemoryInfra = 10; |
| 806 | 754 |
| 807 const String dumpName = getMemoryDumpName(); | 755 const String dumpName = getMemoryDumpName(); |
| 808 WebMemoryAllocatorDump* dump = memoryDump->createMemoryAllocatorDump(dumpNam
e); | 756 WebMemoryAllocatorDump* dump = memoryDump->createMemoryAllocatorDump(dumpNam
e); |
| 809 dump->addScalar("encoded_size", "bytes", m_encodedSize); | 757 dump->addScalar("encoded_size", "bytes", m_encodedSize); |
| 810 if (canDelete()) { | 758 if (m_data && m_data->isLocked()) |
| 759 dump->addScalar("live_size", "bytes", m_encodedSize); |
| 760 else |
| 811 dump->addScalar("dead_size", "bytes", m_encodedSize); | 761 dump->addScalar("dead_size", "bytes", m_encodedSize); |
| 812 } else { | |
| 813 dump->addScalar("live_size", "bytes", m_encodedSize); | |
| 814 } | |
| 815 | 762 |
| 816 if (m_data) { | 763 if (m_data) { |
| 817 dump->addScalar("purgeable_size", "bytes", isPurgeable() && !wasPurged()
? encodedSize() + overheadSize() : 0); | 764 dump->addScalar("purgeable_size", "bytes", isPurgeable() ? encodedSize()
+ overheadSize() : 0); |
| 818 m_data->onMemoryDump(dumpName, memoryDump); | 765 m_data->onMemoryDump(dumpName, memoryDump); |
| 819 } | 766 } |
| 820 | 767 |
| 821 if (levelOfDetail == WebMemoryDumpLevelOfDetail::Detailed) { | 768 if (levelOfDetail == WebMemoryDumpLevelOfDetail::Detailed) { |
| 822 String urlToReport = url().string(); | 769 String urlToReport = url().string(); |
| 823 if (urlToReport.length() > kMaxURLReportLength) { | 770 if (urlToReport.length() > kMaxURLReportLength) { |
| 824 urlToReport.truncate(kMaxURLReportLength); | 771 urlToReport.truncate(kMaxURLReportLength); |
| 825 urlToReport = urlToReport + "..."; | 772 urlToReport = urlToReport + "..."; |
| 826 } | 773 } |
| 827 dump->addString("url", "", urlToReport); | 774 dump->addString("url", "", urlToReport); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 } | 836 } |
| 890 | 837 |
| 891 void Resource::revalidationFailed() | 838 void Resource::revalidationFailed() |
| 892 { | 839 { |
| 893 m_resourceRequest = m_revalidatingRequest; | 840 m_resourceRequest = m_revalidatingRequest; |
| 894 m_revalidatingRequest = ResourceRequest(); | 841 m_revalidatingRequest = ResourceRequest(); |
| 895 m_data.clear(); | 842 m_data.clear(); |
| 896 destroyDecodedDataForFailedRevalidation(); | 843 destroyDecodedDataForFailedRevalidation(); |
| 897 } | 844 } |
| 898 | 845 |
| 899 void Resource::registerHandle(ResourcePtrBase* h) | |
| 900 { | |
| 901 assertAlive(); | |
| 902 ++m_handleCount; | |
| 903 } | |
| 904 | |
| 905 void Resource::unregisterHandle(ResourcePtrBase* h) | |
| 906 { | |
| 907 assertAlive(); | |
| 908 ASSERT(m_handleCount > 0); | |
| 909 --m_handleCount; | |
| 910 | |
| 911 if (!m_handleCount) { | |
| 912 if (deleteIfPossible()) | |
| 913 return; | |
| 914 unlock(); | |
| 915 } else if (m_handleCount == 1 && memoryCache()->contains(this)) { | |
| 916 unlock(); | |
| 917 if (!hasClients()) | |
| 918 memoryCache()->prune(this); | |
| 919 } | |
| 920 } | |
| 921 | |
| 922 bool Resource::canReuseRedirectChain() | 846 bool Resource::canReuseRedirectChain() |
| 923 { | 847 { |
| 924 for (auto& redirect : m_redirectChain) { | 848 for (auto& redirect : m_redirectChain) { |
| 925 if (!canUseResponse(redirect.m_redirectResponse, m_responseTimestamp)) | 849 if (!canUseResponse(redirect.m_redirectResponse, m_responseTimestamp)) |
| 926 return false; | 850 return false; |
| 927 if (redirect.m_request.cacheControlContainsNoCache() || redirect.m_reque
st.cacheControlContainsNoStore()) | 851 if (redirect.m_request.cacheControlContainsNoCache() || redirect.m_reque
st.cacheControlContainsNoStore()) |
| 928 return false; | 852 return false; |
| 929 } | 853 } |
| 930 return true; | 854 return true; |
| 931 } | 855 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 953 if (hasCacheControlNoStoreHeader()) | 877 if (hasCacheControlNoStoreHeader()) |
| 954 return false; | 878 return false; |
| 955 return m_response.hasCacheValidatorFields() || m_resourceRequest.hasCacheVal
idatorFields(); | 879 return m_response.hasCacheValidatorFields() || m_resourceRequest.hasCacheVal
idatorFields(); |
| 956 } | 880 } |
| 957 | 881 |
| 958 bool Resource::isPurgeable() const | 882 bool Resource::isPurgeable() const |
| 959 { | 883 { |
| 960 return m_data && !m_data->isLocked(); | 884 return m_data && !m_data->isLocked(); |
| 961 } | 885 } |
| 962 | 886 |
| 963 bool Resource::wasPurged() const | |
| 964 { | |
| 965 return m_wasPurged; | |
| 966 } | |
| 967 | |
| 968 bool Resource::lock() | 887 bool Resource::lock() |
| 969 { | 888 { |
| 970 if (!m_data) | 889 if (!m_data) |
| 971 return true; | 890 return true; |
| 972 if (m_data->isLocked()) | 891 if (m_data->isLocked()) |
| 973 return true; | 892 return true; |
| 974 | 893 |
| 975 ASSERT(!hasClients()); | 894 ASSERT(!hasClients()); |
| 976 | 895 |
| 896 // If locking fails, our buffer has been purged. There's no point |
| 897 // in leaving a purged resource in MemoryCache. |
| 977 if (!m_data->lock()) { | 898 if (!m_data->lock()) { |
| 978 m_wasPurged = true; | 899 memoryCache()->remove(this); |
| 979 return false; | 900 return false; |
| 980 } | 901 } |
| 981 return true; | 902 return true; |
| 982 } | 903 } |
| 983 | 904 |
| 984 size_t Resource::overheadSize() const | 905 size_t Resource::overheadSize() const |
| 985 { | 906 { |
| 986 static const int kAverageClientsHashMapSize = 384; | 907 static const int kAverageClientsHashMapSize = 384; |
| 987 return sizeof(Resource) + m_response.memoryUsage() + kAverageClientsHashMapS
ize + m_resourceRequest.url().string().length() * 2; | 908 return sizeof(Resource) + m_response.memoryUsage() + kAverageClientsHashMapS
ize + m_resourceRequest.url().string().length() * 2; |
| 988 } | 909 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 m_callbackTaskFactory->cancel(); | 969 m_callbackTaskFactory->cancel(); |
| 1049 } | 970 } |
| 1050 | 971 |
| 1051 bool Resource::ResourceCallback::isScheduled(Resource* resource) const | 972 bool Resource::ResourceCallback::isScheduled(Resource* resource) const |
| 1052 { | 973 { |
| 1053 return m_resourcesWithPendingClients.contains(resource); | 974 return m_resourcesWithPendingClients.contains(resource); |
| 1054 } | 975 } |
| 1055 | 976 |
| 1056 void Resource::ResourceCallback::runTask() | 977 void Resource::ResourceCallback::runTask() |
| 1057 { | 978 { |
| 1058 Vector<ResourcePtr<Resource>> resources; | 979 WillBeHeapVector<RefPtrWillBeMember<Resource>> resources; |
| 1059 for (const RawPtrWillBeMember<Resource>& resource : m_resourcesWithPendingCl
ients) | 980 for (const RefPtrWillBeMember<Resource>& resource : m_resourcesWithPendingCl
ients) |
| 1060 resources.append(resource.get()); | 981 resources.append(resource.get()); |
| 1061 m_resourcesWithPendingClients.clear(); | 982 m_resourcesWithPendingClients.clear(); |
| 1062 | 983 |
| 1063 for (const auto& resource : resources) { | 984 for (const auto& resource : resources) { |
| 1064 resource->assertAlive(); | 985 resource->assertAlive(); |
| 1065 resource->finishPendingClients(); | 986 resource->finishPendingClients(); |
| 1066 resource->assertAlive(); | 987 resource->assertAlive(); |
| 1067 } | 988 } |
| 1068 | 989 |
| 1069 for (const auto& resource : resources) | 990 for (const auto& resource : resources) |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 case Resource::Media: | 1112 case Resource::Media: |
| 1192 return "Media"; | 1113 return "Media"; |
| 1193 case Resource::Manifest: | 1114 case Resource::Manifest: |
| 1194 return "Manifest"; | 1115 return "Manifest"; |
| 1195 } | 1116 } |
| 1196 ASSERT_NOT_REACHED(); | 1117 ASSERT_NOT_REACHED(); |
| 1197 return "Unknown"; | 1118 return "Unknown"; |
| 1198 } | 1119 } |
| 1199 | 1120 |
| 1200 } // namespace blink | 1121 } // namespace blink |
| OLD | NEW |