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

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

Issue 179943002: MemoryCache: make sure that Resources are evicted only when they can be deleted (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 6 years, 9 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
« no previous file with comments | « Source/core/fetch/Resource.h ('k') | Source/core/fetch/ResourceFetcher.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 if (!m_data->isLocked()) 357 if (!m_data->isLocked())
358 return true; 358 return true;
359 359
360 if (!memoryCache()->contains(this) || hasClients() || m_handleCount > 1 || m _proxyResource || m_resourceToRevalidate || !m_loadFinishTime || !isSafeToUnlock ()) 360 if (!memoryCache()->contains(this) || hasClients() || m_handleCount > 1 || m _proxyResource || m_resourceToRevalidate || !m_loadFinishTime || !isSafeToUnlock ())
361 return false; 361 return false;
362 362
363 m_data->unlock(); 363 m_data->unlock();
364 return true; 364 return true;
365 } 365 }
366 366
367 bool Resource::hasRightHandleCountApartFromCache(unsigned targetCount) const
368 {
369 return m_handleCount == targetCount + memoryCache()->contains(this);
370 }
371
367 void Resource::responseReceived(const ResourceResponse& response) 372 void Resource::responseReceived(const ResourceResponse& response)
368 { 373 {
369 setResponse(response); 374 setResponse(response);
370 m_responseTimestamp = currentTime(); 375 m_responseTimestamp = currentTime();
371 String encoding = response.textEncodingName(); 376 String encoding = response.textEncodingName();
372 if (!encoding.isNull()) 377 if (!encoding.isNull())
373 setEncoding(encoding); 378 setEncoding(encoding);
374 379
375 if (!m_resourceToRevalidate) 380 if (!m_resourceToRevalidate)
376 return; 381 return;
(...skipping 19 matching lines...) Expand all
396 // Currently, only one type of cached metadata per resource is supported. 401 // Currently, only one type of cached metadata per resource is supported.
397 // If the need arises for multiple types of metadata per resource this could 402 // If the need arises for multiple types of metadata per resource this could
398 // be enhanced to store types of metadata in a map. 403 // be enhanced to store types of metadata in a map.
399 ASSERT(!m_cachedMetadata); 404 ASSERT(!m_cachedMetadata);
400 405
401 m_cachedMetadata = CachedMetadata::create(dataTypeID, data, size); 406 m_cachedMetadata = CachedMetadata::create(dataTypeID, data, size);
402 const Vector<char>& serializedData = m_cachedMetadata->serialize(); 407 const Vector<char>& serializedData = m_cachedMetadata->serialize();
403 blink::Platform::current()->cacheMetadata(m_response.url(), m_response.respo nseTime(), serializedData.data(), serializedData.size()); 408 blink::Platform::current()->cacheMetadata(m_response.url(), m_response.respo nseTime(), serializedData.data(), serializedData.size());
404 } 409 }
405 410
411 bool Resource::canDelete() const
412 {
413 return !hasClients() && !m_loader && !m_preloadCount && hasRightHandleCountA partFromCache(0)
414 && !m_protectorCount && !m_resourceToRevalidate && !m_proxyResource;
415 }
416
417 bool Resource::hasOneHandleApartFromCache() const
418 {
419 return hasRightHandleCountApartFromCache(1);
420 }
421
406 CachedMetadata* Resource::cachedMetadata(unsigned dataTypeID) const 422 CachedMetadata* Resource::cachedMetadata(unsigned dataTypeID) const
407 { 423 {
408 if (!m_cachedMetadata || m_cachedMetadata->dataTypeID() != dataTypeID) 424 if (!m_cachedMetadata || m_cachedMetadata->dataTypeID() != dataTypeID)
409 return 0; 425 return 0;
410 return m_cachedMetadata.get(); 426 return m_cachedMetadata.get();
411 } 427 }
412 428
413 void Resource::setCacheLiveResourcePriority(CacheLiveResourcePriority priority) 429 void Resource::setCacheLiveResourcePriority(CacheLiveResourcePriority priority)
414 { 430 {
415 if (memoryCache()->contains(this) && memoryCache()->isInLiveDecodedResources List(this) && cacheLiveResourcePriority() != static_cast<unsigned>(priority)) { 431 if (memoryCache()->contains(this) && memoryCache()->isInLiveDecodedResources List(this) && cacheLiveResourcePriority() != static_cast<unsigned>(priority)) {
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 780
765 if (m_resourceToRevalidate) 781 if (m_resourceToRevalidate)
766 m_handlesToRevalidate.remove(h); 782 m_handlesToRevalidate.remove(h);
767 783
768 if (!m_handleCount) { 784 if (!m_handleCount) {
769 if (deleteIfPossible()) 785 if (deleteIfPossible())
770 return; 786 return;
771 unlock(); 787 unlock();
772 } else if (m_handleCount == 1 && memoryCache()->contains(this)) { 788 } else if (m_handleCount == 1 && memoryCache()->contains(this)) {
773 unlock(); 789 unlock();
790 if (!hasClients())
791 memoryCache()->prune(this);
774 } 792 }
775 } 793 }
776 794
777 bool Resource::canReuseRedirectChain() const 795 bool Resource::canReuseRedirectChain() const
778 { 796 {
779 for (size_t i = 0; i < m_redirectChain.size(); ++i) { 797 for (size_t i = 0; i < m_redirectChain.size(); ++i) {
780 if (!canUseResponse(m_redirectChain[i].m_redirectResponse, m_responseTim estamp)) 798 if (!canUseResponse(m_redirectChain[i].m_redirectResponse, m_responseTim estamp))
781 return false; 799 return false;
782 } 800 }
783 return true; 801 return true;
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 return "Shader"; 992 return "Shader";
975 case Resource::ImportResource: 993 case Resource::ImportResource:
976 return "ImportResource"; 994 return "ImportResource";
977 } 995 }
978 ASSERT_NOT_REACHED(); 996 ASSERT_NOT_REACHED();
979 return "Unknown"; 997 return "Unknown";
980 } 998 }
981 #endif // !LOG_DISABLED 999 #endif // !LOG_DISABLED
982 1000
983 } 1001 }
OLDNEW
« no previous file with comments | « Source/core/fetch/Resource.h ('k') | Source/core/fetch/ResourceFetcher.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698