1 // Copyright (c) 2010 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 CHROME_BROWSER_METRICS_USER_METRICS_H_ 6 #define CHROME_BROWSER_METRICS_USER_METRICS_H_ 7 #pragma once 8 9 #include <string> 10 11 class Profile; 12 13 // This module provides some helper functions for logging actions tracked by 14 // the user metrics system. 15 16 17 // UserMetricsAction exist purely to standardize on the paramters passed to 18 // UserMetrics. That way, our toolset can scan the sourcecode reliable for 19 // constructors and extract the associated string constants 20 struct UserMetricsAction { 21 const char* str_; UserMetricsActionUserMetricsAction22 explicit UserMetricsAction(const char* str) : str_(str) {} 23 }; 24 25 26 class UserMetrics { 27 public: 28 // Record that the user performed an action. 29 // "Action" here means a user-generated event: 30 // good: "Reload", "CloseTab", and "IMEInvoked" 31 // not good: "SSLDialogShown", "PageLoaded", "DiskFull" 32 // We use this to gather anonymized information about how users are 33 // interacting with the browser. 34 // WARNING: Call this function exactly like this: 35 // UserMetrics::RecordAction(UserMetricsAction("foo bar")); 36 // (all on one line and with the metric string literal [no variables]) 37 // because otherwise our processing scripts won't pick up on new actions. 38 // 39 // Once a new recorded action is added, run chrome/tools/extract_actions.py 40 // to generate a new mapping of [action hashes -> metric names] and send it 41 // out for review to be updated. 42 // 43 // For more complicated situations (like when there are many different 44 // possible actions), see RecordComputedAction. 45 // 46 // TODO(semenzato): |profile| isn't actually used---should switch all calls 47 // to the version without it. 48 static void RecordAction(const UserMetricsAction& action, Profile* profile); 49 50 // This function has identical input and behavior to RecordAction, but is 51 // not automatically found by the action-processing scripts. It can be used 52 // when it's a pain to enumerate all possible actions, but if you use this 53 // you need to also update the rules for extracting known actions in 54 // chrome/tools/extract_actions.py. 55 static void RecordComputedAction(const std::string& action, 56 Profile* profile); 57 58 static void RecordAction(const UserMetricsAction& action); 59 static void RecordComputedAction(const std::string& action); 60 61 private: 62 static void Record(const char *action, Profile *profile); 63 static void Record(const char *action); 64 static void CallRecordOnUI(const std::string& action); 65 }; 66 67 #endif // CHROME_BROWSER_METRICS_USER_METRICS_H_ 68