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