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

Unified Diff: content/browser/user_metrics.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, 10 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 | « content/browser/notification_service_impl_unittest.cc ('k') | content/public/browser/notification_types.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/user_metrics.cc
diff --git a/content/browser/user_metrics.cc b/content/browser/user_metrics.cc
index 927f3977d6b589f3363ca1c3d9b4a594d48c36ff..a1c7819a5443cae5b22aad918ce3051b06d06b7d 100644
--- a/content/browser/user_metrics.cc
+++ b/content/browser/user_metrics.cc
@@ -4,14 +4,18 @@
#include "content/public/browser/user_metrics.h"
+#include <vector>
+
#include "base/bind.h"
+#include "base/lazy_instance.h"
#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/notification_service.h"
-#include "content/public/browser/notification_types.h"
namespace content {
namespace {
+base::LazyInstance<std::vector<ActionCallback> > g_action_callbacks =
+ LAZY_INSTANCE_INITIALIZER;
+
// Forward declare because of circular dependency.
void CallRecordOnUI(const std::string& action);
@@ -24,10 +28,8 @@ void Record(const char *action) {
return;
}
- NotificationService::current()->Notify(
- NOTIFICATION_USER_ACTION,
- NotificationService::AllSources(),
- Details<const char*>(&action));
+ for (size_t i = 0; i < g_action_callbacks.Get().size(); i++)
+ g_action_callbacks.Get()[i].Run(action);
}
void CallRecordOnUI(const std::string& action) {
@@ -44,4 +46,17 @@ void RecordComputedAction(const std::string& action) {
Record(action.c_str());
}
+void AddActionCallback(const ActionCallback& callback) {
+ g_action_callbacks.Get().push_back(callback);
+}
+
+void RemoveActionCallback(const ActionCallback& callback) {
+ for (size_t i = 0; i < g_action_callbacks.Get().size(); i++) {
+ if (g_action_callbacks.Get()[i].Equals(callback)) {
+ g_action_callbacks.Get().erase(g_action_callbacks.Get().begin() + i);
+ return;
+ }
+ }
+}
+
} // namespace content
« no previous file with comments | « content/browser/notification_service_impl_unittest.cc ('k') | content/public/browser/notification_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698