diff options
Diffstat (limited to 'net/base/mime_sniffer.cc')
-rw-r--r-- | net/base/mime_sniffer.cc | 67 |
1 files changed, 38 insertions, 29 deletions
diff --git a/net/base/mime_sniffer.cc b/net/base/mime_sniffer.cc index 25b94ec..b0b6d03 100644 --- a/net/base/mime_sniffer.cc +++ b/net/base/mime_sniffer.cc @@ -209,9 +209,9 @@ static const MagicNumber kSniffableTags[] = { MAGIC_HTML_TAG("p") // Mozilla }; -static scoped_refptr<base::Histogram> UMASnifferHistogramGet(const char* name, - int array_size) { - scoped_refptr<base::Histogram> counter = +static base::Histogram* UMASnifferHistogramGet(const char* name, + int array_size) { + base::Histogram* counter = base::LinearHistogram::FactoryGet(name, 1, array_size - 1, array_size, base::Histogram::kUmaTargetedHistogramFlag); return counter; @@ -308,13 +308,14 @@ static bool SniffForHTML(const char* content, if (!IsAsciiWhitespace(*pos)) break; } - scoped_refptr<base::Histogram> counter = - UMASnifferHistogramGet("mime_sniffer.kSniffableTags2", - arraysize(kSniffableTags)); + static base::Histogram* counter(NULL); + if (!counter) + counter = UMASnifferHistogramGet("mime_sniffer.kSniffableTags2", + arraysize(kSniffableTags)); // |pos| now points to first non-whitespace character (or at end). return CheckForMagicNumbers(pos, end - pos, kSniffableTags, arraysize(kSniffableTags), - counter.get(), result); + counter, result); } // Returns true and sets result if the content matches any of kMagicNumbers. @@ -326,12 +327,13 @@ static bool SniffForMagicNumbers(const char* content, *have_enough_content &= TruncateSize(kBytesRequiredForMagic, &size); // Check our big table of Magic Numbers - scoped_refptr<base::Histogram> counter = - UMASnifferHistogramGet("mime_sniffer.kMagicNumbers2", - arraysize(kMagicNumbers)); + static base::Histogram* counter(NULL); + if (!counter) + counter = UMASnifferHistogramGet("mime_sniffer.kMagicNumbers2", + arraysize(kMagicNumbers)); return CheckForMagicNumbers(content, size, kMagicNumbers, arraysize(kMagicNumbers), - counter.get(), result); + counter, result); } // Byte order marks @@ -367,9 +369,10 @@ static bool SniffXML(const char* content, // We want to skip XML processing instructions (of the form "<?xml ...") // and stop at the first "plain" tag, then make a decision on the mime-type // based on the name (or possibly attributes) of that tag. - scoped_refptr<base::Histogram> counter = - UMASnifferHistogramGet("mime_sniffer.kMagicXML2", - arraysize(kMagicXML)); + static base::Histogram* counter(NULL); + if (!counter) + counter = UMASnifferHistogramGet("mime_sniffer.kMagicXML2", + arraysize(kMagicXML)); const int kMaxTagIterations = 5; for (int i = 0; i < kMaxTagIterations && pos < end; ++i) { pos = reinterpret_cast<const char*>(memchr(pos, '<', end - pos)); @@ -389,7 +392,7 @@ static bool SniffXML(const char* content, if (CheckForMagicNumbers(pos, end - pos, kMagicXML, arraysize(kMagicXML), - counter.get(), result)) + counter, result)) return true; // TODO(evanm): handle RSS 1.0, which is an RDF format and more difficult @@ -451,13 +454,14 @@ static bool SniffBinary(const char* content, const bool is_truncated = TruncateSize(kMaxBytesToSniff, &size); // First, we look for a BOM. - scoped_refptr<base::Histogram> counter = - UMASnifferHistogramGet("mime_sniffer.kByteOrderMark2", - arraysize(kByteOrderMark)); + static base::Histogram* counter(NULL); + if (!counter) + counter = UMASnifferHistogramGet("mime_sniffer.kByteOrderMark2", + arraysize(kByteOrderMark)); std::string unused; if (CheckForMagicNumbers(content, size, kByteOrderMark, arraysize(kByteOrderMark), - counter.get(), &unused)) { + counter, &unused)) { // If there is BOM, we think the buffer is not binary. result->assign("text/plain"); return false; @@ -493,9 +497,10 @@ static bool IsUnknownMimeType(const std::string& mime_type) { // Firefox rejects a mime type if it is exactly */* "*/*", }; - scoped_refptr<base::Histogram> counter = - UMASnifferHistogramGet("mime_sniffer.kUnknownMimeTypes2", - arraysize(kUnknownMimeTypes) + 1); + static base::Histogram* counter(NULL); + if (!counter) + counter = UMASnifferHistogramGet("mime_sniffer.kUnknownMimeTypes2", + arraysize(kUnknownMimeTypes) + 1); for (size_t i = 0; i < arraysize(kUnknownMimeTypes); ++i) { if (mime_type == kUnknownMimeTypes[i]) { counter->Add(i); @@ -519,8 +524,9 @@ static bool SniffCRX(const char* content, const std::string& type_hint, bool* have_enough_content, std::string* result) { - scoped_refptr<base::Histogram> counter = - UMASnifferHistogramGet("mime_sniffer.kSniffCRX", 3); + static base::Histogram* counter(NULL); + if (!counter) + counter = UMASnifferHistogramGet("mime_sniffer.kSniffCRX", 3); // Technically, the crx magic number is just Cr24, but the bytes after that // are a version number which changes infrequently. Including it in the @@ -557,8 +563,10 @@ static bool SniffCRX(const char* content, } bool ShouldSniffMimeType(const GURL& url, const std::string& mime_type) { - scoped_refptr<base::Histogram> should_sniff_counter = - UMASnifferHistogramGet("mime_sniffer.ShouldSniffMimeType2", 3); + static base::Histogram* should_sniff_counter(NULL); + if (!should_sniff_counter) + should_sniff_counter = + UMASnifferHistogramGet("mime_sniffer.ShouldSniffMimeType2", 3); // We are willing to sniff the mime type for HTTP, HTTPS, and FTP bool sniffable_scheme = url.is_empty() || url.SchemeIs("http") || @@ -582,9 +590,10 @@ bool ShouldSniffMimeType(const GURL& url, const std::string& mime_type) { "text/xml", "application/xml", }; - scoped_refptr<base::Histogram> counter = - UMASnifferHistogramGet("mime_sniffer.kSniffableTypes2", - arraysize(kSniffableTypes) + 1); + static base::Histogram* counter(NULL); + if (!counter) + counter = UMASnifferHistogramGet("mime_sniffer.kSniffableTypes2", + arraysize(kSniffableTypes) + 1); for (size_t i = 0; i < arraysize(kSniffableTypes); ++i) { if (mime_type == kSniffableTypes[i]) { counter->Add(i); |