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

Side by Side Diff: base/metrics/user_metrics.h

Issue 1859213002: Move the thread hop for UMA user actions from content:: to base::. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Initializing in content. Created 4 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/metrics/user_metrics.cc » ('j') | content/browser/browser_main_loop.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef BASE_METRICS_USER_METRICS_H_ 5 #ifndef BASE_METRICS_USER_METRICS_H_
6 #define BASE_METRICS_USER_METRICS_H_ 6 #define BASE_METRICS_USER_METRICS_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/base_export.h" 10 #include "base/base_export.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/metrics/user_metrics_action.h" 12 #include "base/metrics/user_metrics_action.h"
13 #include "base/single_thread_task_runner.h"
13 14
14 namespace base { 15 namespace base {
15 16
16 // This module provides some helper functions for logging actions tracked by 17 // This module provides some helper functions for logging actions tracked by
17 // the user metrics system. 18 // the user metrics system.
18 19
19 // Record that the user performed an action. 20 // Record that the user performed an action.
20 // This method *must* be called from the main thread. 21 // This function must be called after the task runner has been set with
22 // SetRecordActionTaskRunner().
21 // 23 //
22 // "Action" here means a user-generated event: 24 // "Action" here means a user-generated event:
23 // good: "Reload", "CloseTab", and "IMEInvoked" 25 // good: "Reload", "CloseTab", and "IMEInvoked"
24 // not good: "SSLDialogShown", "PageLoaded", "DiskFull" 26 // not good: "SSLDialogShown", "PageLoaded", "DiskFull"
25 // We use this to gather anonymized information about how users are 27 // We use this to gather anonymized information about how users are
26 // interacting with the browser. 28 // interacting with the browser.
27 // WARNING: In calls to this function, UserMetricsAction and a 29 // WARNING: In calls to this function, UserMetricsAction and a
28 // string literal parameter must be on the same line, e.g. 30 // string literal parameter must be on the same line, e.g.
29 // RecordAction(UserMetricsAction("my extremely long action name")); 31 // RecordAction(UserMetricsAction("my extremely long action name"));
30 // This ensures that our processing scripts can associate this action's hash 32 // This ensures that our processing scripts can associate this action's hash
31 // with its metric name. Therefore, it will be possible to retrieve the metric 33 // with its metric name. Therefore, it will be possible to retrieve the metric
32 // name from the hash later on. 34 // name from the hash later on.
33 // 35 //
34 // Once a new recorded action is added, run 36 // Once a new recorded action is added, run
35 // tools/metrics/actions/extract_actions.py 37 // tools/metrics/actions/extract_actions.py
36 // to add the metric to actions.xml, then update the <owner>s and <description> 38 // to add the metric to actions.xml, then update the <owner>s and <description>
37 // sections. Make sure to include the actions.xml file when you upload your code 39 // sections. Make sure to include the actions.xml file when you upload your code
38 // for review! 40 // for review!
39 // 41 //
40 // For more complicated situations (like when there are many different 42 // For more complicated situations (like when there are many different
41 // possible actions), see RecordComputedAction. 43 // possible actions), see RecordComputedAction().
42 BASE_EXPORT void RecordAction(const UserMetricsAction& action); 44 BASE_EXPORT void RecordAction(const UserMetricsAction& action);
43 45
44 // This function has identical input and behavior to RecordAction, but is 46 // This function has identical input and behavior to RecordAction(), but is
45 // not automatically found by the action-processing scripts. It can be used 47 // not automatically found by the action-processing scripts. It can be used
46 // when it's a pain to enumerate all possible actions, but if you use this 48 // when it's a pain to enumerate all possible actions, but if you use this
47 // you need to also update the rules for extracting known actions in 49 // you need to also update the rules for extracting known actions in
48 // tools/metrics/actions/extract_actions.py. 50 // tools/metrics/actions/extract_actions.py.
51 // This function must be called after the task runner has been set with
52 // SetRecordActionTaskRunner().
49 BASE_EXPORT void RecordComputedAction(const std::string& action); 53 BASE_EXPORT void RecordComputedAction(const std::string& action);
50 54
51 // Called with the action string. 55 // Called with the action string.
52 typedef base::Callback<void(const std::string&)> ActionCallback; 56 typedef Callback<void(const std::string&)> ActionCallback;
53 57
54 // Add/remove action callbacks (see above). 58 // Add/remove action callbacks (see above).
59 // These functions must be called after the task runner has been set with
60 // SetRecordActionTaskRunner().
55 BASE_EXPORT void AddActionCallback(const ActionCallback& callback); 61 BASE_EXPORT void AddActionCallback(const ActionCallback& callback);
56 BASE_EXPORT void RemoveActionCallback(const ActionCallback& callback); 62 BASE_EXPORT void RemoveActionCallback(const ActionCallback& callback);
57 63
64 // Set the task runner on which to record actions.
65 BASE_EXPORT void SetRecordActionTaskRunner(
66 scoped_refptr<SingleThreadTaskRunner> task_runner);
67
58 } // namespace base 68 } // namespace base
59 69
60 #endif // BASE_METRICS_USER_METRICS_H_ 70 #endif // BASE_METRICS_USER_METRICS_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/user_metrics.cc » ('j') | content/browser/browser_main_loop.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698