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

Unified Diff: chrome/browser/metrics/metrics_service.cc

Issue 12039079: content: convert user action notification to observer usage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 7 years, 11 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
Index: chrome/browser/metrics/metrics_service.cc
diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc
index 303adb046ffbb9b456dcba173b343c25d46a6ba3..7befa0cfe5ebb01e7361835453482cbe46f1e167 100644
--- a/chrome/browser/metrics/metrics_service.cc
+++ b/chrome/browser/metrics/metrics_service.cc
@@ -636,6 +636,10 @@ void MetricsService::EnableRecording() {
OpenNewLog();
SetUpNotifications(&registrar_, this);
+ content::RemoveActionCallback(action_callback_);
+ action_callback_ = base::Bind(&MetricsService::OnUserAction,
+ base::Unretained(this));
+ content::AddActionCallback(action_callback_);
}
void MetricsService::DisableRecording() {
@@ -645,6 +649,7 @@ void MetricsService::DisableRecording() {
return;
recording_active_ = false;
+ content::RemoveActionCallback(action_callback_);
registrar_.RemoveAll();
PushPendingLogsToPersistentStorage();
DCHECK(!log_manager_.has_staged_log());
@@ -668,8 +673,6 @@ void MetricsService::SetUpNotifications(
content::NotificationService::AllBrowserContextsAndSources());
registrar->Add(observer, chrome::NOTIFICATION_BROWSER_CLOSED,
content::NotificationService::AllSources());
- registrar->Add(observer, content::NOTIFICATION_USER_ACTION,
- content::NotificationService::AllSources());
registrar->Add(observer, chrome::NOTIFICATION_TAB_PARENTED,
content::NotificationService::AllSources());
registrar->Add(observer, chrome::NOTIFICATION_TAB_CLOSING,
@@ -702,15 +705,10 @@ void MetricsService::Observe(int type,
DCHECK(log_manager_.current_log());
DCHECK(IsSingleThreaded());
- if (!CanLogNotification(type, source, details))
+ if (!CanLogNotification())
return;
switch (type) {
- case content::NOTIFICATION_USER_ACTION:
- log_manager_.current_log()->RecordUserAction(
- *content::Details<const char*>(details).ptr());
- break;
-
case chrome::NOTIFICATION_BROWSER_OPENED:
case chrome::NOTIFICATION_BROWSER_CLOSED: {
Browser* browser = content::Source<Browser>(source).ptr();
@@ -1050,6 +1048,14 @@ void MetricsService::OnInitTaskGotGoogleUpdateData(
self_ptr_factory_.GetWeakPtr());
}
+void MetricsService::OnUserAction(const std::string& action) {
+ if (!CanLogNotification())
+ return;
+
+ log_manager_.current_log()->RecordUserAction(action.c_str());
+ HandleIdleSinceLastTransmission(false);
+}
+
void MetricsService::ReceivedProfilerData(
const tracked_objects::ProcessDataSnapshot& process_data,
content::ProcessType process_type) {
@@ -1945,10 +1951,7 @@ void MetricsService::RecordPluginChanges(PrefService* pref) {
child_process_stats_buffer_.clear();
}
-bool MetricsService::CanLogNotification(
- int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
+bool MetricsService::CanLogNotification() {
// We simply don't log anything to UMA if there is a single incognito
// session visible. The problem is that we always notify using the orginal
// profile in order to simplify notification processing.

Powered by Google App Engine
This is Rietveld 408576698