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

Unified Diff: net/base/mime_sniffer.cc

Issue 6780035: Use lock-free lazy initialization for static histogram references (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 months 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 | « net/base/cookie_monster_unittest.cc ('k') | net/disk_cache/histogram_macros.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/mime_sniffer.cc
===================================================================
--- net/base/mime_sniffer.cc (revision 80382)
+++ net/base/mime_sniffer.cc (working copy)
@@ -209,9 +209,9 @@
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 @@
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 @@
*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 @@
// 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 @@
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 @@
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 @@
// 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 @@
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 @@
}
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 @@
"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);
« no previous file with comments | « net/base/cookie_monster_unittest.cc ('k') | net/disk_cache/histogram_macros.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698