ben@chromium.org | b02d8b1 | 2014-01-14 06:24:39 +0900 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BASE_METRICS_USER_METRICS_H_ |
| 6 | #define BASE_METRICS_USER_METRICS_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/base_export.h" |
| 11 | #include "base/callback.h" |
| 12 | #include "base/metrics/user_metrics_action.h" |
beaudoin | 27c49bc | 2016-04-22 23:17:10 +0900 | [diff] [blame] | 13 | #include "base/single_thread_task_runner.h" |
ben@chromium.org | b02d8b1 | 2014-01-14 06:24:39 +0900 | [diff] [blame] | 14 | |
| 15 | namespace base { |
| 16 | |
| 17 | // This module provides some helper functions for logging actions tracked by |
| 18 | // the user metrics system. |
| 19 | |
| 20 | // Record that the user performed an action. |
beaudoin | 27c49bc | 2016-04-22 23:17:10 +0900 | [diff] [blame] | 21 | // This function must be called after the task runner has been set with |
| 22 | // SetRecordActionTaskRunner(). |
isherman@chromium.org | 5694ea0 | 2014-04-10 10:12:36 +0900 | [diff] [blame] | 23 | // |
ben@chromium.org | b02d8b1 | 2014-01-14 06:24:39 +0900 | [diff] [blame] | 24 | // "Action" here means a user-generated event: |
| 25 | // good: "Reload", "CloseTab", and "IMEInvoked" |
| 26 | // not good: "SSLDialogShown", "PageLoaded", "DiskFull" |
| 27 | // We use this to gather anonymized information about how users are |
| 28 | // interacting with the browser. |
| 29 | // WARNING: In calls to this function, UserMetricsAction and a |
| 30 | // string literal parameter must be on the same line, e.g. |
| 31 | // RecordAction(UserMetricsAction("my extremely long action name")); |
| 32 | // This ensures that our processing scripts can associate this action's hash |
| 33 | // with its metric name. Therefore, it will be possible to retrieve the metric |
| 34 | // name from the hash later on. |
| 35 | // |
| 36 | // Once a new recorded action is added, run |
isherman@chromium.org | d54dfe2 | 2014-03-25 09:48:29 +0900 | [diff] [blame] | 37 | // tools/metrics/actions/extract_actions.py |
| 38 | // to add the metric to actions.xml, then update the <owner>s and <description> |
| 39 | // sections. Make sure to include the actions.xml file when you upload your code |
| 40 | // for review! |
ben@chromium.org | b02d8b1 | 2014-01-14 06:24:39 +0900 | [diff] [blame] | 41 | // |
| 42 | // For more complicated situations (like when there are many different |
beaudoin | 27c49bc | 2016-04-22 23:17:10 +0900 | [diff] [blame] | 43 | // possible actions), see RecordComputedAction(). |
ben@chromium.org | b02d8b1 | 2014-01-14 06:24:39 +0900 | [diff] [blame] | 44 | BASE_EXPORT void RecordAction(const UserMetricsAction& action); |
| 45 | |
beaudoin | 27c49bc | 2016-04-22 23:17:10 +0900 | [diff] [blame] | 46 | // This function has identical input and behavior to RecordAction(), but is |
ben@chromium.org | b02d8b1 | 2014-01-14 06:24:39 +0900 | [diff] [blame] | 47 | // not automatically found by the action-processing scripts. It can be used |
| 48 | // when it's a pain to enumerate all possible actions, but if you use this |
| 49 | // you need to also update the rules for extracting known actions in |
| 50 | // tools/metrics/actions/extract_actions.py. |
beaudoin | 27c49bc | 2016-04-22 23:17:10 +0900 | [diff] [blame] | 51 | // This function must be called after the task runner has been set with |
| 52 | // SetRecordActionTaskRunner(). |
ben@chromium.org | b02d8b1 | 2014-01-14 06:24:39 +0900 | [diff] [blame] | 53 | BASE_EXPORT void RecordComputedAction(const std::string& action); |
| 54 | |
| 55 | // Called with the action string. |
beaudoin | 27c49bc | 2016-04-22 23:17:10 +0900 | [diff] [blame] | 56 | typedef Callback<void(const std::string&)> ActionCallback; |
ben@chromium.org | b02d8b1 | 2014-01-14 06:24:39 +0900 | [diff] [blame] | 57 | |
| 58 | // Add/remove action callbacks (see above). |
beaudoin | 27c49bc | 2016-04-22 23:17:10 +0900 | [diff] [blame] | 59 | // These functions must be called after the task runner has been set with |
| 60 | // SetRecordActionTaskRunner(). |
ben@chromium.org | b02d8b1 | 2014-01-14 06:24:39 +0900 | [diff] [blame] | 61 | BASE_EXPORT void AddActionCallback(const ActionCallback& callback); |
| 62 | BASE_EXPORT void RemoveActionCallback(const ActionCallback& callback); |
| 63 | |
beaudoin | 27c49bc | 2016-04-22 23:17:10 +0900 | [diff] [blame] | 64 | // Set the task runner on which to record actions. |
| 65 | BASE_EXPORT void SetRecordActionTaskRunner( |
| 66 | scoped_refptr<SingleThreadTaskRunner> task_runner); |
| 67 | |
ben@chromium.org | b02d8b1 | 2014-01-14 06:24:39 +0900 | [diff] [blame] | 68 | } // namespace base |
| 69 | |
| 70 | #endif // BASE_METRICS_USER_METRICS_H_ |