Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 963 return cache_->OpenEntry(cache_key_, &new_entry_, this); | 963 return cache_->OpenEntry(cache_key_, &new_entry_, this); |
| 964 } | 964 } |
| 965 | 965 |
| 966 int HttpCache::Transaction::DoOpenEntryComplete(int result) { | 966 int HttpCache::Transaction::DoOpenEntryComplete(int result) { |
| 967 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is | 967 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is |
| 968 // OK, otherwise the cache will end up with an active entry without any | 968 // OK, otherwise the cache will end up with an active entry without any |
| 969 // transaction attached. | 969 // transaction attached. |
| 970 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, result); | 970 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, result); |
| 971 cache_pending_ = false; | 971 cache_pending_ = false; |
| 972 if (result == OK) { | 972 if (result == OK) { |
| 973 open_entry_last_used_ = new_entry_->disk_entry->GetLastUsed(); | |
| 973 next_state_ = STATE_ADD_TO_ENTRY; | 974 next_state_ = STATE_ADD_TO_ENTRY; |
| 974 return OK; | 975 return OK; |
| 975 } | 976 } |
| 976 | 977 |
| 977 if (result == ERR_CACHE_RACE) { | 978 if (result == ERR_CACHE_RACE) { |
| 978 next_state_ = STATE_INIT_ENTRY; | 979 next_state_ = STATE_INIT_ENTRY; |
| 979 return OK; | 980 return OK; |
| 980 } | 981 } |
| 981 | 982 |
| 982 if (request_->method == "PUT" || request_->method == "DELETE" || | 983 if (request_->method == "PUT" || request_->method == "DELETE" || |
| (...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2183 | 2184 |
| 2184 if (request_->method == "PUT" || request_->method == "DELETE") | 2185 if (request_->method == "PUT" || request_->method == "DELETE") |
| 2185 return VALIDATION_SYNCHRONOUS; | 2186 return VALIDATION_SYNCHRONOUS; |
| 2186 | 2187 |
| 2187 ValidationType validation_required_by_headers = | 2188 ValidationType validation_required_by_headers = |
| 2188 response_.headers->RequiresValidation(response_.request_time, | 2189 response_.headers->RequiresValidation(response_.request_time, |
| 2189 response_.response_time, | 2190 response_.response_time, |
| 2190 cache_->clock_->Now()); | 2191 cache_->clock_->Now()); |
| 2191 | 2192 |
| 2192 if (validation_required_by_headers != VALIDATION_NONE) { | 2193 if (validation_required_by_headers != VALIDATION_NONE) { |
| 2193 validation_cause_ = | 2194 HttpResponseHeaders::FreshnessLifetimes lifetimes = |
| 2194 response_.headers->GetFreshnessLifetimes(response_.response_time) | 2195 response_.headers->GetFreshnessLifetimes(response_.response_time); |
| 2195 .freshness == base::TimeDelta() | 2196 if (lifetimes.freshness == base::TimeDelta()) { |
| 2196 ? VALIDATION_CAUSE_ZERO_FRESHNESS | 2197 validation_cause_ = VALIDATION_CAUSE_ZERO_FRESHNESS; |
| 2197 : VALIDATION_CAUSE_STALE; | 2198 } else { |
| 2199 validation_cause_ = VALIDATION_CAUSE_STALE; | |
| 2200 stale_entry_freshness_ = lifetimes.freshness; | |
| 2201 } | |
| 2198 } | 2202 } |
| 2199 | 2203 |
| 2200 if (validation_required_by_headers == VALIDATION_ASYNCHRONOUS) { | 2204 if (validation_required_by_headers == VALIDATION_ASYNCHRONOUS) { |
| 2201 // Asynchronous revalidation is only supported for GET methods. | 2205 // Asynchronous revalidation is only supported for GET methods. |
| 2202 if (request_->method != "GET") | 2206 if (request_->method != "GET") |
| 2203 return VALIDATION_SYNCHRONOUS; | 2207 return VALIDATION_SYNCHRONOUS; |
| 2204 } | 2208 } |
| 2205 | 2209 |
| 2206 return validation_required_by_headers; | 2210 return validation_required_by_headers; |
| 2207 } | 2211 } |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2783 } else if (mime_type.find("font") != std::string::npos) { | 2787 } else if (mime_type.find("font") != std::string::npos) { |
| 2784 UMA_HISTOGRAM_ENUMERATION("HttpCache.Pattern.Font", transaction_pattern_, | 2788 UMA_HISTOGRAM_ENUMERATION("HttpCache.Pattern.Font", transaction_pattern_, |
| 2785 PATTERN_MAX); | 2789 PATTERN_MAX); |
| 2786 if (validation_request) { | 2790 if (validation_request) { |
| 2787 UMA_HISTOGRAM_ENUMERATION("HttpCache.ValidationCause.Font", | 2791 UMA_HISTOGRAM_ENUMERATION("HttpCache.ValidationCause.Font", |
| 2788 validation_cause_, VALIDATION_CAUSE_MAX); | 2792 validation_cause_, VALIDATION_CAUSE_MAX); |
| 2789 } | 2793 } |
| 2790 } | 2794 } |
| 2791 } | 2795 } |
| 2792 | 2796 |
| 2797 if ((validation_request || | |
| 2798 transaction_pattern_ == PATTERN_ENTRY_CANT_CONDITIONALIZE) && | |
| 2799 validation_cause_ == VALIDATION_CAUSE_STALE) { | |
| 2800 DCHECK(!open_entry_last_used_.is_null()); | |
| 2801 DCHECK(!stale_entry_freshness_.is_zero()); | |
| 2802 | |
| 2803 base::TimeDelta time_since_use = base::Time::Now() - open_entry_last_used_; | |
| 2804 UMA_HISTOGRAM_COUNTS("HttpCache.StaleEntry.FreshnessPeriodsSinceLastUsed", | |
| 2805 (time_since_use * 1000) / stale_entry_freshness_); | |
|
rkaplow
2016/05/24 17:43:25
instead of doing this, I think you want millisecon
jkarlin
2016/05/24 17:57:40
I see why the 1000 is making you think of millisec
jkarlin
2016/05/24 18:38:30
I've added a comment to clarify what's being recor
| |
| 2806 } | |
| 2807 | |
| 2793 UMA_HISTOGRAM_ENUMERATION( | 2808 UMA_HISTOGRAM_ENUMERATION( |
| 2794 "HttpCache.Pattern", transaction_pattern_, PATTERN_MAX); | 2809 "HttpCache.Pattern", transaction_pattern_, PATTERN_MAX); |
| 2795 | 2810 |
| 2796 if (validation_request) { | 2811 if (validation_request) { |
| 2797 UMA_HISTOGRAM_ENUMERATION("HttpCache.ValidationCause", validation_cause_, | 2812 UMA_HISTOGRAM_ENUMERATION("HttpCache.ValidationCause", validation_cause_, |
| 2798 VALIDATION_CAUSE_MAX); | 2813 VALIDATION_CAUSE_MAX); |
| 2799 } | 2814 } |
| 2800 | 2815 |
| 2801 if (transaction_pattern_ == PATTERN_ENTRY_CANT_CONDITIONALIZE) { | 2816 if (transaction_pattern_ == PATTERN_ENTRY_CANT_CONDITIONALIZE) { |
| 2802 UMA_HISTOGRAM_ENUMERATION("HttpCache.CantConditionalizeCause", | 2817 UMA_HISTOGRAM_ENUMERATION("HttpCache.CantConditionalizeCause", |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2871 default: | 2886 default: |
| 2872 NOTREACHED(); | 2887 NOTREACHED(); |
| 2873 } | 2888 } |
| 2874 } | 2889 } |
| 2875 | 2890 |
| 2876 void HttpCache::Transaction::OnIOComplete(int result) { | 2891 void HttpCache::Transaction::OnIOComplete(int result) { |
| 2877 DoLoop(result); | 2892 DoLoop(result); |
| 2878 } | 2893 } |
| 2879 | 2894 |
| 2880 } // namespace net | 2895 } // namespace net |
| OLD | NEW |