| 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 "chrome/browser/net/chrome_network_delegate.h" | 5 #include "chrome/browser/net/chrome_network_delegate.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include <limits> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/base_paths.h" | 12 #include "base/base_paths.h" |
| 12 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 15 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 16 #include "base/prefs/pref_member.h" | 17 #include "base/prefs/pref_member.h" |
| 17 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
| 18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 Profile* profile) { | 266 Profile* profile) { |
| 266 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 267 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 267 base::Bind(&UpdateContentLengthPrefs, | 268 base::Bind(&UpdateContentLengthPrefs, |
| 268 received_content_length, original_content_length, | 269 received_content_length, original_content_length, |
| 269 data_reduction_type, profile)); | 270 data_reduction_type, profile)); |
| 270 } | 271 } |
| 271 | 272 |
| 272 void RecordContentLengthHistograms( | 273 void RecordContentLengthHistograms( |
| 273 int64 received_content_length, | 274 int64 received_content_length, |
| 274 int64 original_content_length, | 275 int64 original_content_length, |
| 275 const base::TimeDelta& freshness_lifetime) { | 276 base::TimeDelta freshness_lifetime, |
| 277 bool has_finite_freshness_lifetime) { |
| 276 #if defined(OS_ANDROID) | 278 #if defined(OS_ANDROID) |
| 277 // Add the current resource to these histograms only when a valid | 279 // Add the current resource to these histograms only when a valid |
| 278 // X-Original-Content-Length header is present. | 280 // X-Original-Content-Length header is present. |
| 279 if (original_content_length >= 0) { | 281 if (original_content_length >= 0) { |
| 280 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthWithValidOCL", | 282 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthWithValidOCL", |
| 281 received_content_length); | 283 received_content_length); |
| 282 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLengthWithValidOCL", | 284 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLengthWithValidOCL", |
| 283 original_content_length); | 285 original_content_length); |
| 284 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifferenceWithValidOCL", | 286 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifferenceWithValidOCL", |
| 285 original_content_length - received_content_length); | 287 original_content_length - received_content_length); |
| 286 } else { | 288 } else { |
| 287 // Presume the original content length is the same as the received content | 289 // Presume the original content length is the same as the received content |
| 288 // length if the X-Original-Content-Header is not present. | 290 // length if the X-Original-Content-Header is not present. |
| 289 original_content_length = received_content_length; | 291 original_content_length = received_content_length; |
| 290 } | 292 } |
| 291 UMA_HISTOGRAM_COUNTS("Net.HttpContentLength", received_content_length); | 293 UMA_HISTOGRAM_COUNTS("Net.HttpContentLength", received_content_length); |
| 292 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLength", | 294 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLength", |
| 293 original_content_length); | 295 original_content_length); |
| 294 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifference", | 296 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifference", |
| 295 original_content_length - received_content_length); | 297 original_content_length - received_content_length); |
| 298 |
| 299 const double freshness_lifetime_seconds = |
| 300 has_finite_freshness_lifetime ? freshness_lifetime.InSeconds() : |
| 301 std::numeric_limit<double>::max(); |
| 296 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.HttpContentFreshnessLifetime", | 302 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.HttpContentFreshnessLifetime", |
| 297 freshness_lifetime.InSeconds(), | 303 freshness_lifetime_seconds, |
| 298 base::TimeDelta::FromHours(1).InSeconds(), | 304 base::TimeDelta::FromHours(1).InSeconds(), |
| 299 base::TimeDelta::FromDays(30).InSeconds(), | 305 base::TimeDelta::FromDays(30).InSeconds(), |
| 300 100); | 306 100); |
| 301 if (freshness_lifetime.InSeconds() <= 0) | 307 if (freshness_lifetime.InSeconds() <= 0) |
| 302 return; | 308 return; |
| 303 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable", | 309 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable", |
| 304 received_content_length); | 310 received_content_length); |
| 305 if (freshness_lifetime.InHours() < 4) | 311 if (freshness_lifetime.InHours() < 4) |
| 306 return; | 312 return; |
| 307 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable4Hours", | 313 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable4Hours", |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 | 575 |
| 570 if (!request->was_cached() && // Don't record cached content | 576 if (!request->was_cached() && // Don't record cached content |
| 571 received_content_length && // Zero-byte responses aren't useful. | 577 received_content_length && // Zero-byte responses aren't useful. |
| 572 (is_http || is_https)) { // Only record for HTTP or HTTPS urls. | 578 (is_http || is_https)) { // Only record for HTTP or HTTPS urls. |
| 573 int64 original_content_length = | 579 int64 original_content_length = |
| 574 request->response_info().headers->GetInt64HeaderValue( | 580 request->response_info().headers->GetInt64HeaderValue( |
| 575 "x-original-content-length"); | 581 "x-original-content-length"); |
| 576 spdyproxy::DataReductionRequestType data_reduction_type = | 582 spdyproxy::DataReductionRequestType data_reduction_type = |
| 577 spdyproxy::GetDataReductionRequestType(request); | 583 spdyproxy::GetDataReductionRequestType(request); |
| 578 | 584 |
| 579 base::TimeDelta freshness_lifetime = | |
| 580 request->response_info().headers->GetFreshnessLifetime( | |
| 581 request->response_info().response_time); | |
| 582 int64 adjusted_original_content_length = | 585 int64 adjusted_original_content_length = |
| 583 spdyproxy::GetAdjustedOriginalContentLength( | 586 spdyproxy::GetAdjustedOriginalContentLength( |
| 584 data_reduction_type, original_content_length, | 587 data_reduction_type, original_content_length, |
| 585 received_content_length); | 588 received_content_length); |
| 586 AccumulateContentLength(received_content_length, | 589 AccumulateContentLength(received_content_length, |
| 587 adjusted_original_content_length, | 590 adjusted_original_content_length, |
| 588 data_reduction_type); | 591 data_reduction_type); |
| 592 base::TimeDelta freshness_lifetime; |
| 593 bool has_finite_freshness_lifetime; |
| 594 request->response_info().headers->GetFreshnessLifetime( |
| 595 request->response_info().response_time, |
| 596 &freshness_lifetime, &has_finite_freshness_lifetime); |
| 589 RecordContentLengthHistograms(received_content_length, | 597 RecordContentLengthHistograms(received_content_length, |
| 590 original_content_length, | 598 original_content_length, |
| 591 freshness_lifetime); | 599 freshness_lifetime, |
| 600 has_finite_freshness_lifetime); |
| 592 DVLOG(2) << __FUNCTION__ | 601 DVLOG(2) << __FUNCTION__ |
| 593 << " received content length: " << received_content_length | 602 << " received content length: " << received_content_length |
| 594 << " original content length: " << original_content_length | 603 << " original content length: " << original_content_length |
| 595 << " url: " << request->url(); | 604 << " url: " << request->url(); |
| 596 } | 605 } |
| 597 | 606 |
| 598 bool is_redirect = request->response_headers() && | 607 bool is_redirect = request->response_headers() && |
| 599 net::HttpResponseHeaders::IsRedirectResponseCode( | 608 net::HttpResponseHeaders::IsRedirectResponseCode( |
| 600 request->response_headers()->response_code()); | 609 request->response_headers()->response_code()); |
| 601 if (!is_redirect) { | 610 if (!is_redirect) { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 spdyproxy::DataReductionRequestType data_reduction_type) { | 809 spdyproxy::DataReductionRequestType data_reduction_type) { |
| 801 DCHECK_GE(received_content_length, 0); | 810 DCHECK_GE(received_content_length, 0); |
| 802 DCHECK_GE(original_content_length, 0); | 811 DCHECK_GE(original_content_length, 0); |
| 803 StoreAccumulatedContentLength(received_content_length, | 812 StoreAccumulatedContentLength(received_content_length, |
| 804 original_content_length, | 813 original_content_length, |
| 805 data_reduction_type, | 814 data_reduction_type, |
| 806 reinterpret_cast<Profile*>(profile_)); | 815 reinterpret_cast<Profile*>(profile_)); |
| 807 received_content_length_ += received_content_length; | 816 received_content_length_ += received_content_length; |
| 808 original_content_length_ += original_content_length; | 817 original_content_length_ += original_content_length; |
| 809 } | 818 } |
| OLD | NEW |