Index: chrome/browser/metrics/chrome_metrics_service_client.cc |
diff --git a/chrome/browser/metrics/chrome_metrics_service_client.cc b/chrome/browser/metrics/chrome_metrics_service_client.cc |
index 7599f4cd0956a206c42d133bb714711104322ad9..ae8a2358f6553d4668ee8034f5fa2de2fa63a885 100644 |
--- a/chrome/browser/metrics/chrome_metrics_service_client.cc |
+++ b/chrome/browser/metrics/chrome_metrics_service_client.cc |
@@ -6,10 +6,13 @@ |
#include "base/logging.h" |
#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/chrome_notification_types.h" |
#include "chrome/browser/google/google_util.h" |
+#include "chrome/browser/metrics/metrics_service.h" |
#include "chrome/browser/ui/browser_otr_state.h" |
#include "chrome/common/chrome_version_info.h" |
#include "chrome/common/crash_keys.h" |
+#include "content/public/browser/notification_service.h" |
namespace { |
@@ -33,7 +36,8 @@ metrics::SystemProfileProto::Channel AsProtobufChannel( |
} // namespace |
-ChromeMetricsServiceClient::ChromeMetricsServiceClient() { |
+ChromeMetricsServiceClient::ChromeMetricsServiceClient() : service_(NULL) { |
+ RegisterForNotifications(); |
} |
ChromeMetricsServiceClient::~ChromeMetricsServiceClient() { |
@@ -63,3 +67,50 @@ std::string ChromeMetricsServiceClient::GetVersionString() { |
// TODO(asvitkine): Move over from metrics_log.cc |
return std::string(); |
} |
+ |
+void ChromeMetricsServiceClient::RegisterForNotifications() { |
+ registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, |
+ content::NotificationService::AllBrowserContextsAndSources()); |
+ registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSED, |
+ content::NotificationService::AllSources()); |
+ registrar_.Add(this, chrome::NOTIFICATION_TAB_PARENTED, |
+ content::NotificationService::AllSources()); |
+ registrar_.Add(this, chrome::NOTIFICATION_TAB_CLOSING, |
+ content::NotificationService::AllSources()); |
+ registrar_.Add(this, content::NOTIFICATION_LOAD_START, |
+ content::NotificationService::AllSources()); |
+ registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
+ content::NotificationService::AllSources()); |
+ registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
+ content::NotificationService::AllSources()); |
+ registrar_.Add(this, content::NOTIFICATION_RENDER_WIDGET_HOST_HANG, |
+ content::NotificationService::AllSources()); |
+ registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, |
+ content::NotificationService::AllSources()); |
+} |
+ |
+void ChromeMetricsServiceClient::Observe( |
+ int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ |
+ switch (type) { |
+ case chrome::NOTIFICATION_BROWSER_OPENED: |
+ case chrome::NOTIFICATION_BROWSER_CLOSED: |
+ case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: |
+ case chrome::NOTIFICATION_TAB_PARENTED: |
+ case chrome::NOTIFICATION_TAB_CLOSING: |
+ case content::NOTIFICATION_LOAD_STOP: |
+ case content::NOTIFICATION_LOAD_START: |
+ case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: |
+ case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG: |
+ // TODO(isherman): Remove this NULL check: http://crbug.com/375248 |
+ if (service_) |
+ service_->OnApplicationNotIdle(); |
+ break; |
+ |
+ default: |
+ NOTREACHED(); |
+ } |
+} |