Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CONTENT_BROWSER_USER_METRICS_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_USER_METRICS_H_ |
| 6 #define CONTENT_BROWSER_USER_METRICS_H_ | 6 #define CONTENT_PUBLIC_BROWSER_USER_METRICS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 12 | 12 |
| 13 // This module provides some helper functions for logging actions tracked by | 13 // This module provides some helper functions for logging actions tracked by |
| 14 // the user metrics system. | 14 // the user metrics system. |
| 15 // | |
| 16 // Note that we do not wrap this in the content namespace to avoid | |
| 17 // making it more difficult to comply with the single-line requirement | |
| 18 // discussed for UserMetrics::RecordAction below. | |
| 15 | 19 |
| 16 | 20 |
| 17 // UserMetricsAction exist purely to standardize on the paramters passed to | 21 // UserMetricsAction exist purely to standardize on the paramters passed to |
| 18 // UserMetrics. That way, our toolset can scan the sourcecode reliable for | 22 // UserMetrics. That way, our toolset can scan the sourcecode reliable for |
| 19 // constructors and extract the associated string constants | 23 // constructors and extract the associated string constants |
| 20 struct UserMetricsAction { | 24 struct UserMetricsAction { |
| 21 const char* str_; | 25 const char* str_; |
| 22 explicit UserMetricsAction(const char* str) : str_(str) {} | 26 explicit UserMetricsAction(const char* str) : str_(str) {} |
| 23 }; | 27 }; |
| 24 | 28 |
| 25 | 29 |
| 26 class CONTENT_EXPORT UserMetrics { | 30 class CONTENT_EXPORT UserMetrics { |
|
jam
2011/12/12 23:06:55
it seems that we don't need the UserMetrics class
| |
| 27 public: | 31 public: |
| 28 // Record that the user performed an action. | 32 // Record that the user performed an action. |
| 29 // "Action" here means a user-generated event: | 33 // "Action" here means a user-generated event: |
| 30 // good: "Reload", "CloseTab", and "IMEInvoked" | 34 // good: "Reload", "CloseTab", and "IMEInvoked" |
| 31 // not good: "SSLDialogShown", "PageLoaded", "DiskFull" | 35 // not good: "SSLDialogShown", "PageLoaded", "DiskFull" |
| 32 // We use this to gather anonymized information about how users are | 36 // We use this to gather anonymized information about how users are |
| 33 // interacting with the browser. | 37 // interacting with the browser. |
| 34 // WARNING: Call this function exactly like this: | 38 // WARNING: Call this function exactly like this: |
| 35 // UserMetrics::RecordAction(UserMetricsAction("foo bar")); | 39 // UserMetrics::RecordAction(UserMetricsAction("foo bar")); |
| 36 // (all on one line and with the metric string literal [no variables]) | 40 // (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. | 41 // because otherwise our processing scripts won't pick up on new actions. |
| 38 // | 42 // |
| 39 // Once a new recorded action is added, run chrome/tools/extract_actions.py | 43 // 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 | 44 // to generate a new mapping of [action hashes -> metric names] and send it |
| 41 // out for review to be updated. | 45 // out for review to be updated. |
| 42 // | 46 // |
| 43 // For more complicated situations (like when there are many different | 47 // For more complicated situations (like when there are many different |
| 44 // possible actions), see RecordComputedAction. | 48 // possible actions), see RecordComputedAction. |
| 45 static void RecordAction(const UserMetricsAction& action); | 49 static void RecordAction(const UserMetricsAction& action); |
| 46 | 50 |
| 47 // This function has identical input and behavior to RecordAction, but is | 51 // This function has identical input and behavior to RecordAction, but is |
| 48 // not automatically found by the action-processing scripts. It can be used | 52 // not automatically found by the action-processing scripts. It can be used |
| 49 // when it's a pain to enumerate all possible actions, but if you use this | 53 // when it's a pain to enumerate all possible actions, but if you use this |
| 50 // you need to also update the rules for extracting known actions in | 54 // you need to also update the rules for extracting known actions in |
| 51 // chrome/tools/extract_actions.py. | 55 // chrome/tools/extract_actions.py. |
| 52 static void RecordComputedAction(const std::string& action); | 56 static void RecordComputedAction(const std::string& action); |
| 53 | |
| 54 private: | |
| 55 static void Record(const char *action); | |
| 56 static void CallRecordOnUI(const std::string& action); | |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 #endif // CONTENT_BROWSER_USER_METRICS_H_ | 59 #endif // CONTENT_PUBLIC_BROWSER_USER_METRICS_H_ |
| OLD | NEW |