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

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: Make DCHECK_EQ work for TimeDelta objects. Created 6 years, 2 months 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 2386 matching lines...) Expand 10 before | Expand all | Expand 10 after
2397 request_ = custom_request_.get(); 2397 request_ = custom_request_.get();
2398 } 2398 }
2399 DCHECK(custom_request_.get()); 2399 DCHECK(custom_request_.get());
2400 2400
2401 bool use_if_range = partial_.get() && !partial_->IsCurrentRangeCached() && 2401 bool use_if_range = partial_.get() && !partial_->IsCurrentRangeCached() &&
2402 !invalid_range_; 2402 !invalid_range_;
2403 2403
2404 if (!use_if_range) { 2404 if (!use_if_range) {
2405 // stale-while-revalidate is not useful when we only have a partial response 2405 // stale-while-revalidate is not useful when we only have a partial response
2406 // cached, so don't set the header in that case. 2406 // cached, so don't set the header in that case.
2407 HttpResponseHeaders::FreshnessLifetimes lifetime = 2407 HttpResponseHeaders::FreshnessLifetimes lifetimes =
2408 response_.headers->GetFreshnessLifetimes(response_.response_time); 2408 response_.headers->GetFreshnessLifetimes(response_.response_time);
2409 if (lifetime.stale > TimeDelta()) { 2409 if (lifetimes.staleness > TimeDelta()) {
2410 TimeDelta current_age = response_.headers->GetCurrentAge( 2410 TimeDelta current_age = response_.headers->GetCurrentAge(
2411 response_.request_time, response_.response_time, Time::Now()); 2411 response_.request_time, response_.response_time, Time::Now());
2412 2412
2413 custom_request_->extra_headers.SetHeader( 2413 custom_request_->extra_headers.SetHeader(
2414 kFreshnessHeader, 2414 kFreshnessHeader,
2415 base::StringPrintf("max-age=%" PRId64 2415 base::StringPrintf("max-age=%" PRId64
2416 ",stale-while-revalidate=%" PRId64 ",age=%" PRId64, 2416 ",stale-while-revalidate=%" PRId64 ",age=%" PRId64,
2417 lifetime.fresh.InSeconds(), 2417 lifetimes.freshness.InSeconds(),
2418 lifetime.stale.InSeconds(), 2418 lifetimes.staleness.InSeconds(),
2419 current_age.InSeconds())); 2419 current_age.InSeconds()));
2420 } 2420 }
2421 } 2421 }
2422 2422
2423 if (!etag_value.empty()) { 2423 if (!etag_value.empty()) {
2424 if (use_if_range) { 2424 if (use_if_range) {
2425 // We don't want to switch to WRITE mode if we don't have this block of a 2425 // We don't want to switch to WRITE mode if we don't have this block of a
2426 // byte-range request because we may have other parts cached. 2426 // byte-range request because we may have other parts cached.
2427 custom_request_->extra_headers.SetHeader( 2427 custom_request_->extra_headers.SetHeader(
2428 HttpRequestHeaders::kIfRange, etag_value); 2428 HttpRequestHeaders::kIfRange, etag_value);
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
2946 2946
2947 void HttpCache::Transaction::OnIOComplete(int result) { 2947 void HttpCache::Transaction::OnIOComplete(int result) {
2948 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422516 is fixed. 2948 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422516 is fixed.
2949 tracked_objects::ScopedProfile tracking_profile( 2949 tracked_objects::ScopedProfile tracking_profile(
2950 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 Transaction::OnIOComplete")); 2950 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 Transaction::OnIOComplete"));
2951 2951
2952 DoLoop(result); 2952 DoLoop(result);
2953 } 2953 }
2954 2954
2955 } // namespace net 2955 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698