1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/public/browser/user_metrics.h"
10 #include "base/lazy_instance.h"
11 #include "content/public/browser/browser_thread.h"
16 base::LazyInstance<std::vector<ActionCallback> > g_action_callbacks =
17 LAZY_INSTANCE_INITIALIZER;
19 // Forward declare because of circular dependency.
20 void CallRecordOnUI(const std::string& action);
22 void Record(const char *action) {
23 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
24 BrowserThread::PostTask(
27 base::Bind(&CallRecordOnUI, action));
31 for (size_t i = 0; i < g_action_callbacks.Get().size(); i++)
32 g_action_callbacks.Get()[i].Run(action);
35 void CallRecordOnUI(const std::string& action) {
36 Record(action.c_str());
41 void RecordAction(const UserMetricsAction& action) {
45 void RecordComputedAction(const std::string& action) {
46 Record(action.c_str());
49 void AddActionCallback(const ActionCallback& callback) {
50 g_action_callbacks.Get().push_back(callback);
53 void RemoveActionCallback(const ActionCallback& callback) {
54 for (size_t i = 0; i < g_action_callbacks.Get().size(); i++) {
55 if (g_action_callbacks.Get()[i].Equals(callback)) {
56 g_action_callbacks.Get().erase(g_action_callbacks.Get().begin() + i);
62 } // namespace content