+static bool canUseResponse(const ResourceResponse& response, double responseTimestamp)
+{
+ if (response.isNull())
+ return false;
+
+ // FIXME: Why isn't must-revalidate considered a reason we can't use the response?
+ if (response.cacheControlContainsNoCache() || response.cacheControlContainsNoStore())
+ return false;
+
+ if (response.httpStatusCode() == 303) {
+ // Must not be cached.
+ return false;
+ }
+
+ if (response.httpStatusCode() == 302 || response.httpStatusCode() == 307) {
+ // Default to not cacheable.
+ // FIXME: Consider allowing these to be cached if they have headers permitting caching.
+ return false;
+ }
+
+ return currentAge(response, responseTimestamp) <= freshnessLifetime(response, responseTimestamp);
+}
+
+void Resource::willSendRequest(ResourceRequest& request, const ResourceResponse& response)
+{
+ m_redirectChain.append(RedirectPair(request, response));
+ m_requestedFromNetworkingLayer = true;
+}
+
+bool Resource::unlock()
+{
+ if (hasClients() || m_proxyResource || m_resourceToRevalidate || !m_loadFinishTime || !isSafeToUnlock())
+ return false;
+
+ if (m_purgeableData) {
+ ASSERT(!m_data);
+ return true;
+ }
+ if (!m_data)
+ return false;
+
+ // Should not make buffer purgeable if it has refs other than this since we don't want two copies.
+ if (!m_data->hasOneRef())
+ return false;
+
+ m_data->createPurgeableBuffer();
+ if (!m_data->hasPurgeableBuffer())
+ return false;
+
+ m_purgeableData = m_data->releasePurgeableBuffer();
+ m_purgeableData->unlock();
+ m_data.clear();
+ return true;
+}
+