Index: chrome/browser/metrics/metrics_service.cc |
diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc |
index cb183c708f819b2f415242fb5eb37c650a480c91..fc1bded6c20496c6565a901f6ac62c0ac9f93147 100644 |
--- a/chrome/browser/metrics/metrics_service.cc |
+++ b/chrome/browser/metrics/metrics_service.cc |
@@ -532,10 +532,14 @@ MetricsService::MetricsService() |
scheduler_.reset(new MetricsReportingScheduler(callback)); |
log_manager_.set_log_serializer(new MetricsLogSerializer()); |
log_manager_.set_max_ongoing_log_store_size(kUploadLogAvoidRetransmitSize); |
+ |
+ BrowserChildProcessObserver::Add(this); |
} |
MetricsService::~MetricsService() { |
DisableRecording(); |
+ |
+ BrowserChildProcessObserver::Remove(this); |
} |
void MetricsService::Start() { |
@@ -676,18 +680,31 @@ void MetricsService::SetUpNotifications( |
content::NotificationService::AllSources()); |
registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_HANG, |
content::NotificationService::AllSources()); |
- registrar->Add(observer, content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED, |
- content::NotificationService::AllSources()); |
- registrar->Add(observer, content::NOTIFICATION_CHILD_INSTANCE_CREATED, |
- content::NotificationService::AllSources()); |
- registrar->Add(observer, content::NOTIFICATION_CHILD_PROCESS_CRASHED, |
- content::NotificationService::AllSources()); |
registrar->Add(observer, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, |
content::NotificationService::AllSources()); |
registrar->Add(observer, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, |
content::NotificationService::AllSources()); |
} |
+void MetricsService::BrowserChildProcessHostConnected( |
+ const content::ChildProcessData& data) { |
+ GetChildProcessStats(data).process_launches++; |
+} |
+ |
+void MetricsService::BrowserChildProcessCrashed( |
+ const content::ChildProcessData& data) { |
+ GetChildProcessStats(data).process_crashes++; |
+ // Exclude plugin crashes from the count below because we report them via |
+ // a separate UMA metric. |
+ if (!IsPluginProcess(data.type)) |
+ IncrementPrefValue(prefs::kStabilityChildProcessCrashCount); |
+} |
+ |
+void MetricsService::BrowserChildProcessInstanceCreated( |
+ const content::ChildProcessData& data) { |
+ GetChildProcessStats(data).instances++; |
+} |
+ |
void MetricsService::Observe(int type, |
const content::NotificationSource& source, |
const content::NotificationDetails& details) { |
@@ -744,12 +761,6 @@ void MetricsService::Observe(int type, |
LogRendererHang(); |
break; |
- case content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED: |
- case content::NOTIFICATION_CHILD_PROCESS_CRASHED: |
- case content::NOTIFICATION_CHILD_INSTANCE_CREATED: |
- LogChildProcessChange(type, source, details); |
- break; |
- |
case chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED: |
LogKeywordCount(content::Source<TemplateURLService>( |
source)->GetTemplateURLs().size()); |
@@ -1763,42 +1774,12 @@ void MetricsService::LogPluginLoadingError(const base::FilePath& plugin_path) { |
stats.loading_errors++; |
} |
-void MetricsService::LogChildProcessChange( |
- int type, |
- const content::NotificationSource& source, |
- const content::NotificationDetails& details) { |
- content::Details<ChildProcessData> child_details(details); |
- const string16& child_name = child_details->name; |
- |
- if (child_process_stats_buffer_.find(child_name) == |
- child_process_stats_buffer_.end()) { |
- child_process_stats_buffer_[child_name] = |
- ChildProcessStats(child_details->type); |
- } |
- |
- ChildProcessStats& stats = child_process_stats_buffer_[child_name]; |
- switch (type) { |
- case content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED: |
- stats.process_launches++; |
- break; |
- |
- case content::NOTIFICATION_CHILD_INSTANCE_CREATED: |
- stats.instances++; |
- break; |
- |
- case content::NOTIFICATION_CHILD_PROCESS_CRASHED: |
- stats.process_crashes++; |
- // Exclude plugin crashes from the count below because we report them via |
- // a separate UMA metric. |
- if (!IsPluginProcess(child_details->type)) { |
- IncrementPrefValue(prefs::kStabilityChildProcessCrashCount); |
- } |
- break; |
- |
- default: |
- NOTREACHED() << "Unexpected notification type " << type; |
- return; |
- } |
+MetricsService::ChildProcessStats& MetricsService::GetChildProcessStats( |
+ const content::ChildProcessData& data) { |
+ const string16& child_name = data.name; |
+ if (!ContainsKey(child_process_stats_buffer_, child_name)) |
+ child_process_stats_buffer_[child_name] = ChildProcessStats(data.type); |
+ return child_process_stats_buffer_[child_name]; |
} |
void MetricsService::LogKeywordCount(size_t keyword_count) { |