summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-06 00:09:37 +0000
committerjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-06 00:09:37 +0000
commite8829a1981a2d9d849c377c28f9444fdefee0f44 (patch)
tree3cfe522cf76d308dec9fca773d3f9495e12abc5e /chrome/browser
parent4f3b65a30cad88c1f1e482f7bda69ef50f8e1364 (diff)
downloadchromium_src-e8829a1981a2d9d849c377c28f9444fdefee0f44.zip
chromium_src-e8829a1981a2d9d849c377c28f9444fdefee0f44.tar.gz
chromium_src-e8829a1981a2d9d849c377c28f9444fdefee0f44.tar.bz2
Use factory to create histograms, and refcounts to track lifetimes
This is CL patch 377028 by Raman Tenneti, with minor changes to make the try-bots happier. It is cleanup that better ensures lifetimes of histograms (making it harder for users to abuse them). bug=16495 (repairs leak induced by the first landing) bug=18840 (should make leaks less possible) tbr=raman.tenneti Review URL: http://codereview.chromium.org/462027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33933 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/chrome_browser_application_mac.mm9
-rw-r--r--chrome/browser/diagnostics/sqlite_diagnostics.cc8
-rw-r--r--chrome/browser/jankometer.cc22
-rw-r--r--chrome/browser/net/dns_host_info.cc9
-rw-r--r--chrome/browser/net/websocket_experiment/websocket_experiment_runner.cc72
-rw-r--r--chrome/browser/renderer_host/buffered_resource_handler.cc25
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_blocking_page.cc8
-rw-r--r--chrome/browser/ssl/ssl_blocking_page.cc8
-rw-r--r--chrome/browser/sync/profile_sync_service.cc11
9 files changed, 99 insertions, 73 deletions
diff --git a/chrome/browser/chrome_browser_application_mac.mm b/chrome/browser/chrome_browser_application_mac.mm
index 48bef43..3aa31013 100644
--- a/chrome/browser/chrome_browser_application_mac.mm
+++ b/chrome/browser/chrome_browser_application_mac.mm
@@ -91,10 +91,11 @@ size_t BinForException(NSException* exception) {
}
void RecordExceptionWithUma(NSException* exception) {
- static LinearHistogram histogram("OSX.NSException", 0, kUnknownNSException,
- kUnknownNSException + 1);
- histogram.SetFlags(kUmaTargetedHistogramFlag);
- histogram.Add(BinForException(exception));
+ static scoped_refptr<Histogram> histogram =
+ LinearHistogram::LinearHistogramFactoryGet("OSX.NSException",
+ 0, kUnknownNSException, kUnknownNSException + 1);
+ histogram->SetFlags(kUmaTargetedHistogramFlag);
+ histogram->Add(BinForException(exception));
}
void Terminate() {
diff --git a/chrome/browser/diagnostics/sqlite_diagnostics.cc b/chrome/browser/diagnostics/sqlite_diagnostics.cc
index f3ca31d..b266002 100644
--- a/chrome/browser/diagnostics/sqlite_diagnostics.cc
+++ b/chrome/browser/diagnostics/sqlite_diagnostics.cc
@@ -43,9 +43,11 @@ class BasicSqliteErrrorHandler : public sql::ErrorDelegate {
static void RecordErrorInHistogram(int error) {
// The histogram values from sqlite result codes go currently from 1 to
// 26 currently but 50 gives them room to grow.
- static LinearHistogram histogram(kHistogramNames[unique], 1, 50, 51);
- histogram.SetFlags(kUmaTargetedHistogramFlag);
- histogram.Add(error);
+ static scoped_refptr<Histogram> histogram =
+ LinearHistogram::LinearHistogramFactoryGet(kHistogramNames[unique], 1,
+ 50, 51);
+ histogram->SetFlags(kUmaTargetedHistogramFlag);
+ histogram->Add(error);
}
};
diff --git a/chrome/browser/jankometer.cc b/chrome/browser/jankometer.cc
index 32b42ca..10d2f14 100644
--- a/chrome/browser/jankometer.cc
+++ b/chrome/browser/jankometer.cc
@@ -91,13 +91,15 @@ class JankObserver : public base::RefCountedThreadSafe<JankObserver>,
: MaxMessageDelay_(excessive_duration),
slow_processing_counter_(std::string("Chrome.SlowMsg") + thread_name),
queueing_delay_counter_(std::string("Chrome.DelayMsg") + thread_name),
- process_times_((std::string("Chrome.ProcMsgL ") +
- thread_name).c_str(), 1, 3600000, 50),
- total_times_((std::string("Chrome.TotalMsgL ") +
- thread_name).c_str(), 1, 3600000, 50),
total_time_watchdog_(excessive_duration, thread_name, watchdog_enable) {
- process_times_.SetFlags(kUmaTargetedHistogramFlag);
- total_times_.SetFlags(kUmaTargetedHistogramFlag);
+ process_times_ = Histogram::HistogramFactoryGet(
+ (std::string("Chrome.ProcMsgL ") + thread_name),
+ 1, 3600000, 50);
+ total_times_ = Histogram::HistogramFactoryGet(
+ (std::string("Chrome.TotalMsgL ") + thread_name),
+ 1, 3600000, 50);
+ process_times_->SetFlags(kUmaTargetedHistogramFlag);
+ total_times_->SetFlags(kUmaTargetedHistogramFlag);
}
// Attaches the observer to the current thread's message loop. You can only
@@ -137,8 +139,8 @@ class JankObserver : public base::RefCountedThreadSafe<JankObserver>,
TimeTicks now = TimeTicks::Now();
if (begin_process_message_ != TimeTicks()) {
TimeDelta processing_time = now - begin_process_message_;
- process_times_.AddTime(processing_time);
- total_times_.AddTime(queueing_time_ + processing_time);
+ process_times_->AddTime(processing_time);
+ total_times_->AddTime(queueing_time_ + processing_time);
}
if (now - begin_process_message_ >
TimeDelta::FromMilliseconds(kMaxMessageProcessingMs)) {
@@ -208,8 +210,8 @@ class JankObserver : public base::RefCountedThreadSafe<JankObserver>,
// Counters for the two types of jank we measure.
StatsCounter slow_processing_counter_; // Messages with long processing time.
StatsCounter queueing_delay_counter_; // Messages with long queueing delay.
- Histogram process_times_; // Time spent processing task.
- Histogram total_times_; // Total of queueing plus processing time.
+ scoped_refptr<Histogram> process_times_; // Time spent processing task.
+ scoped_refptr<Histogram> total_times_; // Total queueing plus processing.
JankWatchdog total_time_watchdog_; // Watching for excessive total_time.
DISALLOW_EVIL_CONSTRUCTORS(JankObserver);
diff --git a/chrome/browser/net/dns_host_info.cc b/chrome/browser/net/dns_host_info.cc
index 63eae34..755f54d 100644
--- a/chrome/browser/net/dns_host_info.cc
+++ b/chrome/browser/net/dns_host_info.cc
@@ -104,10 +104,11 @@ void DnsHostInfo::RemoveFromQueue() {
}
// Make a custom linear histogram for the region from 0 to boundary.
const size_t kBucketCount = 52;
- static LinearHistogram histogram("DNS.QueueRecycledUnder2", TimeDelta(),
- kBoundary, kBucketCount);
- histogram.SetFlags(kUmaTargetedHistogramFlag);
- histogram.AddTime(queue_duration_);
+ static scoped_refptr<Histogram> histogram =
+ LinearHistogram::LinearHistogramFactoryGet("DNS.QueueRecycledUnder2",
+ TimeDelta(), kBoundary, kBucketCount);
+ histogram->SetFlags(kUmaTargetedHistogramFlag);
+ histogram->AddTime(queue_duration_);
}
void DnsHostInfo::SetPendingDeleteState() {
diff --git a/chrome/browser/net/websocket_experiment/websocket_experiment_runner.cc b/chrome/browser/net/websocket_experiment/websocket_experiment_runner.cc
index 1dfa3d6..8d03b6f 100644
--- a/chrome/browser/net/websocket_experiment/websocket_experiment_runner.cc
+++ b/chrome/browser/net/websocket_experiment/websocket_experiment_runner.cc
@@ -28,31 +28,36 @@ static const int kWebSocketTimeSec = 10;
static const int kTimeBucketCount = 50;
// TODO(ukai): Use new thread-safe-reference-counted Histograms.
-#define UPDATE_HISTOGRAM(name, sample, min, max, bucket_count) do { \
- switch (task_state_) { \
- case STATE_RUN_WS: \
- { \
- static LinearHistogram counter( \
- "WebSocketExperiment.Basic." name, min, max, bucket_count); \
- counter.SetFlags(kUmaTargetedHistogramFlag); \
- counter.Add(sample); \
+#define UPDATE_HISTOGRAM(name, sample, min, max, bucket_count) do { \
+ switch (task_state_) { \
+ case STATE_RUN_WS: \
+ { \
+ static scoped_refptr<Histogram> counter = \
+ LinearHistogram::LinearHistogramFactoryGet(\
+ "WebSocketExperiment.Basic." name, \
+ min, max, bucket_count); \
+ counter->SetFlags(kUmaTargetedHistogramFlag); \
+ counter->Add(sample); \
} \
break; \
case STATE_RUN_WSS: \
{ \
- static LinearHistogram counter( \
- "WebSocketExperiment.Secure." name, min, max, bucket_count); \
- counter.SetFlags(kUmaTargetedHistogramFlag); \
- counter.Add(sample); \
+ static scoped_refptr<Histogram> counter = \
+ LinearHistogram::LinearHistogramFactoryGet(\
+ "WebSocketExperiment.Secure." name, \
+ min, max, bucket_count); \
+ counter->SetFlags(kUmaTargetedHistogramFlag); \
+ counter->Add(sample); \
} \
break; \
case STATE_RUN_WS_NODEFAULT_PORT: \
{ \
- static LinearHistogram counter( \
- "WebSocketExperiment.NoDefaultPort." name, \
- min, max, bucket_count); \
- counter.SetFlags(kUmaTargetedHistogramFlag); \
- counter.Add(sample); \
+ static scoped_refptr<Histogram> counter = \
+ LinearHistogram::LinearHistogramFactoryGet(\
+ "WebSocketExperiment.NoDefaultPort." name, \
+ min, max, bucket_count); \
+ counter->SetFlags(kUmaTargetedHistogramFlag); \
+ counter->Add(sample); \
} \
break; \
default: \
@@ -61,31 +66,36 @@ static const int kTimeBucketCount = 50;
} \
} while (0)
-#define UPDATE_HISTOGRAM_TIMES(name, sample, min, max, bucket_count) do { \
+#define UPDATE_HISTOGRAM_TIMES(name, sample, min, max, bucket_count) do { \
switch (task_state_) { \
case STATE_RUN_WS: \
{ \
- static Histogram counter( \
- "WebSocketExperiment.Basic." name, min, max, bucket_count); \
- counter.SetFlags(kUmaTargetedHistogramFlag); \
- counter.AddTime(sample); \
+ static scoped_refptr<Histogram> counter = \
+ Histogram::HistogramFactoryGet(\
+ "WebSocketExperiment.Basic." name, \
+ min, max, bucket_count); \
+ counter->SetFlags(kUmaTargetedHistogramFlag); \
+ counter->AddTime(sample); \
} \
break; \
case STATE_RUN_WSS: \
{ \
- static Histogram counter( \
- "WebSocketExperiment.Secure." name, min, max, bucket_count); \
- counter.SetFlags(kUmaTargetedHistogramFlag); \
- counter.AddTime(sample); \
+ static scoped_refptr<Histogram> counter = \
+ Histogram::HistogramFactoryGet(\
+ "WebSocketExperiment.Secure." name, \
+ min, max, bucket_count); \
+ counter->SetFlags(kUmaTargetedHistogramFlag); \
+ counter->AddTime(sample); \
} \
break; \
case STATE_RUN_WS_NODEFAULT_PORT: \
{ \
- static Histogram counter( \
- "WebSocketExperiment.NoDefaultPort." name, \
- min, max, bucket_count); \
- counter.SetFlags(kUmaTargetedHistogramFlag); \
- counter.AddTime(sample); \
+ static scoped_refptr<Histogram> counter = \
+ Histogram::HistogramFactoryGet(\
+ "WebSocketExperiment.NoDefaultPort." name, \
+ min, max, bucket_count); \
+ counter->SetFlags(kUmaTargetedHistogramFlag); \
+ counter->AddTime(sample); \
} \
break; \
default: \
diff --git a/chrome/browser/renderer_host/buffered_resource_handler.cc b/chrome/browser/renderer_host/buffered_resource_handler.cc
index f3ca82f..6cf4430 100644
--- a/chrome/browser/renderer_host/buffered_resource_handler.cc
+++ b/chrome/browser/renderer_host/buffered_resource_handler.cc
@@ -30,18 +30,23 @@ const int kMaxBytesToSniff = 512;
void RecordSnifferMetrics(bool sniffing_blocked,
bool we_would_like_to_sniff,
const std::string& mime_type) {
- static BooleanHistogram nosniff_usage("nosniff.usage");
- nosniff_usage.SetFlags(kUmaTargetedHistogramFlag);
- nosniff_usage.AddBoolean(sniffing_blocked);
+ static scoped_refptr<Histogram> nosniff_usage =
+ BooleanHistogram::BooleanHistogramFactoryGet("nosniff.usage");
+ nosniff_usage->SetFlags(kUmaTargetedHistogramFlag);
+ nosniff_usage->AddBoolean(sniffing_blocked);
if (sniffing_blocked) {
- static BooleanHistogram nosniff_otherwise("nosniff.otherwise");
- nosniff_otherwise.SetFlags(kUmaTargetedHistogramFlag);
- nosniff_otherwise.AddBoolean(we_would_like_to_sniff);
-
- static BooleanHistogram nosniff_empty_mime_type("nosniff.empty_mime_type");
- nosniff_empty_mime_type.SetFlags(kUmaTargetedHistogramFlag);
- nosniff_empty_mime_type.AddBoolean(mime_type.empty());
+ static scoped_refptr<Histogram> nosniff_otherwise =
+ BooleanHistogram::BooleanHistogramFactoryGet(
+ "nosniff.otherwise");
+ nosniff_otherwise->SetFlags(kUmaTargetedHistogramFlag);
+ nosniff_otherwise->AddBoolean(we_would_like_to_sniff);
+
+ static scoped_refptr<Histogram> nosniff_empty_mime_type =
+ BooleanHistogram::BooleanHistogramFactoryGet(
+ "nosniff.empty_mime_type");
+ nosniff_empty_mime_type->SetFlags(kUmaTargetedHistogramFlag);
+ nosniff_empty_mime_type->AddBoolean(mime_type.empty());
}
}
diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
index a96146ce..3f559c0 100644
--- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
@@ -69,9 +69,11 @@ enum SafeBrowsingBlockingPageEvent {
};
void RecordSafeBrowsingBlockingPageStats(SafeBrowsingBlockingPageEvent event) {
- static LinearHistogram histogram("interstial.safe_browsing", 0, 2, 3);
- histogram.SetFlags(kUmaTargetedHistogramFlag);
- histogram.Add(event);
+ static scoped_refptr<Histogram> histogram =
+ LinearHistogram::LinearHistogramFactoryGet("interstial.safe_browsing",
+ 1, 2, 3);
+ histogram->SetFlags(kUmaTargetedHistogramFlag);
+ histogram->Add(event);
}
} // namespace
diff --git a/chrome/browser/ssl/ssl_blocking_page.cc b/chrome/browser/ssl/ssl_blocking_page.cc
index 2de2d58c..d0f3d6a 100644
--- a/chrome/browser/ssl/ssl_blocking_page.cc
+++ b/chrome/browser/ssl/ssl_blocking_page.cc
@@ -34,9 +34,11 @@ enum SSLBlockingPageEvent {
};
void RecordSSLBlockingPageStats(SSLBlockingPageEvent event) {
- static LinearHistogram histogram("interstial.ssl", 0, 2, 3);
- histogram.SetFlags(kUmaTargetedHistogramFlag);
- histogram.Add(event);
+ static scoped_refptr<Histogram> histogram =
+ LinearHistogram::LinearHistogramFactoryGet(
+ "interstial.ssl", 1, 2, 3);
+ histogram->SetFlags(kUmaTargetedHistogramFlag);
+ histogram->Add(event);
}
} // namespace
diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc
index 4cd9c6b..570b9a3 100644
--- a/chrome/browser/sync/profile_sync_service.cc
+++ b/chrome/browser/sync/profile_sync_service.cc
@@ -450,11 +450,12 @@ void ProfileSyncService::RemoveObserver(Observer* observer) {
}
void ProfileSyncService::SyncEvent(SyncEventCodes code) {
- static LinearHistogram histogram("Sync.EventCodes", MIN_SYNC_EVENT_CODE,
- MAX_SYNC_EVENT_CODE - 1,
- MAX_SYNC_EVENT_CODE);
- histogram.SetFlags(kUmaTargetedHistogramFlag);
- histogram.Add(code);
+ static scoped_refptr<Histogram> histogram =
+ LinearHistogram::LinearHistogramFactoryGet("Sync.EventCodes",
+ MIN_SYNC_EVENT_CODE + 1, MAX_SYNC_EVENT_CODE - 1,
+ MAX_SYNC_EVENT_CODE);
+ histogram->SetFlags(kUmaTargetedHistogramFlag);
+ histogram->Add(code);
}
bool ProfileSyncService::IsSyncEnabled() {