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/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "content/browser/download/download_resource_handler.h" | 9 #include "content/browser/download/download_resource_handler.h" |
10 #include "content/public/browser/download_interrupt_reasons.h" | 10 #include "content/public/browser/download_interrupt_reasons.h" |
| 11 #include "net/http/http_content_disposition.h" |
11 | 12 |
12 namespace content { | 13 namespace content { |
13 | 14 |
| 15 namespace { |
| 16 |
14 // All possible error codes from the network module. Note that the error codes | 17 // All possible error codes from the network module. Note that the error codes |
15 // are all positive (since histograms expect positive sample values). | 18 // are all positive (since histograms expect positive sample values). |
16 const int kAllInterruptReasonCodes[] = { | 19 const int kAllInterruptReasonCodes[] = { |
17 #define INTERRUPT_REASON(label, value) (value), | 20 #define INTERRUPT_REASON(label, value) (value), |
18 #include "content/public/browser/download_interrupt_reason_values.h" | 21 #include "content/public/browser/download_interrupt_reason_values.h" |
19 #undef INTERRUPT_REASON | 22 #undef INTERRUPT_REASON |
20 }; | 23 }; |
21 | 24 |
| 25 // These values are based on net::HttpContentDisposition::ParseResult values. |
| 26 // Values other than HEADER_PRESENT and IS_VALID are only measured if |IS_VALID| |
| 27 // is true. |
| 28 enum ContentDispositionCountTypes { |
| 29 // Count of downloads which had a Content-Disposition headers. The total |
| 30 // number of downloads is measured by UNTHROTTLED_COUNT. |
| 31 CONTENT_DISPOSITION_HEADER_PRESENT = 0, |
| 32 |
| 33 // At least one of 'name', 'filename' or 'filenae*' attributes were valid and |
| 34 // yielded a non-empty filename. |
| 35 CONTENT_DISPOSITION_IS_VALID, |
| 36 |
| 37 // The following enum values correspond to |
| 38 // net::HttpContentDisposition::ParseResult. |
| 39 CONTENT_DISPOSITION_HAS_DISPOSITION_TYPE, |
| 40 CONTENT_DISPOSITION_HAS_UNKNOWN_TYPE, |
| 41 CONTENT_DISPOSITION_HAS_NAME, |
| 42 CONTENT_DISPOSITION_HAS_FILENAME, |
| 43 CONTENT_DISPOSITION_HAS_EXT_FILENAME, |
| 44 CONTENT_DISPOSITION_HAS_NON_ASCII_STRINGS, |
| 45 CONTENT_DISPOSITION_HAS_PERCENT_ENCODED_STRINGS, |
| 46 CONTENT_DISPOSITION_HAS_RFC2047_ENCODED_STRINGS, |
| 47 |
| 48 // Only have the 'name' attribute is present. |
| 49 CONTENT_DISPOSITION_HAS_NAME_ONLY, |
| 50 |
| 51 CONTENT_DISPOSITION_LAST_ENTRY |
| 52 }; |
| 53 |
| 54 void RecordContentDispositionCount(ContentDispositionCountTypes type, |
| 55 bool record) { |
| 56 if (!record) |
| 57 return; |
| 58 UMA_HISTOGRAM_ENUMERATION( |
| 59 "Download.ContentDisposition", type, CONTENT_DISPOSITION_LAST_ENTRY); |
| 60 } |
| 61 |
| 62 void RecordContentDispositionCountFlag( |
| 63 ContentDispositionCountTypes type, |
| 64 int flags_to_test, |
| 65 net::HttpContentDisposition::ParseResultFlags flag) { |
| 66 RecordContentDispositionCount(type, (flags_to_test & flag) == flag); |
| 67 } |
| 68 |
| 69 } // namespace |
| 70 |
22 void RecordDownloadCount(DownloadCountTypes type) { | 71 void RecordDownloadCount(DownloadCountTypes type) { |
23 UMA_HISTOGRAM_ENUMERATION( | 72 UMA_HISTOGRAM_ENUMERATION( |
24 "Download.Counts", type, DOWNLOAD_COUNT_TYPES_LAST_ENTRY); | 73 "Download.Counts", type, DOWNLOAD_COUNT_TYPES_LAST_ENTRY); |
25 } | 74 } |
26 | 75 |
27 void RecordDownloadSource(DownloadSource source) { | 76 void RecordDownloadSource(DownloadSource source) { |
28 UMA_HISTOGRAM_ENUMERATION( | 77 UMA_HISTOGRAM_ENUMERATION( |
29 "Download.Sources", source, DOWNLOAD_SOURCE_LAST_ENTRY); | 78 "Download.Sources", source, DOWNLOAD_SOURCE_LAST_ENTRY); |
30 } | 79 } |
31 | 80 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 download_content = DOWNLOAD_CONTENT_VIDEO; | 294 download_content = DOWNLOAD_CONTENT_VIDEO; |
246 } | 295 } |
247 } | 296 } |
248 | 297 |
249 // Record the value. | 298 // Record the value. |
250 UMA_HISTOGRAM_ENUMERATION("Download.ContentType", | 299 UMA_HISTOGRAM_ENUMERATION("Download.ContentType", |
251 download_content, | 300 download_content, |
252 DOWNLOAD_CONTENT_MAX); | 301 DOWNLOAD_CONTENT_MAX); |
253 } | 302 } |
254 | 303 |
| 304 void RecordDownloadContentDisposition( |
| 305 const std::string& content_disposition_string) { |
| 306 if (content_disposition_string.empty()) |
| 307 return; |
| 308 net::HttpContentDisposition content_disposition( |
| 309 content_disposition_string, ""); |
| 310 int result = content_disposition.parse_result_flags(); |
| 311 |
| 312 bool is_valid = !content_disposition.filename().empty(); |
| 313 RecordContentDispositionCount(CONTENT_DISPOSITION_HEADER_PRESENT, true); |
| 314 RecordContentDispositionCount(CONTENT_DISPOSITION_IS_VALID, is_valid); |
| 315 if (!is_valid) |
| 316 return; |
| 317 |
| 318 RecordContentDispositionCountFlag( |
| 319 CONTENT_DISPOSITION_HAS_DISPOSITION_TYPE, result, |
| 320 net::HttpContentDisposition::HAS_DISPOSITION_TYPE); |
| 321 RecordContentDispositionCountFlag( |
| 322 CONTENT_DISPOSITION_HAS_UNKNOWN_TYPE, result, |
| 323 net::HttpContentDisposition::HAS_UNKNOWN_DISPOSITION_TYPE); |
| 324 RecordContentDispositionCountFlag( |
| 325 CONTENT_DISPOSITION_HAS_NAME, result, |
| 326 net::HttpContentDisposition::HAS_NAME); |
| 327 RecordContentDispositionCountFlag( |
| 328 CONTENT_DISPOSITION_HAS_FILENAME, result, |
| 329 net::HttpContentDisposition::HAS_FILENAME); |
| 330 RecordContentDispositionCountFlag( |
| 331 CONTENT_DISPOSITION_HAS_EXT_FILENAME, result, |
| 332 net::HttpContentDisposition::HAS_EXT_FILENAME); |
| 333 RecordContentDispositionCountFlag( |
| 334 CONTENT_DISPOSITION_HAS_NON_ASCII_STRINGS, result, |
| 335 net::HttpContentDisposition::HAS_NON_ASCII_STRINGS); |
| 336 RecordContentDispositionCountFlag( |
| 337 CONTENT_DISPOSITION_HAS_PERCENT_ENCODED_STRINGS, result, |
| 338 net::HttpContentDisposition::HAS_PERCENT_ENCODED_STRINGS); |
| 339 RecordContentDispositionCountFlag( |
| 340 CONTENT_DISPOSITION_HAS_RFC2047_ENCODED_STRINGS, result, |
| 341 net::HttpContentDisposition::HAS_RFC2047_ENCODED_STRINGS); |
| 342 |
| 343 RecordContentDispositionCount( |
| 344 CONTENT_DISPOSITION_HAS_NAME_ONLY, |
| 345 (result & (net::HttpContentDisposition::HAS_NAME | |
| 346 net::HttpContentDisposition::HAS_FILENAME | |
| 347 net::HttpContentDisposition::HAS_EXT_FILENAME)) == |
| 348 net::HttpContentDisposition::HAS_NAME); |
| 349 } |
| 350 |
255 void RecordFileThreadReceiveBuffers(size_t num_buffers) { | 351 void RecordFileThreadReceiveBuffers(size_t num_buffers) { |
256 UMA_HISTOGRAM_CUSTOM_COUNTS( | 352 UMA_HISTOGRAM_CUSTOM_COUNTS( |
257 "Download.FileThreadReceiveBuffers", num_buffers, 1, | 353 "Download.FileThreadReceiveBuffers", num_buffers, 1, |
258 100, 100); | 354 100, 100); |
259 } | 355 } |
260 | 356 |
261 void RecordBandwidth(double actual_bandwidth, double potential_bandwidth) { | 357 void RecordBandwidth(double actual_bandwidth, double potential_bandwidth) { |
262 UMA_HISTOGRAM_CUSTOM_COUNTS( | 358 UMA_HISTOGRAM_CUSTOM_COUNTS( |
263 "Download.ActualBandwidth", actual_bandwidth, 1, 1000000000, 50); | 359 "Download.ActualBandwidth", actual_bandwidth, 1, 1000000000, 50); |
264 UMA_HISTOGRAM_CUSTOM_COUNTS( | 360 UMA_HISTOGRAM_CUSTOM_COUNTS( |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 disk_write_time_ms * 100 / elapsed_time_ms); | 428 disk_write_time_ms * 100 / elapsed_time_ms); |
333 } | 429 } |
334 | 430 |
335 void RecordSavePackageEvent(SavePackageEvent event) { | 431 void RecordSavePackageEvent(SavePackageEvent event) { |
336 UMA_HISTOGRAM_ENUMERATION("Download.SavePackage", | 432 UMA_HISTOGRAM_ENUMERATION("Download.SavePackage", |
337 event, | 433 event, |
338 SAVE_PACKAGE_LAST_ENTRY); | 434 SAVE_PACKAGE_LAST_ENTRY); |
339 } | 435 } |
340 | 436 |
341 } // namespace content | 437 } // namespace content |
OLD | NEW |