Chromium Code Reviews| 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..2555f9c58285ee1af3ed41fd1b71520f395915c6 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,16 @@ WebCachePolicy ResourceRequest::getCachePolicy() const { |
| } |
| void ResourceRequest::setCachePolicy(WebCachePolicy cachePolicy) { |
| - m_cachePolicy = cachePolicy; |
| + // TODO(632580): This may be called after cache-aware loading is activated, |
| + // deactivate if cache policy is set to unsupported value. |
| + if (m_isCacheAwareLoadingActivated && |
| + !isCacheAwareLoadingSupported(cachePolicy)) |
| + deactivateCacheAwareLoading(); |
| + |
| + if (m_isCacheAwareLoadingActivated) |
| + m_savedCachePolicy = cachePolicy; |
| + else |
| + m_cachePolicy = cachePolicy; |
| } |
| double ResourceRequest::timeoutInterval() const { |
| @@ -392,6 +405,37 @@ 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; |
|
kouhei (in TOK)
2016/10/20 10:43:07
default:
ASSERT_NOT_REACHED()?
yhirano
2016/10/20 11:07:35
This CL once had the statements but I asked to rem
kouhei (in TOK)
2016/10/20 11:48:42
Got it. Please follow yhirano-san.
|
| + } |
| + return true; |
| +} |
| + |
| +void ResourceRequest::mayActivateCacheAwareLoading() { |
| + DCHECK(!m_isCacheAwareLoadingActivated); |
| + if (!isCacheAwareLoadingSupported(m_cachePolicy)) |
| + return; |
| + |
| + m_savedCachePolicy = m_cachePolicy; |
| + // TODO(652649): Stale data may be retrieved with this flag. Switch to new |
|
kouhei (in TOK)
2016/10/20 10:43:07
TODO(shaochuan): ... crbug.com/652649
Shao-Chuan Lee
2016/10/21 04:35:02
Done.
|
| + // flag to load from disk cache with validation when available in net. |
| + 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 +468,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 |