summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-17 19:15:36 +0000
committerabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-17 19:15:36 +0000
commit30629139d1e967d14c0df8752831a0b9b78f49b9 (patch)
tree0f9e28068ca2dd6120a0d2f58ae999eed32cfbd6
parent435ba90f861416f41753284966dab9bae422043f (diff)
downloadchromium_src-30629139d1e967d14c0df8752831a0b9b78f49b9.zip
chromium_src-30629139d1e967d14c0df8752831a0b9b78f49b9.tar.gz
chromium_src-30629139d1e967d14c0df8752831a0b9b78f49b9.tar.bz2
Collect some metrics on nosniff. There is some concern that respecting this header causes more harm than good.
R=darin Review URL: http://codereview.chromium.org/18214 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8257 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/histogram.h12
-rw-r--r--chrome/browser/renderer_host/buffered_resource_handler.cc33
2 files changed, 43 insertions, 2 deletions
diff --git a/base/histogram.h b/base/histogram.h
index f56d05f..8b4bded 100644
--- a/base/histogram.h
+++ b/base/histogram.h
@@ -370,6 +370,18 @@ class LinearHistogram : public Histogram {
DISALLOW_EVIL_CONSTRUCTORS(LinearHistogram);
};
+//------------------------------------------------------------------------------
+
+// BooleanHistogram is a histogram for booleans.
+class BooleanHistogram : public LinearHistogram {
+ public:
+ BooleanHistogram(const wchar_t* name) : LinearHistogram(name, 0, 2, 3) {}
+
+ virtual void AddBoolean(bool value) { Add(value ? 1 : 0); }
+
+ private:
+ DISALLOW_EVIL_CONSTRUCTORS(BooleanHistogram);
+};
//------------------------------------------------------------------------------
// This section provides implementation for ThreadSafeHistogram.
diff --git a/chrome/browser/renderer_host/buffered_resource_handler.cc b/chrome/browser/renderer_host/buffered_resource_handler.cc
index 7630dd1..14f6934 100644
--- a/chrome/browser/renderer_host/buffered_resource_handler.cc
+++ b/chrome/browser/renderer_host/buffered_resource_handler.cc
@@ -4,10 +4,33 @@
#include "chrome/browser/renderer_host/buffered_resource_handler.h"
+#include "base/histogram.h"
#include "net/base/mime_sniffer.h"
#include "chrome/browser/renderer_host/download_throttling_resource_handler.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
+namespace {
+
+void RecordSnifferMetrics(bool sniffing_blocked,
+ bool we_would_like_to_sniff,
+ const std::string& mime_type) {
+ static BooleanHistogram nosniff_usage(L"nosniff.usage");
+ nosniff_usage.SetFlags(kUmaTargetedHistogramFlag);
+ nosniff_usage.AddBoolean(sniffing_blocked);
+
+ if (sniffing_blocked) {
+ static BooleanHistogram nosniff_otherwise(L"nosniff.otherwise");
+ nosniff_otherwise.SetFlags(kUmaTargetedHistogramFlag);
+ nosniff_otherwise.AddBoolean(we_would_like_to_sniff);
+
+ static BooleanHistogram nosniff_empty_mime_type(L"nosniff.empty_mime_type");
+ nosniff_empty_mime_type.SetFlags(kUmaTargetedHistogramFlag);
+ nosniff_empty_mime_type.AddBoolean(mime_type.empty());
+ }
+}
+
+} // namespace
+
BufferedResourceHandler::BufferedResourceHandler(ResourceHandler* handler,
ResourceDispatcherHost* host,
URLRequest* request)
@@ -92,8 +115,14 @@ bool BufferedResourceHandler::DelayResponse() {
std::string content_type_options;
request_->GetResponseHeaderByName("x-content-type-options",
&content_type_options);
- if (content_type_options != "nosniff" &&
- net::ShouldSniffMimeType(request_->url(), mime_type)) {
+
+ const bool sniffing_blocked = (content_type_options == "nosniff");
+ const bool we_would_like_to_sniff =
+ net::ShouldSniffMimeType(request_->url(), mime_type);
+
+ RecordSnifferMetrics(sniffing_blocked, we_would_like_to_sniff, mime_type);
+
+ if (!sniffing_blocked && we_would_like_to_sniff) {
// We're going to look at the data before deciding what the content type
// is. That means we need to delay sending the ResponseStarted message
// over the IPC channel.