| Index: third_party/WebKit/Source/platform/network/ResourceRequest.cpp
|
| diff --git a/third_party/WebKit/Source/platform/network/ResourceRequest.cpp b/third_party/WebKit/Source/platform/network/ResourceRequest.cpp
|
| index 4d264c050380bd298bae9b62e29b41ddb7e3be49..05c5525b82cba65a89ad1b9e0627fd02369dd6f5 100644
|
| --- a/third_party/WebKit/Source/platform/network/ResourceRequest.cpp
|
| +++ b/third_party/WebKit/Source/platform/network/ResourceRequest.cpp
|
| @@ -88,6 +88,8 @@ ResourceRequest::ResourceRequest(CrossThreadResourceRequestData* data)
|
| m_uiStartTime = data->m_uiStartTime;
|
| m_isExternalRequest = data->m_isExternalRequest;
|
| m_inputPerfMetricReportPolicy = data->m_inputPerfMetricReportPolicy;
|
| + m_isCacheAwareLoadingActivated = data->m_isCacheAwareLoadingActivated;
|
| + m_savedCachePolicy = data->m_savedCachePolicy;
|
| m_redirectStatus = data->m_redirectStatus;
|
| }
|
|
|
| @@ -136,6 +138,8 @@ std::unique_ptr<CrossThreadResourceRequestData> ResourceRequest::copyData()
|
| data->m_uiStartTime = m_uiStartTime;
|
| data->m_isExternalRequest = m_isExternalRequest;
|
| data->m_inputPerfMetricReportPolicy = m_inputPerfMetricReportPolicy;
|
| + data->m_isCacheAwareLoadingActivated = m_isCacheAwareLoadingActivated;
|
| + data->m_savedCachePolicy = m_savedCachePolicy;
|
| data->m_redirectStatus = m_redirectStatus;
|
| return data;
|
| }
|
| @@ -169,7 +173,17 @@ WebCachePolicy ResourceRequest::getCachePolicy() const {
|
| }
|
|
|
| void ResourceRequest::setCachePolicy(WebCachePolicy cachePolicy) {
|
| - m_cachePolicy = cachePolicy;
|
| + // TODO(shaochuan): This may be called after cache-aware loading is activated,
|
| + // deactivate if cache policy is set to unsupported value. Remove after cache
|
| + // policy is only set before cache-aware loading activation. crbug.com/632580
|
| + if (m_isCacheAwareLoadingActivated &&
|
| + !isCacheAwareLoadingSupported(cachePolicy))
|
| + deactivateCacheAwareLoading();
|
| +
|
| + if (m_isCacheAwareLoadingActivated)
|
| + m_savedCachePolicy = cachePolicy;
|
| + else
|
| + m_cachePolicy = cachePolicy;
|
| }
|
|
|
| double ResourceRequest::timeoutInterval() const {
|
| @@ -392,6 +406,38 @@ bool ResourceRequest::hasCacheValidatorFields() const {
|
| !m_httpHeaderFields.get(HTTPNames::ETag).isEmpty();
|
| }
|
|
|
| +bool ResourceRequest::isCacheAwareLoadingSupported(WebCachePolicy cachePolicy) {
|
| + switch (cachePolicy) {
|
| + case WebCachePolicy::BypassingCache:
|
| + case WebCachePolicy::ReturnCacheDataDontLoad:
|
| + return false;
|
| + case WebCachePolicy::UseProtocolCachePolicy:
|
| + case WebCachePolicy::ValidatingCacheData:
|
| + case WebCachePolicy::ReturnCacheDataElseLoad:
|
| + break;
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +void ResourceRequest::mayActivateCacheAwareLoading() {
|
| + DCHECK(!m_isCacheAwareLoadingActivated);
|
| + if (!isCacheAwareLoadingSupported(m_cachePolicy))
|
| + return;
|
| +
|
| + m_savedCachePolicy = m_cachePolicy;
|
| + // TODO(shaochuan): Stale data may be retrieved with this flag. Switch to new
|
| + // flag to load from disk cache with validation when available in net.
|
| + // crbug.com/652649
|
| + m_cachePolicy = WebCachePolicy::ReturnCacheDataDontLoad;
|
| + m_isCacheAwareLoadingActivated = true;
|
| +}
|
| +
|
| +void ResourceRequest::deactivateCacheAwareLoading() {
|
| + DCHECK(m_isCacheAwareLoadingActivated);
|
| + m_cachePolicy = m_savedCachePolicy;
|
| + m_isCacheAwareLoadingActivated = false;
|
| +}
|
| +
|
| void ResourceRequest::initialize(const KURL& url) {
|
| m_url = url;
|
| m_cachePolicy = WebCachePolicy::UseProtocolCachePolicy;
|
| @@ -424,6 +470,8 @@ void ResourceRequest::initialize(const KURL& url) {
|
| m_inputPerfMetricReportPolicy = InputToLoadPerfMetricReportPolicy::NoReport;
|
| m_redirectStatus = RedirectStatus::NoRedirect;
|
| m_requestorOrigin = SecurityOrigin::createUnique();
|
| + m_isCacheAwareLoadingActivated = false;
|
| + m_savedCachePolicy = WebCachePolicy::UseProtocolCachePolicy;
|
| }
|
|
|
| } // namespace blink
|
|
|