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

Side by Side Diff: net/http/http_cache_transaction.cc

Issue 665023002: Post-commit fixes for "stale-while-revalidate..." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 6 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_cache_transaction.h" 5 #include "net/http/http_cache_transaction.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_POSIX) 9 #if defined(OS_POSIX)
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 2389 matching lines...) Expand 10 before | Expand all | Expand 10 after
2400 request_ = custom_request_.get(); 2400 request_ = custom_request_.get();
2401 } 2401 }
2402 DCHECK(custom_request_.get()); 2402 DCHECK(custom_request_.get());
2403 2403
2404 bool use_if_range = partial_.get() && !partial_->IsCurrentRangeCached() && 2404 bool use_if_range = partial_.get() && !partial_->IsCurrentRangeCached() &&
2405 !invalid_range_; 2405 !invalid_range_;
2406 2406
2407 if (!use_if_range) { 2407 if (!use_if_range) {
2408 // stale-while-revalidate is not useful when we only have a partial response 2408 // stale-while-revalidate is not useful when we only have a partial response
2409 // cached, so don't set the header in that case. 2409 // cached, so don't set the header in that case.
2410 HttpResponseHeaders::FreshnessLifetimes lifetime = 2410 HttpResponseHeaders::FreshnessLifetimes lifetimes =
2411 response_.headers->GetFreshnessLifetimes(response_.response_time); 2411 response_.headers->GetFreshnessLifetimes(response_.response_time);
2412 if (lifetime.stale > TimeDelta()) { 2412 if (lifetimes.staleness > TimeDelta()) {
2413 TimeDelta current_age = response_.headers->GetCurrentAge( 2413 TimeDelta current_age = response_.headers->GetCurrentAge(
2414 response_.request_time, response_.response_time, Time::Now()); 2414 response_.request_time, response_.response_time, Time::Now());
2415 2415
2416 custom_request_->extra_headers.SetHeader( 2416 custom_request_->extra_headers.SetHeader(
2417 kFreshnessHeader, 2417 kFreshnessHeader,
2418 base::StringPrintf("max-age=%" PRId64 2418 base::StringPrintf("max-age=%" PRId64
2419 ",stale-while-revalidate=%" PRId64 ",age=%" PRId64, 2419 ",stale-while-revalidate=%" PRId64 ",age=%" PRId64,
2420 lifetime.fresh.InSeconds(), 2420 lifetimes.freshness.InSeconds(),
2421 lifetime.stale.InSeconds(), 2421 lifetimes.staleness.InSeconds(),
2422 current_age.InSeconds())); 2422 current_age.InSeconds()));
2423 } 2423 }
2424 } 2424 }
2425 2425
2426 if (!etag_value.empty()) { 2426 if (!etag_value.empty()) {
2427 if (use_if_range) { 2427 if (use_if_range) {
2428 // We don't want to switch to WRITE mode if we don't have this block of a 2428 // We don't want to switch to WRITE mode if we don't have this block of a
2429 // byte-range request because we may have other parts cached. 2429 // byte-range request because we may have other parts cached.
2430 custom_request_->extra_headers.SetHeader( 2430 custom_request_->extra_headers.SetHeader(
2431 HttpRequestHeaders::kIfRange, etag_value); 2431 HttpRequestHeaders::kIfRange, etag_value);
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
2949 2949
2950 void HttpCache::Transaction::OnIOComplete(int result) { 2950 void HttpCache::Transaction::OnIOComplete(int result) {
2951 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. 2951 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed.
2952 tracked_objects::ScopedTracker tracking_profile( 2952 tracked_objects::ScopedTracker tracking_profile(
2953 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 Transaction::OnIOComplete")); 2953 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 Transaction::OnIOComplete"));
2954 2954
2955 DoLoop(result); 2955 DoLoop(result);
2956 } 2956 }
2957 2957
2958 } // namespace net 2958 } // namespace net
OLDNEW
« no previous file with comments | « chrome/browser/predictors/resource_prefetch_predictor.cc ('k') | net/http/http_response_headers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698