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

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

Issue 2005753004: Record the number of freshness periods since a stale HttpCache entry was last used (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests Created 4 years, 7 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
« no previous file with comments | « net/http/http_cache_transaction.h ('k') | net/http/mock_http_cache.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" // For OS_POSIX 7 #include "build/build_config.h" // For OS_POSIX
8 8
9 #if defined(OS_POSIX) 9 #if defined(OS_POSIX)
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 // The cache is busy, bypass it for this transaction. 1127 // The cache is busy, bypass it for this transaction.
1128 mode_ = NONE; 1128 mode_ = NONE;
1129 next_state_ = STATE_SEND_REQUEST; 1129 next_state_ = STATE_SEND_REQUEST;
1130 if (partial_) { 1130 if (partial_) {
1131 partial_->RestoreHeaders(&custom_request_->extra_headers); 1131 partial_->RestoreHeaders(&custom_request_->extra_headers);
1132 partial_.reset(); 1132 partial_.reset();
1133 } 1133 }
1134 return OK; 1134 return OK;
1135 } 1135 }
1136 1136
1137 open_entry_last_used_ = entry_->disk_entry->GetLastUsed();
1138
1137 if (result != OK) { 1139 if (result != OK) {
1138 NOTREACHED(); 1140 NOTREACHED();
1139 return result; 1141 return result;
1140 } 1142 }
1141 1143
1142 if (mode_ == WRITE) { 1144 if (mode_ == WRITE) {
1143 if (partial_) 1145 if (partial_)
1144 partial_->RestoreHeaders(&custom_request_->extra_headers); 1146 partial_->RestoreHeaders(&custom_request_->extra_headers);
1145 next_state_ = STATE_SEND_REQUEST; 1147 next_state_ = STATE_SEND_REQUEST;
1146 } else { 1148 } else {
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after
2183 2185
2184 if (request_->method == "PUT" || request_->method == "DELETE") 2186 if (request_->method == "PUT" || request_->method == "DELETE")
2185 return VALIDATION_SYNCHRONOUS; 2187 return VALIDATION_SYNCHRONOUS;
2186 2188
2187 ValidationType validation_required_by_headers = 2189 ValidationType validation_required_by_headers =
2188 response_.headers->RequiresValidation(response_.request_time, 2190 response_.headers->RequiresValidation(response_.request_time,
2189 response_.response_time, 2191 response_.response_time,
2190 cache_->clock_->Now()); 2192 cache_->clock_->Now());
2191 2193
2192 if (validation_required_by_headers != VALIDATION_NONE) { 2194 if (validation_required_by_headers != VALIDATION_NONE) {
2193 validation_cause_ = 2195 HttpResponseHeaders::FreshnessLifetimes lifetimes =
2194 response_.headers->GetFreshnessLifetimes(response_.response_time) 2196 response_.headers->GetFreshnessLifetimes(response_.response_time);
2195 .freshness == base::TimeDelta() 2197 if (lifetimes.freshness == base::TimeDelta()) {
2196 ? VALIDATION_CAUSE_ZERO_FRESHNESS 2198 validation_cause_ = VALIDATION_CAUSE_ZERO_FRESHNESS;
2197 : VALIDATION_CAUSE_STALE; 2199 } else {
2200 validation_cause_ = VALIDATION_CAUSE_STALE;
2201 stale_entry_freshness_ = lifetimes.freshness;
2202 }
2198 } 2203 }
2199 2204
2200 if (validation_required_by_headers == VALIDATION_ASYNCHRONOUS) { 2205 if (validation_required_by_headers == VALIDATION_ASYNCHRONOUS) {
2201 // Asynchronous revalidation is only supported for GET methods. 2206 // Asynchronous revalidation is only supported for GET methods.
2202 if (request_->method != "GET") 2207 if (request_->method != "GET")
2203 return VALIDATION_SYNCHRONOUS; 2208 return VALIDATION_SYNCHRONOUS;
2204 } 2209 }
2205 2210
2206 return validation_required_by_headers; 2211 return validation_required_by_headers;
2207 } 2212 }
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
2783 } else if (mime_type.find("font") != std::string::npos) { 2788 } else if (mime_type.find("font") != std::string::npos) {
2784 UMA_HISTOGRAM_ENUMERATION("HttpCache.Pattern.Font", transaction_pattern_, 2789 UMA_HISTOGRAM_ENUMERATION("HttpCache.Pattern.Font", transaction_pattern_,
2785 PATTERN_MAX); 2790 PATTERN_MAX);
2786 if (validation_request) { 2791 if (validation_request) {
2787 UMA_HISTOGRAM_ENUMERATION("HttpCache.ValidationCause.Font", 2792 UMA_HISTOGRAM_ENUMERATION("HttpCache.ValidationCause.Font",
2788 validation_cause_, VALIDATION_CAUSE_MAX); 2793 validation_cause_, VALIDATION_CAUSE_MAX);
2789 } 2794 }
2790 } 2795 }
2791 } 2796 }
2792 2797
2798 if ((validation_request ||
2799 transaction_pattern_ == PATTERN_ENTRY_CANT_CONDITIONALIZE) &&
2800 validation_cause_ == VALIDATION_CAUSE_STALE) {
2801 // For stale entries, record how many freshness periods have elapsed since
2802 // the entry was last used.
2803 DCHECK(!open_entry_last_used_.is_null());
2804 DCHECK(!stale_entry_freshness_.is_zero());
2805
2806 base::TimeDelta time_since_use = base::Time::Now() - open_entry_last_used_;
2807 UMA_HISTOGRAM_COUNTS("HttpCache.StaleEntry.FreshnessPeriodsSinceLastUsed",
2808 (time_since_use * 1000) / stale_entry_freshness_);
2809 }
2810
2793 UMA_HISTOGRAM_ENUMERATION( 2811 UMA_HISTOGRAM_ENUMERATION(
2794 "HttpCache.Pattern", transaction_pattern_, PATTERN_MAX); 2812 "HttpCache.Pattern", transaction_pattern_, PATTERN_MAX);
2795 2813
2796 if (validation_request) { 2814 if (validation_request) {
2797 UMA_HISTOGRAM_ENUMERATION("HttpCache.ValidationCause", validation_cause_, 2815 UMA_HISTOGRAM_ENUMERATION("HttpCache.ValidationCause", validation_cause_,
2798 VALIDATION_CAUSE_MAX); 2816 VALIDATION_CAUSE_MAX);
2799 } 2817 }
2800 2818
2801 if (transaction_pattern_ == PATTERN_ENTRY_CANT_CONDITIONALIZE) { 2819 if (transaction_pattern_ == PATTERN_ENTRY_CANT_CONDITIONALIZE) {
2802 UMA_HISTOGRAM_ENUMERATION("HttpCache.CantConditionalizeCause", 2820 UMA_HISTOGRAM_ENUMERATION("HttpCache.CantConditionalizeCause",
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
2871 default: 2889 default:
2872 NOTREACHED(); 2890 NOTREACHED();
2873 } 2891 }
2874 } 2892 }
2875 2893
2876 void HttpCache::Transaction::OnIOComplete(int result) { 2894 void HttpCache::Transaction::OnIOComplete(int result) {
2877 DoLoop(result); 2895 DoLoop(result);
2878 } 2896 }
2879 2897
2880 } // namespace net 2898 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_cache_transaction.h ('k') | net/http/mock_http_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698