Chromium Code Reviews| 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 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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() | 554 bool Resource::unlock() |
| 555 { | 555 { |
| 556 if (!m_data) | 556 if (!m_data) |
| 557 return false; | 557 return false; |
| 558 | 558 |
| 559 if (!m_data->isLocked()) | |
| 560 return true; | |
| 561 | |
| 562 if (!memoryCache()->contains(this) || hasClientsOrObservers() || !isLoaded() || !isSafeToUnlock()) | 559 if (!memoryCache()->contains(this) || hasClientsOrObservers() || !isLoaded() || !isSafeToUnlock()) |
| 563 return false; | 560 return false; |
| 564 | 561 |
| 565 if (RuntimeEnabledFeatures::doNotUnlockSharedBufferEnabled()) | 562 memoryCache()->remove(this); |
|
haraken
2016/08/17 08:13:31
Would you help me understand why you need to proac
hiroshige
2016/08/17 09:02:38
Because the Resource is not expected to be reused
haraken
2016/08/17 09:10:25
Makes sense.
I'm feeling that whether we call mem
| |
| 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; | 563 return true; |
| 573 } | 564 } |
| 574 | 565 |
| 575 void Resource::responseReceived(const ResourceResponse& response, std::unique_pt r<WebDataConsumerHandle>) | 566 void Resource::responseReceived(const ResourceResponse& response, std::unique_pt r<WebDataConsumerHandle>) |
| 576 { | 567 { |
| 577 m_responseTimestamp = currentTime(); | 568 m_responseTimestamp = currentTime(); |
| 578 if (m_preloadDiscoveryTime) { | 569 if (m_preloadDiscoveryTime) { |
| 579 int timeSinceDiscovery = static_cast<int>(1000 * (monotonicallyIncreasin gTime() - m_preloadDiscoveryTime)); | 570 int timeSinceDiscovery = static_cast<int>(1000 * (monotonicallyIncreasin gTime() - m_preloadDiscoveryTime)); |
| 580 DEFINE_STATIC_LOCAL(CustomCountHistogram, preloadDiscoveryToFirstByteHis togram, ("PreloadScanner.TTFB", 0, 10000, 50)); | 571 DEFINE_STATIC_LOCAL(CustomCountHistogram, preloadDiscoveryToFirstByteHis togram, ("PreloadScanner.TTFB", 0, 10000, 50)); |
| 581 preloadDiscoveryToFirstByteHistogram.count(timeSinceDiscovery); | 572 preloadDiscoveryToFirstByteHistogram.count(timeSinceDiscovery); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 669 return true; | 660 return true; |
| 670 if (type == Resource::Script) | 661 if (type == Resource::Script) |
| 671 return true; | 662 return true; |
| 672 if (type == Resource::Font) | 663 if (type == Resource::Font) |
| 673 return true; | 664 return true; |
| 674 return false; | 665 return false; |
| 675 } | 666 } |
| 676 | 667 |
| 677 void Resource::willAddClientOrObserver() | 668 void Resource::willAddClientOrObserver() |
| 678 { | 669 { |
| 679 ASSERT(!isPurgeable()); | |
| 680 if (m_preloadResult == PreloadNotReferenced) { | 670 if (m_preloadResult == PreloadNotReferenced) { |
| 681 if (isLoaded()) | 671 if (isLoaded()) |
| 682 m_preloadResult = PreloadReferencedWhileComplete; | 672 m_preloadResult = PreloadReferencedWhileComplete; |
| 683 else if (isLoading()) | 673 else if (isLoading()) |
| 684 m_preloadResult = PreloadReferencedWhileLoading; | 674 m_preloadResult = PreloadReferencedWhileLoading; |
| 685 else | 675 else |
| 686 m_preloadResult = PreloadReferenced; | 676 m_preloadResult = PreloadReferenced; |
| 687 | 677 |
| 688 if (m_preloadDiscoveryTime) { | 678 if (m_preloadDiscoveryTime) { |
| 689 int timeSinceDiscovery = static_cast<int>(1000 * (monotonicallyIncre asingTime() - m_preloadDiscoveryTime)); | 679 int timeSinceDiscovery = static_cast<int>(1000 * (monotonicallyIncre asingTime() - m_preloadDiscoveryTime)); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 836 } | 826 } |
| 837 | 827 |
| 838 void Resource::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfDetail, WebProcess MemoryDump* memoryDump) const | 828 void Resource::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfDetail, WebProcess MemoryDump* memoryDump) const |
| 839 { | 829 { |
| 840 static const size_t kMaxURLReportLength = 128; | 830 static const size_t kMaxURLReportLength = 128; |
| 841 static const int kMaxResourceClientToShowInMemoryInfra = 10; | 831 static const int kMaxResourceClientToShowInMemoryInfra = 10; |
| 842 | 832 |
| 843 const String dumpName = getMemoryDumpName(); | 833 const String dumpName = getMemoryDumpName(); |
| 844 WebMemoryAllocatorDump* dump = memoryDump->createMemoryAllocatorDump(dumpNam e); | 834 WebMemoryAllocatorDump* dump = memoryDump->createMemoryAllocatorDump(dumpNam e); |
| 845 dump->addScalar("encoded_size", "bytes", m_encodedSize); | 835 dump->addScalar("encoded_size", "bytes", m_encodedSize); |
| 846 if (m_data && m_data->isLocked()) | 836 if (m_data) |
| 847 dump->addScalar("live_size", "bytes", m_encodedSize); | 837 dump->addScalar("live_size", "bytes", m_encodedSize); |
| 848 else | 838 else |
| 849 dump->addScalar("dead_size", "bytes", m_encodedSize); | 839 dump->addScalar("dead_size", "bytes", m_encodedSize); |
| 850 | 840 |
| 851 if (m_data) { | 841 if (m_data) { |
| 852 dump->addScalar("purgeable_size", "bytes", isPurgeable() ? encodedSize() + overheadSize() : 0); | |
| 853 m_data->onMemoryDump(dumpName, memoryDump); | 842 m_data->onMemoryDump(dumpName, memoryDump); |
| 854 } | 843 } |
| 855 | 844 |
| 856 if (levelOfDetail == WebMemoryDumpLevelOfDetail::Detailed) { | 845 if (levelOfDetail == WebMemoryDumpLevelOfDetail::Detailed) { |
| 857 String urlToReport = url().getString(); | 846 String urlToReport = url().getString(); |
| 858 if (urlToReport.length() > kMaxURLReportLength) { | 847 if (urlToReport.length() > kMaxURLReportLength) { |
| 859 urlToReport.truncate(kMaxURLReportLength); | 848 urlToReport.truncate(kMaxURLReportLength); |
| 860 urlToReport = urlToReport + "..."; | 849 urlToReport = urlToReport + "..."; |
| 861 } | 850 } |
| 862 dump->addString("url", "", urlToReport); | 851 dump->addString("url", "", urlToReport); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 976 if (hasCacheControlNoStoreHeader()) | 965 if (hasCacheControlNoStoreHeader()) |
| 977 return false; | 966 return false; |
| 978 | 967 |
| 979 // Do not revalidate Resource with redirects. https://crbug.com/613971 | 968 // Do not revalidate Resource with redirects. https://crbug.com/613971 |
| 980 if (!redirectChain().isEmpty()) | 969 if (!redirectChain().isEmpty()) |
| 981 return false; | 970 return false; |
| 982 | 971 |
| 983 return m_response.hasCacheValidatorFields() || m_resourceRequest.hasCacheVal idatorFields(); | 972 return m_response.hasCacheValidatorFields() || m_resourceRequest.hasCacheVal idatorFields(); |
| 984 } | 973 } |
| 985 | 974 |
| 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 | 975 size_t Resource::calculateOverheadSize() const |
| 1019 { | 976 { |
| 1020 static const int kAverageClientsHashMapSize = 384; | 977 static const int kAverageClientsHashMapSize = 384; |
| 1021 return sizeof(Resource) + m_response.memoryUsage() + kAverageClientsHashMapS ize + m_resourceRequest.url().getString().length() * 2; | 978 return sizeof(Resource) + m_response.memoryUsage() + kAverageClientsHashMapS ize + m_resourceRequest.url().getString().length() * 2; |
| 1022 } | 979 } |
| 1023 | 980 |
| 1024 void Resource::didChangePriority(ResourceLoadPriority loadPriority, int intraPri orityValue) | 981 void Resource::didChangePriority(ResourceLoadPriority loadPriority, int intraPri orityValue) |
| 1025 { | 982 { |
| 1026 m_resourceRequest.setPriority(loadPriority, intraPriorityValue); | 983 m_resourceRequest.setPriority(loadPriority, intraPriorityValue); |
| 1027 if (m_loader) | 984 if (m_loader) |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1111 case Resource::TextTrack: | 1068 case Resource::TextTrack: |
| 1112 case Resource::Media: | 1069 case Resource::Media: |
| 1113 case Resource::Manifest: | 1070 case Resource::Manifest: |
| 1114 return false; | 1071 return false; |
| 1115 } | 1072 } |
| 1116 ASSERT_NOT_REACHED(); | 1073 ASSERT_NOT_REACHED(); |
| 1117 return false; | 1074 return false; |
| 1118 } | 1075 } |
| 1119 | 1076 |
| 1120 } // namespace blink | 1077 } // namespace blink |
| OLD | NEW |