1*635a8641SAndroid Build Coastguard Worker // Copyright 2014 The Chromium Authors. All rights reserved. 2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file. 4*635a8641SAndroid Build Coastguard Worker 5*635a8641SAndroid Build Coastguard Worker #ifndef BASE_METRICS_USER_METRICS_H_ 6*635a8641SAndroid Build Coastguard Worker #define BASE_METRICS_USER_METRICS_H_ 7*635a8641SAndroid Build Coastguard Worker 8*635a8641SAndroid Build Coastguard Worker #include <string> 9*635a8641SAndroid Build Coastguard Worker 10*635a8641SAndroid Build Coastguard Worker #include "base/base_export.h" 11*635a8641SAndroid Build Coastguard Worker #include "base/callback.h" 12*635a8641SAndroid Build Coastguard Worker #include "base/metrics/user_metrics_action.h" 13*635a8641SAndroid Build Coastguard Worker #include "base/single_thread_task_runner.h" 14*635a8641SAndroid Build Coastguard Worker 15*635a8641SAndroid Build Coastguard Worker namespace base { 16*635a8641SAndroid Build Coastguard Worker 17*635a8641SAndroid Build Coastguard Worker // This module provides some helper functions for logging actions tracked by 18*635a8641SAndroid Build Coastguard Worker // the user metrics system. 19*635a8641SAndroid Build Coastguard Worker 20*635a8641SAndroid Build Coastguard Worker // For best practices on deciding when to emit a user action, see 21*635a8641SAndroid Build Coastguard Worker // https://chromium.googlesource.com/chromium/src.git/+/HEAD/tools/metrics/actions/README.md 22*635a8641SAndroid Build Coastguard Worker 23*635a8641SAndroid Build Coastguard Worker // Record that the user performed an action. 24*635a8641SAndroid Build Coastguard Worker // This function must be called after the task runner has been set with 25*635a8641SAndroid Build Coastguard Worker // SetRecordActionTaskRunner(). 26*635a8641SAndroid Build Coastguard Worker // 27*635a8641SAndroid Build Coastguard Worker // "Action" here means a user-generated event: 28*635a8641SAndroid Build Coastguard Worker // good: "Reload", "CloseTab", and "IMEInvoked" 29*635a8641SAndroid Build Coastguard Worker // not good: "SSLDialogShown", "PageLoaded", "DiskFull" 30*635a8641SAndroid Build Coastguard Worker // We use this to gather anonymized information about how users are 31*635a8641SAndroid Build Coastguard Worker // interacting with the browser. 32*635a8641SAndroid Build Coastguard Worker // WARNING: In calls to this function, UserMetricsAction should be followed by a 33*635a8641SAndroid Build Coastguard Worker // string literal parameter and not a variable e.g. 34*635a8641SAndroid Build Coastguard Worker // RecordAction(UserMetricsAction("my action name")); 35*635a8641SAndroid Build Coastguard Worker // This ensures that our processing scripts can associate this action's hash 36*635a8641SAndroid Build Coastguard Worker // with its metric name. Therefore, it will be possible to retrieve the metric 37*635a8641SAndroid Build Coastguard Worker // name from the hash later on. 38*635a8641SAndroid Build Coastguard Worker // 39*635a8641SAndroid Build Coastguard Worker // Once a new recorded action is added, run 40*635a8641SAndroid Build Coastguard Worker // tools/metrics/actions/extract_actions.py 41*635a8641SAndroid Build Coastguard Worker // to add the metric to actions.xml, then update the <owner>s and <description> 42*635a8641SAndroid Build Coastguard Worker // sections. Make sure to include the actions.xml file when you upload your code 43*635a8641SAndroid Build Coastguard Worker // for review! 44*635a8641SAndroid Build Coastguard Worker // 45*635a8641SAndroid Build Coastguard Worker // For more complicated situations (like when there are many different 46*635a8641SAndroid Build Coastguard Worker // possible actions), see RecordComputedAction(). 47*635a8641SAndroid Build Coastguard Worker BASE_EXPORT void RecordAction(const UserMetricsAction& action); 48*635a8641SAndroid Build Coastguard Worker 49*635a8641SAndroid Build Coastguard Worker // This function has identical input and behavior to RecordAction(), but is 50*635a8641SAndroid Build Coastguard Worker // not automatically found by the action-processing scripts. It can be used 51*635a8641SAndroid Build Coastguard Worker // when it's a pain to enumerate all possible actions, but if you use this 52*635a8641SAndroid Build Coastguard Worker // you need to also update the rules for extracting known actions in 53*635a8641SAndroid Build Coastguard Worker // tools/metrics/actions/extract_actions.py. 54*635a8641SAndroid Build Coastguard Worker // This function must be called after the task runner has been set with 55*635a8641SAndroid Build Coastguard Worker // SetRecordActionTaskRunner(). 56*635a8641SAndroid Build Coastguard Worker BASE_EXPORT void RecordComputedAction(const std::string& action); 57*635a8641SAndroid Build Coastguard Worker 58*635a8641SAndroid Build Coastguard Worker // Called with the action string. 59*635a8641SAndroid Build Coastguard Worker typedef Callback<void(const std::string&)> ActionCallback; 60*635a8641SAndroid Build Coastguard Worker 61*635a8641SAndroid Build Coastguard Worker // Add/remove action callbacks (see above). 62*635a8641SAndroid Build Coastguard Worker // These functions must be called after the task runner has been set with 63*635a8641SAndroid Build Coastguard Worker // SetRecordActionTaskRunner(). 64*635a8641SAndroid Build Coastguard Worker BASE_EXPORT void AddActionCallback(const ActionCallback& callback); 65*635a8641SAndroid Build Coastguard Worker BASE_EXPORT void RemoveActionCallback(const ActionCallback& callback); 66*635a8641SAndroid Build Coastguard Worker 67*635a8641SAndroid Build Coastguard Worker // Set the task runner on which to record actions. 68*635a8641SAndroid Build Coastguard Worker BASE_EXPORT void SetRecordActionTaskRunner( 69*635a8641SAndroid Build Coastguard Worker scoped_refptr<SingleThreadTaskRunner> task_runner); 70*635a8641SAndroid Build Coastguard Worker 71*635a8641SAndroid Build Coastguard Worker } // namespace base 72*635a8641SAndroid Build Coastguard Worker 73*635a8641SAndroid Build Coastguard Worker #endif // BASE_METRICS_USER_METRICS_H_ 74