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

Unified Diff: chrome/browser/extensions/api/metrics/metrics_apitest.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
« no previous file with comments | « no previous file | chrome/browser/metrics/metrics_service.h » ('j') | content/browser/user_metrics.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/metrics/metrics_apitest.cc
diff --git a/chrome/browser/extensions/api/metrics/metrics_apitest.cc b/chrome/browser/extensions/api/metrics/metrics_apitest.cc
index 9ee37b9dc454fa01fdd135d29a5b4c77d8e422b7..e9d5efe3d0ae21ffd99473a2196d921999bafb9e 100644
--- a/chrome/browser/extensions/api/metrics/metrics_apitest.cc
+++ b/chrome/browser/extensions/api/metrics/metrics_apitest.cc
@@ -7,8 +7,7 @@
#include "base/metrics/histogram.h"
#include "base/metrics/statistics_recorder.h"
#include "chrome/browser/extensions/extension_apitest.h"
-#include "content/public/browser/notification_registrar.h"
-#include "content/public/browser/notification_service.h"
+#include "content/public/browser/user_metrics.h"
namespace {
@@ -46,19 +45,18 @@ struct RecordedHistogram {
// This class observes and collects user action notifications that are sent
// by the tests, so that they can be examined afterwards for correctness.
-class UserActionObserver : public content::NotificationObserver {
+class UserActionObserver {
public:
UserActionObserver();
+ ~UserActionObserver();
void ValidateUserActions(const RecordedUserAction* recorded, int count);
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details);
-
private:
typedef std::map<std::string, int> UserActionCountMap;
+ void OnUserAction(const std::string& action);
+
int num_metrics() const {
return count_map_.size();
}
@@ -68,20 +66,25 @@ class UserActionObserver : public content::NotificationObserver {
return i == count_map_.end() ? -1 : i->second;
}
- content::NotificationRegistrar registrar_;
UserActionCountMap count_map_;
+
+ content::ActionCallback action_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(UserActionObserver);
};
-UserActionObserver::UserActionObserver() {
- registrar_.Add(this, content::NOTIFICATION_USER_ACTION,
- content::NotificationService::AllSources());
+UserActionObserver::UserActionObserver()
+ : action_callback_(base::Bind(&UserActionObserver::OnUserAction,
+ base::Unretained(this))) {
+ content::AddActionCallback(action_callback_);
+}
+
+UserActionObserver::~UserActionObserver() {
+ content::RemoveActionCallback(action_callback_);
}
-void UserActionObserver::Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- const char* name = *content::Details<const char*>(details).ptr();
- ++(count_map_[name]);
+void UserActionObserver::OnUserAction(const std::string& action) {
+ ++(count_map_[action]);
}
void UserActionObserver::ValidateUserActions(const RecordedUserAction* recorded,
« no previous file with comments | « no previous file | chrome/browser/metrics/metrics_service.h » ('j') | content/browser/user_metrics.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698