OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/public/browser/user_metrics.h" | 5 #include "content/public/browser/user_metrics.h" |
6 | 6 |
7 #include <vector> | |
8 | |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/lazy_instance.h" | |
8 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
9 #include "content/public/browser/notification_service.h" | |
10 #include "content/public/browser/notification_types.h" | |
11 | 12 |
12 namespace content { | 13 namespace content { |
13 namespace { | 14 namespace { |
14 | 15 |
16 base::LazyInstance<std::vector<ActionCallback> > g_action_callbacks = | |
17 LAZY_INSTANCE_INITIALIZER; | |
18 | |
15 // Forward declare because of circular dependency. | 19 // Forward declare because of circular dependency. |
16 void CallRecordOnUI(const std::string& action); | 20 void CallRecordOnUI(const std::string& action); |
17 | 21 |
18 void Record(const char *action) { | 22 void Record(const char *action) { |
19 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 23 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
20 BrowserThread::PostTask( | 24 BrowserThread::PostTask( |
21 BrowserThread::UI, | 25 BrowserThread::UI, |
22 FROM_HERE, | 26 FROM_HERE, |
23 base::Bind(&CallRecordOnUI, action)); | 27 base::Bind(&CallRecordOnUI, action)); |
24 return; | 28 return; |
25 } | 29 } |
26 | 30 |
27 NotificationService::current()->Notify( | 31 for (std::vector<ActionCallback>::iterator i = |
jam
2013/01/30 17:53:24
nit: size_t is more readable for vectors
Paweł Hajdan Jr.
2013/01/31 14:34:44
Done.
| |
28 NOTIFICATION_USER_ACTION, | 32 g_action_callbacks.Get().begin(); |
29 NotificationService::AllSources(), | 33 i != g_action_callbacks.Get().end(); |
30 Details<const char*>(&action)); | 34 ++i) { |
35 (*i).Run(action); | |
36 } | |
31 } | 37 } |
32 | 38 |
33 void CallRecordOnUI(const std::string& action) { | 39 void CallRecordOnUI(const std::string& action) { |
34 Record(action.c_str()); | 40 Record(action.c_str()); |
35 } | 41 } |
36 | 42 |
37 } // namespace | 43 } // namespace |
38 | 44 |
39 void RecordAction(const UserMetricsAction& action) { | 45 void RecordAction(const UserMetricsAction& action) { |
40 Record(action.str_); | 46 Record(action.str_); |
41 } | 47 } |
42 | 48 |
43 void RecordComputedAction(const std::string& action) { | 49 void RecordComputedAction(const std::string& action) { |
44 Record(action.c_str()); | 50 Record(action.c_str()); |
45 } | 51 } |
46 | 52 |
53 void AddActionCallback(const ActionCallback& callback) { | |
54 g_action_callbacks.Get().push_back(callback); | |
55 } | |
56 | |
57 void RemoveActionCallback(const ActionCallback& callback) { | |
58 for (std::vector<ActionCallback>::iterator i = | |
59 g_action_callbacks.Get().begin(); | |
60 i != g_action_callbacks.Get().end(); | |
61 ++i) { | |
62 if ((*i).Equals(callback)) { | |
63 i = g_action_callbacks.Get().erase(i); | |
64 } | |
65 } | |
66 } | |
67 | |
47 } // namespace content | 68 } // namespace content |
OLD | NEW |