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

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: rebase 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 fd5f73f9a13c99413556f83c13938a44d6d60aa5..5154ff0309ead133df588a8b811736765d16f986 100644
--- a/chrome/browser/metrics/metrics_service.cc
+++ b/chrome/browser/metrics/metrics_service.cc
@@ -629,6 +629,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() {
@@ -638,6 +642,7 @@ void MetricsService::DisableRecording() {
return;
recording_active_ = false;
+ content::RemoveActionCallback(action_callback_);
registrar_.RemoveAll();
PushPendingLogsToPersistentStorage();
DCHECK(!log_manager_.has_staged_log());
@@ -661,8 +666,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,
@@ -693,15 +696,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();
@@ -1035,6 +1033,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) {
@@ -1892,10 +1898,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.
« no previous file with comments | « chrome/browser/metrics/metrics_service.h ('k') | chrome/browser/ui/webui/user_actions/user_actions_ui_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698