| 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 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 m_redirectChain.append(RedirectPair(newRequest, redirectResponse)); | 544 m_redirectChain.append(RedirectPair(newRequest, redirectResponse)); |
| 545 } | 545 } |
| 546 | 546 |
| 547 void Resource::setResponse(const ResourceResponse& response) | 547 void Resource::setResponse(const ResourceResponse& response) |
| 548 { | 548 { |
| 549 m_response = response; | 549 m_response = response; |
| 550 if (m_response.wasFetchedViaServiceWorker()) | 550 if (m_response.wasFetchedViaServiceWorker()) |
| 551 m_cacheHandler = ServiceWorkerResponseCachedMetadataHandler::create(this
, m_fetcherSecurityOrigin.get()); | 551 m_cacheHandler = ServiceWorkerResponseCachedMetadataHandler::create(this
, m_fetcherSecurityOrigin.get()); |
| 552 } | 552 } |
| 553 | 553 |
| 554 bool Resource::unlock() | |
| 555 { | |
| 556 if (!m_data) | |
| 557 return false; | |
| 558 | |
| 559 if (!m_data->isLocked()) | |
| 560 return true; | |
| 561 | |
| 562 if (!memoryCache()->contains(this) || hasClientsOrObservers() || !isLoaded()
|| !isSafeToUnlock()) | |
| 563 return false; | |
| 564 | |
| 565 if (RuntimeEnabledFeatures::doNotUnlockSharedBufferEnabled()) | |
| 566 return false; | |
| 567 | |
| 568 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, unlockHistogram, new E
numerationHistogram("Blink.SharedBuffer.Unlock", kLastResourceType)); | |
| 569 unlockHistogram.count(getType()); | |
| 570 | |
| 571 m_data->unlock(); | |
| 572 return true; | |
| 573 } | |
| 574 | |
| 575 void Resource::responseReceived(const ResourceResponse& response, std::unique_pt
r<WebDataConsumerHandle>) | 554 void Resource::responseReceived(const ResourceResponse& response, std::unique_pt
r<WebDataConsumerHandle>) |
| 576 { | 555 { |
| 577 m_responseTimestamp = currentTime(); | 556 m_responseTimestamp = currentTime(); |
| 578 if (m_preloadDiscoveryTime) { | 557 if (m_preloadDiscoveryTime) { |
| 579 int timeSinceDiscovery = static_cast<int>(1000 * (monotonicallyIncreasin
gTime() - m_preloadDiscoveryTime)); | 558 int timeSinceDiscovery = static_cast<int>(1000 * (monotonicallyIncreasin
gTime() - m_preloadDiscoveryTime)); |
| 580 DEFINE_STATIC_LOCAL(CustomCountHistogram, preloadDiscoveryToFirstByteHis
togram, ("PreloadScanner.TTFB", 0, 10000, 50)); | 559 DEFINE_STATIC_LOCAL(CustomCountHistogram, preloadDiscoveryToFirstByteHis
togram, ("PreloadScanner.TTFB", 0, 10000, 50)); |
| 581 preloadDiscoveryToFirstByteHistogram.count(timeSinceDiscovery); | 560 preloadDiscoveryToFirstByteHistogram.count(timeSinceDiscovery); |
| 582 } | 561 } |
| 583 | 562 |
| 584 if (m_isRevalidating) { | 563 if (m_isRevalidating) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 return true; | 648 return true; |
| 670 if (type == Resource::Script) | 649 if (type == Resource::Script) |
| 671 return true; | 650 return true; |
| 672 if (type == Resource::Font) | 651 if (type == Resource::Font) |
| 673 return true; | 652 return true; |
| 674 return false; | 653 return false; |
| 675 } | 654 } |
| 676 | 655 |
| 677 void Resource::willAddClientOrObserver() | 656 void Resource::willAddClientOrObserver() |
| 678 { | 657 { |
| 679 ASSERT(!isPurgeable()); | |
| 680 if (m_preloadResult == PreloadNotReferenced) { | 658 if (m_preloadResult == PreloadNotReferenced) { |
| 681 if (isLoaded()) | 659 if (isLoaded()) |
| 682 m_preloadResult = PreloadReferencedWhileComplete; | 660 m_preloadResult = PreloadReferencedWhileComplete; |
| 683 else if (isLoading()) | 661 else if (isLoading()) |
| 684 m_preloadResult = PreloadReferencedWhileLoading; | 662 m_preloadResult = PreloadReferencedWhileLoading; |
| 685 else | 663 else |
| 686 m_preloadResult = PreloadReferenced; | 664 m_preloadResult = PreloadReferenced; |
| 687 | 665 |
| 688 if (m_preloadDiscoveryTime) { | 666 if (m_preloadDiscoveryTime) { |
| 689 int timeSinceDiscovery = static_cast<int>(1000 * (monotonicallyIncre
asingTime() - m_preloadDiscoveryTime)); | 667 int timeSinceDiscovery = static_cast<int>(1000 * (monotonicallyIncre
asingTime() - m_preloadDiscoveryTime)); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 } | 732 } |
| 755 | 733 |
| 756 void Resource::allClientsAndObserversRemoved() | 734 void Resource::allClientsAndObserversRemoved() |
| 757 { | 735 { |
| 758 if (!m_loader) | 736 if (!m_loader) |
| 759 return; | 737 return; |
| 760 if (m_type == Raw) | 738 if (m_type == Raw) |
| 761 cancelTimerFired(&m_cancelTimer); | 739 cancelTimerFired(&m_cancelTimer); |
| 762 else if (!m_cancelTimer.isActive()) | 740 else if (!m_cancelTimer.isActive()) |
| 763 m_cancelTimer.startOneShot(0, BLINK_FROM_HERE); | 741 m_cancelTimer.startOneShot(0, BLINK_FROM_HERE); |
| 764 | |
| 765 unlock(); | |
| 766 } | 742 } |
| 767 | 743 |
| 768 void Resource::cancelTimerFired(TimerBase* timer) | 744 void Resource::cancelTimerFired(TimerBase* timer) |
| 769 { | 745 { |
| 770 ASSERT_UNUSED(timer, timer == &m_cancelTimer); | 746 ASSERT_UNUSED(timer, timer == &m_cancelTimer); |
| 771 if (!hasClientsOrObservers() && m_loader) | 747 if (!hasClientsOrObservers() && m_loader) |
| 772 m_loader->cancel(); | 748 m_loader->cancel(); |
| 773 } | 749 } |
| 774 | 750 |
| 775 void Resource::setDecodedSize(size_t decodedSize) | 751 void Resource::setDecodedSize(size_t decodedSize) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 if (scheduled && m_clientsAwaitingCallback.isEmpty()) | 801 if (scheduled && m_clientsAwaitingCallback.isEmpty()) |
| 826 ResourceCallback::callbackHandler().cancel(this); | 802 ResourceCallback::callbackHandler().cancel(this); |
| 827 | 803 |
| 828 // Prevent the case when there are clients waiting but no callback scheduled
. | 804 // Prevent the case when there are clients waiting but no callback scheduled
. |
| 829 ASSERT(m_clientsAwaitingCallback.isEmpty() || scheduled); | 805 ASSERT(m_clientsAwaitingCallback.isEmpty() || scheduled); |
| 830 } | 806 } |
| 831 | 807 |
| 832 void Resource::prune() | 808 void Resource::prune() |
| 833 { | 809 { |
| 834 destroyDecodedDataIfPossible(); | 810 destroyDecodedDataIfPossible(); |
| 835 unlock(); | |
| 836 } | 811 } |
| 837 | 812 |
| 838 void Resource::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfDetail, WebProcess
MemoryDump* memoryDump) const | 813 void Resource::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfDetail, WebProcess
MemoryDump* memoryDump) const |
| 839 { | 814 { |
| 840 static const size_t kMaxURLReportLength = 128; | 815 static const size_t kMaxURLReportLength = 128; |
| 841 static const int kMaxResourceClientToShowInMemoryInfra = 10; | 816 static const int kMaxResourceClientToShowInMemoryInfra = 10; |
| 842 | 817 |
| 843 const String dumpName = getMemoryDumpName(); | 818 const String dumpName = getMemoryDumpName(); |
| 844 WebMemoryAllocatorDump* dump = memoryDump->createMemoryAllocatorDump(dumpNam
e); | 819 WebMemoryAllocatorDump* dump = memoryDump->createMemoryAllocatorDump(dumpNam
e); |
| 845 dump->addScalar("encoded_size", "bytes", m_encodedSize); | 820 dump->addScalar("encoded_size", "bytes", m_encodedSize); |
| 846 if (m_data && m_data->isLocked()) | 821 if (hasClientsOrObservers()) |
| 847 dump->addScalar("live_size", "bytes", m_encodedSize); | 822 dump->addScalar("live_size", "bytes", m_encodedSize); |
| 848 else | 823 else |
| 849 dump->addScalar("dead_size", "bytes", m_encodedSize); | 824 dump->addScalar("dead_size", "bytes", m_encodedSize); |
| 850 | 825 |
| 851 if (m_data) { | 826 if (m_data) |
| 852 dump->addScalar("purgeable_size", "bytes", isPurgeable() ? encodedSize()
+ overheadSize() : 0); | |
| 853 m_data->onMemoryDump(dumpName, memoryDump); | 827 m_data->onMemoryDump(dumpName, memoryDump); |
| 854 } | |
| 855 | 828 |
| 856 if (levelOfDetail == WebMemoryDumpLevelOfDetail::Detailed) { | 829 if (levelOfDetail == WebMemoryDumpLevelOfDetail::Detailed) { |
| 857 String urlToReport = url().getString(); | 830 String urlToReport = url().getString(); |
| 858 if (urlToReport.length() > kMaxURLReportLength) { | 831 if (urlToReport.length() > kMaxURLReportLength) { |
| 859 urlToReport.truncate(kMaxURLReportLength); | 832 urlToReport.truncate(kMaxURLReportLength); |
| 860 urlToReport = urlToReport + "..."; | 833 urlToReport = urlToReport + "..."; |
| 861 } | 834 } |
| 862 dump->addString("url", "", urlToReport); | 835 dump->addString("url", "", urlToReport); |
| 863 | 836 |
| 864 dump->addString("reason_not_deletable", "", reasonNotDeletable()); | 837 dump->addString("reason_not_deletable", "", reasonNotDeletable()); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 if (hasCacheControlNoStoreHeader()) | 949 if (hasCacheControlNoStoreHeader()) |
| 977 return false; | 950 return false; |
| 978 | 951 |
| 979 // Do not revalidate Resource with redirects. https://crbug.com/613971 | 952 // Do not revalidate Resource with redirects. https://crbug.com/613971 |
| 980 if (!redirectChain().isEmpty()) | 953 if (!redirectChain().isEmpty()) |
| 981 return false; | 954 return false; |
| 982 | 955 |
| 983 return m_response.hasCacheValidatorFields() || m_resourceRequest.hasCacheVal
idatorFields(); | 956 return m_response.hasCacheValidatorFields() || m_resourceRequest.hasCacheVal
idatorFields(); |
| 984 } | 957 } |
| 985 | 958 |
| 986 bool Resource::isPurgeable() const | |
| 987 { | |
| 988 return m_data && !m_data->isLocked(); | |
| 989 } | |
| 990 | |
| 991 bool Resource::lock() | |
| 992 { | |
| 993 if (!m_data) | |
| 994 return true; | |
| 995 if (m_data->isLocked()) | |
| 996 return true; | |
| 997 | |
| 998 ASSERT(!hasClientsOrObservers()); | |
| 999 | |
| 1000 // If locking fails, our buffer has been purged. There's no point | |
| 1001 // in leaving a purged resource in MemoryCache. | |
| 1002 if (!m_data->lock()) { | |
| 1003 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, failedLockHistogra
m, new EnumerationHistogram("Blink.SharedBuffer.FailedLock", kLastResourceType))
; | |
| 1004 failedLockHistogram.count(getType()); | |
| 1005 | |
| 1006 m_data.clear(); | |
| 1007 setEncodedSize(0); | |
| 1008 memoryCache()->remove(this); | |
| 1009 return false; | |
| 1010 } | |
| 1011 | |
| 1012 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, successfulLockHistogra
m, new EnumerationHistogram("Blink.SharedBuffer.SuccessfulLock", kLastResourceTy
pe)); | |
| 1013 successfulLockHistogram.count(getType()); | |
| 1014 | |
| 1015 return true; | |
| 1016 } | |
| 1017 | |
| 1018 size_t Resource::calculateOverheadSize() const | 959 size_t Resource::calculateOverheadSize() const |
| 1019 { | 960 { |
| 1020 static const int kAverageClientsHashMapSize = 384; | 961 static const int kAverageClientsHashMapSize = 384; |
| 1021 return sizeof(Resource) + m_response.memoryUsage() + kAverageClientsHashMapS
ize + m_resourceRequest.url().getString().length() * 2; | 962 return sizeof(Resource) + m_response.memoryUsage() + kAverageClientsHashMapS
ize + m_resourceRequest.url().getString().length() * 2; |
| 1022 } | 963 } |
| 1023 | 964 |
| 1024 void Resource::didChangePriority(ResourceLoadPriority loadPriority, int intraPri
orityValue) | 965 void Resource::didChangePriority(ResourceLoadPriority loadPriority, int intraPri
orityValue) |
| 1025 { | 966 { |
| 1026 m_resourceRequest.setPriority(loadPriority, intraPriorityValue); | 967 m_resourceRequest.setPriority(loadPriority, intraPriorityValue); |
| 1027 if (m_loader) | 968 if (m_loader) |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 case Resource::TextTrack: | 1052 case Resource::TextTrack: |
| 1112 case Resource::Media: | 1053 case Resource::Media: |
| 1113 case Resource::Manifest: | 1054 case Resource::Manifest: |
| 1114 return false; | 1055 return false; |
| 1115 } | 1056 } |
| 1116 ASSERT_NOT_REACHED(); | 1057 ASSERT_NOT_REACHED(); |
| 1117 return false; | 1058 return false; |
| 1118 } | 1059 } |
| 1119 | 1060 |
| 1120 } // namespace blink | 1061 } // namespace blink |
| OLD | NEW |