Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: third_party/WebKit/Source/core/fetch/Resource.cpp

Issue 2253853002: Remove SharedBuffer::unlock() and keep Resource's SharedBuffer always locked (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove Resource::isSafeToUnlock() Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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
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 (m_data)
847 dump->addScalar("live_size", "bytes", m_encodedSize); 822 dump->addScalar("live_size", "bytes", m_encodedSize);
yhirano 2016/08/18 09:28:27 Do these live/dead concepts make sense without isL
hiroshige 2016/08/19 05:37:43 Nice catch. In fact, there seems multiple definiti
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 } 828 }
855 829
856 if (levelOfDetail == WebMemoryDumpLevelOfDetail::Detailed) { 830 if (levelOfDetail == WebMemoryDumpLevelOfDetail::Detailed) {
857 String urlToReport = url().getString(); 831 String urlToReport = url().getString();
858 if (urlToReport.length() > kMaxURLReportLength) { 832 if (urlToReport.length() > kMaxURLReportLength) {
859 urlToReport.truncate(kMaxURLReportLength); 833 urlToReport.truncate(kMaxURLReportLength);
860 urlToReport = urlToReport + "..."; 834 urlToReport = urlToReport + "...";
861 } 835 }
862 dump->addString("url", "", urlToReport); 836 dump->addString("url", "", urlToReport);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 if (hasCacheControlNoStoreHeader()) 950 if (hasCacheControlNoStoreHeader())
977 return false; 951 return false;
978 952
979 // Do not revalidate Resource with redirects. https://crbug.com/613971 953 // Do not revalidate Resource with redirects. https://crbug.com/613971
980 if (!redirectChain().isEmpty()) 954 if (!redirectChain().isEmpty())
981 return false; 955 return false;
982 956
983 return m_response.hasCacheValidatorFields() || m_resourceRequest.hasCacheVal idatorFields(); 957 return m_response.hasCacheValidatorFields() || m_resourceRequest.hasCacheVal idatorFields();
984 } 958 }
985 959
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 960 size_t Resource::calculateOverheadSize() const
1019 { 961 {
1020 static const int kAverageClientsHashMapSize = 384; 962 static const int kAverageClientsHashMapSize = 384;
1021 return sizeof(Resource) + m_response.memoryUsage() + kAverageClientsHashMapS ize + m_resourceRequest.url().getString().length() * 2; 963 return sizeof(Resource) + m_response.memoryUsage() + kAverageClientsHashMapS ize + m_resourceRequest.url().getString().length() * 2;
1022 } 964 }
1023 965
1024 void Resource::didChangePriority(ResourceLoadPriority loadPriority, int intraPri orityValue) 966 void Resource::didChangePriority(ResourceLoadPriority loadPriority, int intraPri orityValue)
1025 { 967 {
1026 m_resourceRequest.setPriority(loadPriority, intraPriorityValue); 968 m_resourceRequest.setPriority(loadPriority, intraPriorityValue);
1027 if (m_loader) 969 if (m_loader)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 case Resource::TextTrack: 1053 case Resource::TextTrack:
1112 case Resource::Media: 1054 case Resource::Media:
1113 case Resource::Manifest: 1055 case Resource::Manifest:
1114 return false; 1056 return false;
1115 } 1057 }
1116 ASSERT_NOT_REACHED(); 1058 ASSERT_NOT_REACHED();
1117 return false; 1059 return false;
1118 } 1060 }
1119 1061
1120 } // namespace blink 1062 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/Resource.h ('k') | third_party/WebKit/Source/core/fetch/ResourceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698