: m_resourceRequest(request)
, m_responseTimestamp(currentTime())
, m_cancelTimer(this, &Resource::cancelTimerFired)
- , m_lastDecodedAccessTime(0)
, m_loadFinishTime(0)
, m_identifier(0)
, m_encodedSize(0)
, m_preloadCount(0)
, m_protectorCount(0)
, m_preloadResult(PreloadNotReferenced)
- , m_cacheLiveResourcePriority(CacheLiveResourcePriorityLow)
, m_requestedFromNetworkingLayer(false)
, m_loading(false)
, m_switchingClientsToRevalidatedResource(false)
return correctedReceivedAge + residentTime;
}
-static double freshnessLifetime(const ResourceResponse& response, double responseTimestamp)
+static double freshnessLifetime(ResourceResponse& response, double responseTimestamp)
{
#if !OS(ANDROID)
// On desktop, local files should be reloaded in case they change.
return 0;
}
-static bool canUseResponse(const ResourceResponse& response, double responseTimestamp)
+static bool canUseResponse(ResourceResponse& response, double responseTimestamp)
{
if (response.isNull())
return false;
return true;
}
+bool Resource::hasRightHandleCountApartFromCache(unsigned targetCount) const
+{
+ return m_handleCount == targetCount + (memoryCache()->contains(this) ? 1 : 0);
+}
+
void Resource::responseReceived(const ResourceResponse& response)
{
setResponse(response);
blink::Platform::current()->cacheMetadata(m_response.url(), m_response.responseTime(), serializedData.data(), serializedData.size());
}
+bool Resource::canDelete() const
+{
+ return !hasClients() && !m_loader && !m_preloadCount && hasRightHandleCountApartFromCache(0)
+ && !m_protectorCount && !m_resourceToRevalidate && !m_proxyResource;
+}
+
+bool Resource::hasOneHandle() const
+{
+ return hasRightHandleCountApartFromCache(1);
+}
+
CachedMetadata* Resource::cachedMetadata(unsigned dataTypeID) const
{
if (!m_cachedMetadata || m_cachedMetadata->dataTypeID() != dataTypeID)
return m_cachedMetadata.get();
}
-void Resource::setCacheLiveResourcePriority(CacheLiveResourcePriority priority)
-{
- if (memoryCache()->contains(this) && memoryCache()->isInLiveDecodedResourcesList(this) && cacheLiveResourcePriority() != static_cast<unsigned>(priority)) {
- memoryCache()->removeFromLiveDecodedResourcesList(this);
- m_cacheLiveResourcePriority = priority;
- memoryCache()->insertInLiveDecodedResourcesList(this);
- memoryCache()->prune();
- }
-}
-
void Resource::clearLoader()
{
m_loader = nullptr;
else
m_preloadResult = PreloadReferenced;
}
- if (!hasClients() && memoryCache()->contains(this))
- memoryCache()->addToLiveResourcesSize(this);
+ if (!hasClients())
+ memoryCache()->makeLive(this);
// If we have existing data to send to the new client and the resource type supprts it, send it asynchronously.
if (!m_response.isNull() && !m_proxyResource && !shouldSendCachedDataSynchronouslyForType(type()) && !m_needsSynchronousCacheHit) {
bool deleted = deleteIfPossible();
if (!deleted && !hasClients()) {
- if (memoryCache()->contains(this)) {
- memoryCache()->removeFromLiveResourcesSize(this);
- memoryCache()->removeFromLiveDecodedResourcesList(this);
- }
+ memoryCache()->makeDead(this);
if (!m_switchingClientsToRevalidatedResource)
allClientsRemoved();
// "no-store: ... MUST make a best-effort attempt to remove the information from volatile storage as promptly as possible"
// "... History buffers MAY store such responses as part of their normal operation."
// We allow non-secure content to be reused in history, but we do not allow secure content to be reused.
- if (response().cacheControlContainsNoStore() && url().protocolIs("https")) {
+ if (hasCacheControlNoStoreHeader() && url().protocolIs("https")) {
memoryCache()->remove(this);
memoryCache()->prune();
} else {
return;
size_t oldSize = size();
m_decodedSize = decodedSize;
-
- if (memoryCache()->contains(this)) {
- // Insert into or remove from the live decoded list if necessary.
- // When inserting into the LiveDecodedResourcesList it is possible
- // that the m_lastDecodedAccessTime is still zero or smaller than
- // the m_lastDecodedAccessTime of the current list head. This is a
- // violation of the invariant that the list is to be kept sorted
- // by access time. The weakening of the invariant does not pose
- // a problem. For more details please see: https://bugs.webkit.org/show_bug.cgi?id=30209
- if (m_decodedSize && !memoryCache()->isInLiveDecodedResourcesList(this) && hasClients())
- memoryCache()->insertInLiveDecodedResourcesList(this);
- else if (!m_decodedSize && memoryCache()->isInLiveDecodedResourcesList(this))
- memoryCache()->removeFromLiveDecodedResourcesList(this);
-
- // Update the cache's size totals.
- memoryCache()->update(this, oldSize, size());
- }
+ memoryCache()->update(this, oldSize, size());
+ memoryCache()->updateDecodedResource(this, UpdateForPropertyChange);
}
void Resource::setEncodedSize(size_t encodedSize)
return;
size_t oldSize = size();
m_encodedSize = encodedSize;
- if (memoryCache()->contains(this))
- memoryCache()->update(this, oldSize, size());
+ memoryCache()->update(this, oldSize, size());
}
-void Resource::didAccessDecodedData(double timeStamp)
+void Resource::didAccessDecodedData()
{
- m_lastDecodedAccessTime = timeStamp;
- if (memoryCache()->contains(this)) {
- if (memoryCache()->isInLiveDecodedResourcesList(this)) {
- memoryCache()->removeFromLiveDecodedResourcesList(this);
- memoryCache()->insertInLiveDecodedResourcesList(this);
- }
- memoryCache()->prune();
- }
+ memoryCache()->updateDecodedResource(this, UpdateForAccess);
+ memoryCache()->prune();
}
void Resource::finishPendingClients()
ASSERT(m_resourceToRevalidate);
ASSERT(!memoryCache()->contains(m_resourceToRevalidate));
ASSERT(m_resourceToRevalidate->isLoaded());
- ASSERT(memoryCache()->contains(this));
// Calling evict() can potentially delete revalidatingResource, which we use
// below. This mustn't be the case since revalidation means it is loaded
unlock();
} else if (m_handleCount == 1 && memoryCache()->contains(this)) {
unlock();
+ if (!hasClients())
+ memoryCache()->prune(this);
}
}
-bool Resource::canReuseRedirectChain() const
+bool Resource::canReuseRedirectChain()
{
for (size_t i = 0; i < m_redirectChain.size(); ++i) {
if (!canUseResponse(m_redirectChain[i].m_redirectResponse, m_responseTimestamp))
return false;
+ if (m_redirectChain[i].m_request.cacheControlContainsNoCache() || m_redirectChain[i].m_request.cacheControlContainsNoStore())
+ return false;
}
return true;
}
-bool Resource::mustRevalidateDueToCacheHeaders() const
+bool Resource::hasCacheControlNoStoreHeader()
+{
+ return m_response.cacheControlContainsNoStore() || m_resourceRequest.cacheControlContainsNoStore();
+}
+
+bool Resource::mustRevalidateDueToCacheHeaders()
{
- return !canUseResponse(m_response, m_responseTimestamp);
+ return !canUseResponse(m_response, m_responseTimestamp) || m_resourceRequest.cacheControlContainsNoCache() || m_resourceRequest.cacheControlContainsNoStore();
}
-bool Resource::canUseCacheValidator() const
+bool Resource::canUseCacheValidator()
{
if (m_loading || errorOccurred())
return false;
- if (m_response.cacheControlContainsNoStore())
+ if (hasCacheControlNoStoreHeader())
return false;
- return m_response.hasCacheValidatorFields();
+ return m_response.hasCacheValidatorFields() || m_resourceRequest.hasCacheValidatorFields();
}
bool Resource::isPurgeable() const
return "Shader";
case Resource::ImportResource:
return "Imported resource";
+ case Resource::Media:
+ return "Media";
}
ASSERT_NOT_REACHED();
return initatorTypeNameToString(initiatorInfo.name);
return "Shader";
case Resource::ImportResource:
return "ImportResource";
+ case Resource::Media:
+ return "Media";
}
ASSERT_NOT_REACHED();
return "Unknown";