blob: a1c7819a5443cae5b22aad918ce3051b06d06b7d [file] [log] [blame]
[email protected]b3841c502011-03-09 01:21:311// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]7f6f44c2011-12-14 13:23:385#include "content/public/browser/user_metrics.h"
[email protected]ca59d8a2010-12-23 01:22:046
[email protected]dd98f392013-02-04 13:03:227#include <vector>
8
[email protected]80751052011-11-12 17:10:589#include "base/bind.h"
[email protected]dd98f392013-02-04 13:03:2210#include "base/lazy_instance.h"
[email protected]c38831a12011-10-28 12:44:4911#include "content/public/browser/browser_thread.h"
[email protected]29cf16772010-04-21 15:13:4712
[email protected]46488322012-10-30 03:22:2013namespace content {
[email protected]7f6f44c2011-12-14 13:23:3814namespace {
15
[email protected]dd98f392013-02-04 13:03:2216base::LazyInstance<std::vector<ActionCallback> > g_action_callbacks =
17 LAZY_INSTANCE_INITIALIZER;
18
[email protected]7f6f44c2011-12-14 13:23:3819// Forward declare because of circular dependency.
20void CallRecordOnUI(const std::string& action);
[email protected]29cf16772010-04-21 15:13:4721
[email protected]7f6f44c2011-12-14 13:23:3822void Record(const char *action) {
[email protected]ca59d8a2010-12-23 01:22:0423 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
[email protected]7f6f44c2011-12-14 13:23:3824 BrowserThread::PostTask(
25 BrowserThread::UI,
26 FROM_HERE,
27 base::Bind(&CallRecordOnUI, action));
[email protected]ca59d8a2010-12-23 01:22:0428 return;
29 }
30
[email protected]dd98f392013-02-04 13:03:2231 for (size_t i = 0; i < g_action_callbacks.Get().size(); i++)
32 g_action_callbacks.Get()[i].Run(action);
[email protected]896220042010-03-23 18:14:2833}
34
[email protected]7f6f44c2011-12-14 13:23:3835void CallRecordOnUI(const std::string& action) {
[email protected]ca59d8a2010-12-23 01:22:0436 Record(action.c_str());
37}
[email protected]7f6f44c2011-12-14 13:23:3838
39} // namespace
40
[email protected]7f6f44c2011-12-14 13:23:3841void RecordAction(const UserMetricsAction& action) {
42 Record(action.str_);
43}
44
45void RecordComputedAction(const std::string& action) {
46 Record(action.c_str());
47}
48
[email protected]dd98f392013-02-04 13:03:2249void AddActionCallback(const ActionCallback& callback) {
50 g_action_callbacks.Get().push_back(callback);
51}
52
53void 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);
57 return;
58 }
59 }
60}
61
[email protected]7f6f44c2011-12-14 13:23:3862} // namespace content