| 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 "content/browser/download/download_stats.h" | 5 #include "content/browser/download/download_stats.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/metrics/histogram_functions.h" | 8 #include "base/metrics/histogram_functions.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 FILE_PATH_LITERAL(".img"), | 332 FILE_PATH_LITERAL(".img"), |
| 333 FILE_PATH_LITERAL(".imgpart"), | 333 FILE_PATH_LITERAL(".imgpart"), |
| 334 FILE_PATH_LITERAL(".ndif"), | 334 FILE_PATH_LITERAL(".ndif"), |
| 335 FILE_PATH_LITERAL(".smi"), | 335 FILE_PATH_LITERAL(".smi"), |
| 336 FILE_PATH_LITERAL(".sparsebundle"), | 336 FILE_PATH_LITERAL(".sparsebundle"), |
| 337 FILE_PATH_LITERAL(".sparseimage"), | 337 FILE_PATH_LITERAL(".sparseimage"), |
| 338 FILE_PATH_LITERAL(".toast"), | 338 FILE_PATH_LITERAL(".toast"), |
| 339 FILE_PATH_LITERAL(".udif"), | 339 FILE_PATH_LITERAL(".udif"), |
| 340 }; | 340 }; |
| 341 | 341 |
| 342 // The maximum size in KB for the file size metric, file size larger than this |
| 343 // will be kept in overflow bucket. |
| 344 const int64_t kMaxFileSizeKb = 4 * 1024 * 1024; /* 4GB. */ |
| 345 |
| 342 // Maps extensions to their matching UMA histogram int value. | 346 // Maps extensions to their matching UMA histogram int value. |
| 343 int GetDangerousFileType(const base::FilePath& file_path) { | 347 int GetDangerousFileType(const base::FilePath& file_path) { |
| 344 for (size_t i = 0; i < arraysize(kDangerousFileTypes); ++i) { | 348 for (size_t i = 0; i < arraysize(kDangerousFileTypes); ++i) { |
| 345 if (file_path.MatchesExtension(kDangerousFileTypes[i])) | 349 if (file_path.MatchesExtension(kDangerousFileTypes[i])) |
| 346 return i + 1; | 350 return i + 1; |
| 347 } | 351 } |
| 348 return 0; // Unknown extension. | 352 return 0; // Unknown extension. |
| 349 } | 353 } |
| 350 | 354 |
| 351 // Helper method to calculate the bandwidth given the data length and time. | 355 // Helper method to calculate the bandwidth given the data length and time. |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 void RecordParallelDownloadAddStreamSuccess(bool success) { | 793 void RecordParallelDownloadAddStreamSuccess(bool success) { |
| 790 UMA_HISTOGRAM_BOOLEAN("Download.ParallelDownloadAddStreamSuccess", success); | 794 UMA_HISTOGRAM_BOOLEAN("Download.ParallelDownloadAddStreamSuccess", success); |
| 791 } | 795 } |
| 792 | 796 |
| 793 void RecordParallelizableDownloadStats( | 797 void RecordParallelizableDownloadStats( |
| 794 size_t bytes_downloaded_with_parallel_streams, | 798 size_t bytes_downloaded_with_parallel_streams, |
| 795 base::TimeDelta time_with_parallel_streams, | 799 base::TimeDelta time_with_parallel_streams, |
| 796 size_t bytes_downloaded_without_parallel_streams, | 800 size_t bytes_downloaded_without_parallel_streams, |
| 797 base::TimeDelta time_without_parallel_streams, | 801 base::TimeDelta time_without_parallel_streams, |
| 798 bool uses_parallel_requests) { | 802 bool uses_parallel_requests) { |
| 803 RecordParallelizableDownloadAverageStats( |
| 804 bytes_downloaded_with_parallel_streams + |
| 805 bytes_downloaded_without_parallel_streams, |
| 806 time_with_parallel_streams + time_without_parallel_streams); |
| 807 |
| 799 int64_t bandwidth_without_parallel_streams = 0; | 808 int64_t bandwidth_without_parallel_streams = 0; |
| 800 if (bytes_downloaded_without_parallel_streams > 0) { | 809 if (bytes_downloaded_without_parallel_streams > 0) { |
| 801 bandwidth_without_parallel_streams = CalculateBandwidthBytesPerSecond( | 810 bandwidth_without_parallel_streams = CalculateBandwidthBytesPerSecond( |
| 802 bytes_downloaded_without_parallel_streams, | 811 bytes_downloaded_without_parallel_streams, |
| 803 time_without_parallel_streams); | 812 time_without_parallel_streams); |
| 804 if (uses_parallel_requests) { | 813 if (uses_parallel_requests) { |
| 805 RecordBandwidthMetric( | 814 RecordBandwidthMetric( |
| 806 "Download.ParallelizableDownloadBandwidth." | 815 "Download.ParallelizableDownloadBandwidth." |
| 807 "WithParallelRequestsSingleStream", | 816 "WithParallelRequestsSingleStream", |
| 808 bandwidth_without_parallel_streams); | 817 bandwidth_without_parallel_streams); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 UMA_HISTOGRAM_CUSTOM_COUNTS( | 865 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 857 "Download.EstimatedTimeSavedWithParallelDownload", | 866 "Download.EstimatedTimeSavedWithParallelDownload", |
| 858 time_saved.InMilliseconds(), 0, kMillisecondsPerHour, 50); | 867 time_saved.InMilliseconds(), 0, kMillisecondsPerHour, 50); |
| 859 } else { | 868 } else { |
| 860 UMA_HISTOGRAM_CUSTOM_COUNTS( | 869 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 861 "Download.EstimatedTimeWastedWithParallelDownload", | 870 "Download.EstimatedTimeWastedWithParallelDownload", |
| 862 -time_saved.InMilliseconds(), 0, kMillisecondsPerHour, 50); | 871 -time_saved.InMilliseconds(), 0, kMillisecondsPerHour, 50); |
| 863 } | 872 } |
| 864 } | 873 } |
| 865 | 874 |
| 875 void RecordParallelizableDownloadAverageStats( |
| 876 int64_t bytes_downloaded, |
| 877 const base::TimeDelta& time_span) { |
| 878 if (time_span.is_zero() || bytes_downloaded <= 0) |
| 879 return; |
| 880 |
| 881 int64_t average_bandwidth = |
| 882 CalculateBandwidthBytesPerSecond(bytes_downloaded, time_span); |
| 883 int64_t file_size_kb = bytes_downloaded / 1024; |
| 884 RecordBandwidthMetric("Download.ParallelizableDownloadBandwidth", |
| 885 average_bandwidth); |
| 886 UMA_HISTOGRAM_LONG_TIMES("Download.Parallelizable.DownloadTime", time_span); |
| 887 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.Parallelizable.FileSize", file_size_kb, |
| 888 1, kMaxFileSizeKb, 50); |
| 889 } |
| 890 |
| 866 void RecordParallelDownloadCreationEvent(ParallelDownloadCreationEvent event) { | 891 void RecordParallelDownloadCreationEvent(ParallelDownloadCreationEvent event) { |
| 867 UMA_HISTOGRAM_ENUMERATION("Download.ParallelDownload.CreationEvent", event, | 892 UMA_HISTOGRAM_ENUMERATION("Download.ParallelDownload.CreationEvent", event, |
| 868 ParallelDownloadCreationEvent::COUNT); | 893 ParallelDownloadCreationEvent::COUNT); |
| 869 } | 894 } |
| 870 | 895 |
| 871 void RecordDownloadFileRenameResultAfterRetry( | 896 void RecordDownloadFileRenameResultAfterRetry( |
| 872 base::TimeDelta time_since_first_failure, | 897 base::TimeDelta time_since_first_failure, |
| 873 DownloadInterruptReason interrupt_reason) { | 898 DownloadInterruptReason interrupt_reason) { |
| 874 if (interrupt_reason == DOWNLOAD_INTERRUPT_REASON_NONE) { | 899 if (interrupt_reason == DOWNLOAD_INTERRUPT_REASON_NONE) { |
| 875 UMA_HISTOGRAM_TIMES("Download.TimeToRenameSuccessAfterInitialFailure", | 900 UMA_HISTOGRAM_TIMES("Download.TimeToRenameSuccessAfterInitialFailure", |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 } | 977 } |
| 953 | 978 |
| 954 void RecordDownloadHttpResponseCode(int response_code) { | 979 void RecordDownloadHttpResponseCode(int response_code) { |
| 955 UMA_HISTOGRAM_CUSTOM_ENUMERATION( | 980 UMA_HISTOGRAM_CUSTOM_ENUMERATION( |
| 956 "Download.HttpResponseCode", | 981 "Download.HttpResponseCode", |
| 957 net::HttpUtil::MapStatusCodeForHistogram(response_code), | 982 net::HttpUtil::MapStatusCodeForHistogram(response_code), |
| 958 net::HttpUtil::GetStatusCodesForHistogram()); | 983 net::HttpUtil::GetStatusCodesForHistogram()); |
| 959 } | 984 } |
| 960 | 985 |
| 961 } // namespace content | 986 } // namespace content |
| OLD | NEW |