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

Unified 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: Suppress accidental trigraph 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/download/download_stats.h ('k') | net/http/http_content_disposition.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/download/download_stats.cc
diff --git a/content/browser/download/download_stats.cc b/content/browser/download/download_stats.cc
index 2da505a27a00e85e61d46f28f4c2995e71b8d3ce..cad6cbe4bac245454522b354b6c6a05f10a2bbcb 100644
--- a/content/browser/download/download_stats.cc
+++ b/content/browser/download/download_stats.cc
@@ -8,9 +8,12 @@
#include "base/string_util.h"
#include "content/browser/download/download_resource_handler.h"
#include "content/public/browser/download_interrupt_reasons.h"
+#include "net/http/http_content_disposition.h"
namespace content {
+namespace {
+
// All possible error codes from the network module. Note that the error codes
// are all positive (since histograms expect positive sample values).
const int kAllInterruptReasonCodes[] = {
@@ -19,6 +22,52 @@ const int kAllInterruptReasonCodes[] = {
#undef INTERRUPT_REASON
};
+// These values are based on net::HttpContentDisposition::ParseResult values.
+// Values other than HEADER_PRESENT and IS_VALID are only measured if |IS_VALID|
+// is true.
+enum ContentDispositionCountTypes {
+ // Count of downloads which had a Content-Disposition headers. The total
+ // number of downloads is measured by UNTHROTTLED_COUNT.
+ CONTENT_DISPOSITION_HEADER_PRESENT = 0,
+
+ // At least one of 'name', 'filename' or 'filenae*' attributes were valid and
+ // yielded a non-empty filename.
+ CONTENT_DISPOSITION_IS_VALID,
+
+ // The following enum values correspond to
+ // net::HttpContentDisposition::ParseResult.
+ CONTENT_DISPOSITION_HAS_DISPOSITION_TYPE,
+ CONTENT_DISPOSITION_HAS_UNKNOWN_TYPE,
+ CONTENT_DISPOSITION_HAS_NAME,
+ CONTENT_DISPOSITION_HAS_FILENAME,
+ CONTENT_DISPOSITION_HAS_EXT_FILENAME,
+ CONTENT_DISPOSITION_HAS_NON_ASCII_STRINGS,
+ CONTENT_DISPOSITION_HAS_PERCENT_ENCODED_STRINGS,
+ CONTENT_DISPOSITION_HAS_RFC2047_ENCODED_STRINGS,
+
+ // Only have the 'name' attribute is present.
+ CONTENT_DISPOSITION_HAS_NAME_ONLY,
+
+ CONTENT_DISPOSITION_LAST_ENTRY
+};
+
+void RecordContentDispositionCount(ContentDispositionCountTypes type,
+ bool record) {
+ if (!record)
+ return;
+ UMA_HISTOGRAM_ENUMERATION(
+ "Download.ContentDisposition", type, CONTENT_DISPOSITION_LAST_ENTRY);
+}
+
+void RecordContentDispositionCountFlag(
+ ContentDispositionCountTypes type,
+ int flags_to_test,
+ net::HttpContentDisposition::ParseResultFlags flag) {
+ RecordContentDispositionCount(type, (flags_to_test & flag) == flag);
+}
+
+} // namespace
+
void RecordDownloadCount(DownloadCountTypes type) {
UMA_HISTOGRAM_ENUMERATION(
"Download.Counts", type, DOWNLOAD_COUNT_TYPES_LAST_ENTRY);
@@ -252,6 +301,53 @@ void RecordDownloadMimeType(const std::string& mime_type_string) {
DOWNLOAD_CONTENT_MAX);
}
+void RecordDownloadContentDisposition(
+ const std::string& content_disposition_string) {
+ if (content_disposition_string.empty())
+ return;
+ net::HttpContentDisposition content_disposition(
+ content_disposition_string, "");
+ int result = content_disposition.parse_result_flags();
+
+ bool is_valid = !content_disposition.filename().empty();
+ RecordContentDispositionCount(CONTENT_DISPOSITION_HEADER_PRESENT, true);
+ RecordContentDispositionCount(CONTENT_DISPOSITION_IS_VALID, is_valid);
+ if (!is_valid)
+ return;
+
+ RecordContentDispositionCountFlag(
+ CONTENT_DISPOSITION_HAS_DISPOSITION_TYPE, result,
+ net::HttpContentDisposition::HAS_DISPOSITION_TYPE);
+ RecordContentDispositionCountFlag(
+ CONTENT_DISPOSITION_HAS_UNKNOWN_TYPE, result,
+ net::HttpContentDisposition::HAS_UNKNOWN_DISPOSITION_TYPE);
+ RecordContentDispositionCountFlag(
+ CONTENT_DISPOSITION_HAS_NAME, result,
+ net::HttpContentDisposition::HAS_NAME);
+ RecordContentDispositionCountFlag(
+ CONTENT_DISPOSITION_HAS_FILENAME, result,
+ net::HttpContentDisposition::HAS_FILENAME);
+ RecordContentDispositionCountFlag(
+ CONTENT_DISPOSITION_HAS_EXT_FILENAME, result,
+ net::HttpContentDisposition::HAS_EXT_FILENAME);
+ RecordContentDispositionCountFlag(
+ CONTENT_DISPOSITION_HAS_NON_ASCII_STRINGS, result,
+ net::HttpContentDisposition::HAS_NON_ASCII_STRINGS);
+ RecordContentDispositionCountFlag(
+ CONTENT_DISPOSITION_HAS_PERCENT_ENCODED_STRINGS, result,
+ net::HttpContentDisposition::HAS_PERCENT_ENCODED_STRINGS);
+ RecordContentDispositionCountFlag(
+ CONTENT_DISPOSITION_HAS_RFC2047_ENCODED_STRINGS, result,
+ net::HttpContentDisposition::HAS_RFC2047_ENCODED_STRINGS);
+
+ RecordContentDispositionCount(
+ CONTENT_DISPOSITION_HAS_NAME_ONLY,
+ (result & (net::HttpContentDisposition::HAS_NAME |
+ net::HttpContentDisposition::HAS_FILENAME |
+ net::HttpContentDisposition::HAS_EXT_FILENAME)) ==
+ net::HttpContentDisposition::HAS_NAME);
+}
+
void RecordFileThreadReceiveBuffers(size_t num_buffers) {
UMA_HISTOGRAM_CUSTOM_COUNTS(
"Download.FileThreadReceiveBuffers", num_buffers, 1,
« no previous file with comments | « content/browser/download/download_stats.h ('k') | net/http/http_content_disposition.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698