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

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: callbacks 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..32e9cccb7665a3c5af95dab233694ff1819e8ca8 100644
--- a/chrome/browser/metrics/metrics_service.cc
+++ b/chrome/browser/metrics/metrics_service.cc
@@ -636,6 +636,8 @@ void MetricsService::EnableRecording() {
OpenNewLog();
SetUpNotifications(&registrar_, this);
+ content::AddActionCallback(base::Bind(&MetricsService::OnUserAction,
+ base::Unretained(this)));
}
void MetricsService::DisableRecording() {
@@ -645,6 +647,8 @@ void MetricsService::DisableRecording() {
return;
recording_active_ = false;
+ content::RemoveActionCallback(base::Bind(&MetricsService::OnUserAction,
+ base::Unretained(this)));
registrar_.RemoveAll();
PushPendingLogsToPersistentStorage();
DCHECK(!log_manager_.has_staged_log());
@@ -668,8 +672,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 +704,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();
@@ -791,6 +788,14 @@ void MetricsService::Observe(int type,
HandleIdleSinceLastTransmission(false);
}
+void MetricsService::OnUserAction(const std::string& action) {
+ if (!CanLogNotification())
+ return;
+
+ log_manager_.current_log()->RecordUserAction(action.c_str());
+ HandleIdleSinceLastTransmission(false);
+}
+
void MetricsService::HandleIdleSinceLastTransmission(bool in_idle) {
// If there wasn't a lot of action, maybe the computer was asleep, in which
// case, the log transmissions should have stopped. Here we start them up
@@ -1945,10 +1950,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