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

Side by Side Diff: third_party/WebKit/Source/platform/network/ResourceRequest.cpp

Issue 2390583002: [WIP] WebFonts cache-aware timeout adaption (Closed)
Patch Set: check ERR_CACHE_MISS directly in ResourceError Created 4 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2009, 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2009, 2012 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 setFetchRequestMode(data->m_fetchRequestMode); 81 setFetchRequestMode(data->m_fetchRequestMode);
82 setFetchCredentialsMode(data->m_fetchCredentialsMode); 82 setFetchCredentialsMode(data->m_fetchCredentialsMode);
83 setFetchRedirectMode(data->m_fetchRedirectMode); 83 setFetchRedirectMode(data->m_fetchRedirectMode);
84 setLoFiState(data->m_loFiState); 84 setLoFiState(data->m_loFiState);
85 m_referrerPolicy = data->m_referrerPolicy; 85 m_referrerPolicy = data->m_referrerPolicy;
86 m_didSetHTTPReferrer = data->m_didSetHTTPReferrer; 86 m_didSetHTTPReferrer = data->m_didSetHTTPReferrer;
87 m_checkForBrowserSideNavigation = data->m_checkForBrowserSideNavigation; 87 m_checkForBrowserSideNavigation = data->m_checkForBrowserSideNavigation;
88 m_uiStartTime = data->m_uiStartTime; 88 m_uiStartTime = data->m_uiStartTime;
89 m_isExternalRequest = data->m_isExternalRequest; 89 m_isExternalRequest = data->m_isExternalRequest;
90 m_inputPerfMetricReportPolicy = data->m_inputPerfMetricReportPolicy; 90 m_inputPerfMetricReportPolicy = data->m_inputPerfMetricReportPolicy;
91 m_isCacheAwareLoadingActivated = data->m_isCacheAwareLoadingActivated;
92 m_savedCachePolicy = data->m_savedCachePolicy;
91 m_redirectStatus = data->m_redirectStatus; 93 m_redirectStatus = data->m_redirectStatus;
92 } 94 }
93 95
94 ResourceRequest::ResourceRequest(const ResourceRequest&) = default; 96 ResourceRequest::ResourceRequest(const ResourceRequest&) = default;
95 97
96 ResourceRequest& ResourceRequest::operator=(const ResourceRequest&) = default; 98 ResourceRequest& ResourceRequest::operator=(const ResourceRequest&) = default;
97 99
98 std::unique_ptr<CrossThreadResourceRequestData> ResourceRequest::copyData() 100 std::unique_ptr<CrossThreadResourceRequestData> ResourceRequest::copyData()
99 const { 101 const {
100 std::unique_ptr<CrossThreadResourceRequestData> data = 102 std::unique_ptr<CrossThreadResourceRequestData> data =
(...skipping 28 matching lines...) Expand all
129 data->m_fetchRequestMode = m_fetchRequestMode; 131 data->m_fetchRequestMode = m_fetchRequestMode;
130 data->m_fetchCredentialsMode = m_fetchCredentialsMode; 132 data->m_fetchCredentialsMode = m_fetchCredentialsMode;
131 data->m_fetchRedirectMode = m_fetchRedirectMode; 133 data->m_fetchRedirectMode = m_fetchRedirectMode;
132 data->m_loFiState = m_loFiState; 134 data->m_loFiState = m_loFiState;
133 data->m_referrerPolicy = m_referrerPolicy; 135 data->m_referrerPolicy = m_referrerPolicy;
134 data->m_didSetHTTPReferrer = m_didSetHTTPReferrer; 136 data->m_didSetHTTPReferrer = m_didSetHTTPReferrer;
135 data->m_checkForBrowserSideNavigation = m_checkForBrowserSideNavigation; 137 data->m_checkForBrowserSideNavigation = m_checkForBrowserSideNavigation;
136 data->m_uiStartTime = m_uiStartTime; 138 data->m_uiStartTime = m_uiStartTime;
137 data->m_isExternalRequest = m_isExternalRequest; 139 data->m_isExternalRequest = m_isExternalRequest;
138 data->m_inputPerfMetricReportPolicy = m_inputPerfMetricReportPolicy; 140 data->m_inputPerfMetricReportPolicy = m_inputPerfMetricReportPolicy;
141 data->m_isCacheAwareLoadingActivated = m_isCacheAwareLoadingActivated;
142 data->m_savedCachePolicy = m_savedCachePolicy;
139 data->m_redirectStatus = m_redirectStatus; 143 data->m_redirectStatus = m_redirectStatus;
140 return data; 144 return data;
141 } 145 }
142 146
143 bool ResourceRequest::isEmpty() const { 147 bool ResourceRequest::isEmpty() const {
144 return m_url.isEmpty(); 148 return m_url.isEmpty();
145 } 149 }
146 150
147 bool ResourceRequest::isNull() const { 151 bool ResourceRequest::isNull() const {
148 return m_url.isNull(); 152 return m_url.isNull();
(...skipping 13 matching lines...) Expand all
162 166
163 m_url.setUser(String()); 167 m_url.setUser(String());
164 m_url.setPass(String()); 168 m_url.setPass(String());
165 } 169 }
166 170
167 WebCachePolicy ResourceRequest::getCachePolicy() const { 171 WebCachePolicy ResourceRequest::getCachePolicy() const {
168 return m_cachePolicy; 172 return m_cachePolicy;
169 } 173 }
170 174
171 void ResourceRequest::setCachePolicy(WebCachePolicy cachePolicy) { 175 void ResourceRequest::setCachePolicy(WebCachePolicy cachePolicy) {
172 m_cachePolicy = cachePolicy; 176 // TODO(shaochuan): This may be called after cache-aware loading is activated,
177 // deactivate if cache policy is set to unsupported value. Remove after cache
178 // policy is only set before cache-aware loading activation. crbug.com/632580
179 if (m_isCacheAwareLoadingActivated &&
180 !isCacheAwareLoadingSupported(cachePolicy))
181 deactivateCacheAwareLoading();
182
183 if (m_isCacheAwareLoadingActivated)
184 m_savedCachePolicy = cachePolicy;
185 else
186 m_cachePolicy = cachePolicy;
173 } 187 }
174 188
175 double ResourceRequest::timeoutInterval() const { 189 double ResourceRequest::timeoutInterval() const {
176 return m_timeoutInterval; 190 return m_timeoutInterval;
177 } 191 }
178 192
179 void ResourceRequest::setTimeoutInterval(double timoutIntervalSeconds) { 193 void ResourceRequest::setTimeoutInterval(double timoutIntervalSeconds) {
180 m_timeoutInterval = timoutIntervalSeconds; 194 m_timeoutInterval = timoutIntervalSeconds;
181 } 195 }
182 196
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 399
386 bool ResourceRequest::cacheControlContainsNoStore() const { 400 bool ResourceRequest::cacheControlContainsNoStore() const {
387 return cacheControlHeader().containsNoStore; 401 return cacheControlHeader().containsNoStore;
388 } 402 }
389 403
390 bool ResourceRequest::hasCacheValidatorFields() const { 404 bool ResourceRequest::hasCacheValidatorFields() const {
391 return !m_httpHeaderFields.get(HTTPNames::Last_Modified).isEmpty() || 405 return !m_httpHeaderFields.get(HTTPNames::Last_Modified).isEmpty() ||
392 !m_httpHeaderFields.get(HTTPNames::ETag).isEmpty(); 406 !m_httpHeaderFields.get(HTTPNames::ETag).isEmpty();
393 } 407 }
394 408
409 bool ResourceRequest::isCacheAwareLoadingSupported(WebCachePolicy cachePolicy) {
410 switch (cachePolicy) {
411 case WebCachePolicy::BypassingCache:
412 case WebCachePolicy::ReturnCacheDataDontLoad:
413 return false;
414 case WebCachePolicy::UseProtocolCachePolicy:
415 case WebCachePolicy::ValidatingCacheData:
416 case WebCachePolicy::ReturnCacheDataElseLoad:
417 break;
418 }
419 return true;
420 }
421
422 void ResourceRequest::mayActivateCacheAwareLoading() {
423 DCHECK(!m_isCacheAwareLoadingActivated);
424 if (!isCacheAwareLoadingSupported(m_cachePolicy))
425 return;
426
427 m_savedCachePolicy = m_cachePolicy;
428 // TODO(shaochuan): Stale data may be retrieved with this flag. Switch to new
429 // flag to load from disk cache with validation when available in net.
430 // crbug.com/652649
431 m_cachePolicy = WebCachePolicy::ReturnCacheDataDontLoad;
432 m_isCacheAwareLoadingActivated = true;
433 }
434
435 void ResourceRequest::deactivateCacheAwareLoading() {
436 DCHECK(m_isCacheAwareLoadingActivated);
437 m_cachePolicy = m_savedCachePolicy;
438 m_isCacheAwareLoadingActivated = false;
439 }
440
395 void ResourceRequest::initialize(const KURL& url) { 441 void ResourceRequest::initialize(const KURL& url) {
396 m_url = url; 442 m_url = url;
397 m_cachePolicy = WebCachePolicy::UseProtocolCachePolicy; 443 m_cachePolicy = WebCachePolicy::UseProtocolCachePolicy;
398 m_timeoutInterval = s_defaultTimeoutInterval; 444 m_timeoutInterval = s_defaultTimeoutInterval;
399 m_httpMethod = HTTPNames::GET; 445 m_httpMethod = HTTPNames::GET;
400 m_allowStoredCredentials = true; 446 m_allowStoredCredentials = true;
401 m_reportUploadProgress = false; 447 m_reportUploadProgress = false;
402 m_reportRawHeaders = false; 448 m_reportRawHeaders = false;
403 m_hasUserGesture = false; 449 m_hasUserGesture = false;
404 m_downloadToFile = false; 450 m_downloadToFile = false;
(...skipping 12 matching lines...) Expand all
417 m_fetchRedirectMode = WebURLRequest::FetchRedirectModeFollow; 463 m_fetchRedirectMode = WebURLRequest::FetchRedirectModeFollow;
418 m_referrerPolicy = ReferrerPolicyDefault; 464 m_referrerPolicy = ReferrerPolicyDefault;
419 m_loFiState = WebURLRequest::LoFiUnspecified; 465 m_loFiState = WebURLRequest::LoFiUnspecified;
420 m_didSetHTTPReferrer = false; 466 m_didSetHTTPReferrer = false;
421 m_checkForBrowserSideNavigation = true; 467 m_checkForBrowserSideNavigation = true;
422 m_uiStartTime = 0; 468 m_uiStartTime = 0;
423 m_isExternalRequest = false; 469 m_isExternalRequest = false;
424 m_inputPerfMetricReportPolicy = InputToLoadPerfMetricReportPolicy::NoReport; 470 m_inputPerfMetricReportPolicy = InputToLoadPerfMetricReportPolicy::NoReport;
425 m_redirectStatus = RedirectStatus::NoRedirect; 471 m_redirectStatus = RedirectStatus::NoRedirect;
426 m_requestorOrigin = SecurityOrigin::createUnique(); 472 m_requestorOrigin = SecurityOrigin::createUnique();
473 m_isCacheAwareLoadingActivated = false;
474 m_savedCachePolicy = WebCachePolicy::UseProtocolCachePolicy;
427 } 475 }
428 476
429 } // namespace blink 477 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698