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

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

Issue 683113005: Update from chromium https://crrev.com/302282 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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
« no previous file with comments | « net/http/http_cache.cc ('k') | net/http/http_network_transaction.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
11 #endif 11 #endif
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <string> 14 #include <string>
15 15
16 #include "base/bind.h" 16 #include "base/bind.h"
17 #include "base/compiler_specific.h" 17 #include "base/compiler_specific.h"
18 #include "base/format_macros.h" 18 #include "base/format_macros.h"
19 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
20 #include "base/memory/scoped_ptr.h" 20 #include "base/memory/scoped_ptr.h"
21 #include "base/metrics/field_trial.h" 21 #include "base/metrics/field_trial.h"
22 #include "base/metrics/histogram.h" 22 #include "base/metrics/histogram.h"
23 #include "base/metrics/sparse_histogram.h" 23 #include "base/metrics/sparse_histogram.h"
24 #include "base/profiler/scoped_profile.h" 24 #include "base/profiler/scoped_tracker.h"
25 #include "base/rand_util.h" 25 #include "base/rand_util.h"
26 #include "base/strings/string_number_conversions.h" 26 #include "base/strings/string_number_conversions.h"
27 #include "base/strings/string_piece.h" 27 #include "base/strings/string_piece.h"
28 #include "base/strings/string_util.h" 28 #include "base/strings/string_util.h"
29 #include "base/strings/stringprintf.h" 29 #include "base/strings/stringprintf.h"
30 #include "base/time/time.h" 30 #include "base/time/time.h"
31 #include "base/values.h" 31 #include "base/values.h"
32 #include "net/base/completion_callback.h" 32 #include "net/base/completion_callback.h"
33 #include "net/base/io_buffer.h" 33 #include "net/base/io_buffer.h"
34 #include "net/base/load_flags.h" 34 #include "net/base/load_flags.h"
(...skipping 2365 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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
2941 UMA_HISTOGRAM_PERCENTAGE("HttpCache.PercentBeforeSend.Updated", 2941 UMA_HISTOGRAM_PERCENTAGE("HttpCache.PercentBeforeSend.Updated",
2942 before_send_percent); 2942 before_send_percent);
2943 break; 2943 break;
2944 } 2944 }
2945 default: 2945 default:
2946 NOTREACHED(); 2946 NOTREACHED();
2947 } 2947 }
2948 } 2948 }
2949 2949
2950 void HttpCache::Transaction::OnIOComplete(int result) { 2950 void HttpCache::Transaction::OnIOComplete(int result) {
2951 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422516 is fixed. 2951 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed.
2952 tracked_objects::ScopedProfile 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 | « net/http/http_cache.cc ('k') | net/http/http_network_transaction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698