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

Side by Side Diff: content/browser/download/download_stats.cc

Issue 11478034: Add UMA for measuring Content-Dispostion header use and abuse. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Only measure valid C-D headers Created 8 years 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 | Annotate | Revision Log
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 "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 } // namespace
63
22 void RecordDownloadCount(DownloadCountTypes type) { 64 void RecordDownloadCount(DownloadCountTypes type) {
23 UMA_HISTOGRAM_ENUMERATION( 65 UMA_HISTOGRAM_ENUMERATION(
24 "Download.Counts", type, DOWNLOAD_COUNT_TYPES_LAST_ENTRY); 66 "Download.Counts", type, DOWNLOAD_COUNT_TYPES_LAST_ENTRY);
25 } 67 }
26 68
27 void RecordDownloadSource(DownloadSource source) { 69 void RecordDownloadSource(DownloadSource source) {
28 UMA_HISTOGRAM_ENUMERATION( 70 UMA_HISTOGRAM_ENUMERATION(
29 "Download.Sources", source, DOWNLOAD_SOURCE_LAST_ENTRY); 71 "Download.Sources", source, DOWNLOAD_SOURCE_LAST_ENTRY);
30 } 72 }
31 73
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 download_content = DOWNLOAD_CONTENT_VIDEO; 287 download_content = DOWNLOAD_CONTENT_VIDEO;
246 } 288 }
247 } 289 }
248 290
249 // Record the value. 291 // Record the value.
250 UMA_HISTOGRAM_ENUMERATION("Download.ContentType", 292 UMA_HISTOGRAM_ENUMERATION("Download.ContentType",
251 download_content, 293 download_content,
252 DOWNLOAD_CONTENT_MAX); 294 DOWNLOAD_CONTENT_MAX);
253 } 295 }
254 296
297 void RecordDownloadContentDisposition(
rvargas (doing something else) 2012/12/14 22:49:54 Isn't it better to generate the histograms directl
asanka 2012/12/15 01:57:32 The data gathered here would be used to decide whe
rvargas (doing something else) 2012/12/15 02:46:57 But that can be answered by generating the same hi
asanka 2012/12/16 18:32:04 HttpContentDisposition is instantiated in multiple
298 const std::string& content_disposition_string) {
299 if (content_disposition_string.empty())
300 return;
301 net::HttpContentDisposition content_disposition(
302 content_disposition_string, "");
303 const net::HttpContentDisposition::ParseResult& result =
304 content_disposition.parse_result();
305
306 bool is_valid = !result.filename().empty();
307 RecordContentDispositionCount(CONTENT_DISPOSITION_HEADER_PRESENT, true);
308 RecordContentDispositionCount(CONTENT_DISPOSITION_IS_VALID, is_valid);
309 if (!is_valid)
310 return;
311
312 RecordContentDispositionCount(CONTENT_DISPOSITION_HAS_DISPOSITION_TYPE,
313 result.has_disposition_type);
314 RecordContentDispositionCount(CONTENT_DISPOSITION_HAS_UNKNOWN_TYPE,
315 result.has_unknown_disposition_type);
316 RecordContentDispositionCount(CONTENT_DISPOSITION_HAS_NAME,
317 result.has_name);
318 RecordContentDispositionCount(CONTENT_DISPOSITION_HAS_FILENAME,
319 result.has_filename);
320 RecordContentDispositionCount(CONTENT_DISPOSITION_HAS_EXT_FILENAME,
321 result.has_ext_filename);
322 RecordContentDispositionCount(CONTENT_DISPOSITION_HAS_NON_ASCII_STRINGS,
323 result.has_non_ascii_strings);
324 RecordContentDispositionCount(CONTENT_DISPOSITION_HAS_PERCENT_ENCODED_STRINGS,
325 result.has_percent_encoded_strings);
326 RecordContentDispositionCount(CONTENT_DISPOSITION_HAS_RFC2047_ENCODED_STRINGS,
327 result.has_rfc2047_encoded_strings);
328
329 RecordContentDispositionCount(CONTENT_DISPOSITION_HAS_NAME_ONLY,
330 (result.has_name && !result.has_filename &&
331 !result.has_ext_filename));
332 }
333
255 void RecordFileThreadReceiveBuffers(size_t num_buffers) { 334 void RecordFileThreadReceiveBuffers(size_t num_buffers) {
256 UMA_HISTOGRAM_CUSTOM_COUNTS( 335 UMA_HISTOGRAM_CUSTOM_COUNTS(
257 "Download.FileThreadReceiveBuffers", num_buffers, 1, 336 "Download.FileThreadReceiveBuffers", num_buffers, 1,
258 100, 100); 337 100, 100);
259 } 338 }
260 339
261 void RecordBandwidth(double actual_bandwidth, double potential_bandwidth) { 340 void RecordBandwidth(double actual_bandwidth, double potential_bandwidth) {
262 UMA_HISTOGRAM_CUSTOM_COUNTS( 341 UMA_HISTOGRAM_CUSTOM_COUNTS(
263 "Download.ActualBandwidth", actual_bandwidth, 1, 1000000000, 50); 342 "Download.ActualBandwidth", actual_bandwidth, 1, 1000000000, 50);
264 UMA_HISTOGRAM_CUSTOM_COUNTS( 343 UMA_HISTOGRAM_CUSTOM_COUNTS(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 disk_write_time_ms * 100 / elapsed_time_ms); 411 disk_write_time_ms * 100 / elapsed_time_ms);
333 } 412 }
334 413
335 void RecordSavePackageEvent(SavePackageEvent event) { 414 void RecordSavePackageEvent(SavePackageEvent event) {
336 UMA_HISTOGRAM_ENUMERATION("Download.SavePackage", 415 UMA_HISTOGRAM_ENUMERATION("Download.SavePackage",
337 event, 416 event,
338 SAVE_PACKAGE_LAST_ENTRY); 417 SAVE_PACKAGE_LAST_ENTRY);
339 } 418 }
340 419
341 } // namespace content 420 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698