Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(718)

Unified Diff: chrome/browser/chromeos/external_metrics.cc

Issue 6266011: chromeos: Simplify user action code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/browser
Patch Set: only insert user actions when metrics collection is started Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/external_metrics.h ('k') | chrome/tools/chromeactions.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/external_metrics.cc
diff --git a/chrome/browser/chromeos/external_metrics.cc b/chrome/browser/chromeos/external_metrics.cc
index 73e24d82a873bc6e35f688486e2144f6b3d6f70c..08be59bc3565e8025156c3e14a23b5917e525d1c 100644
--- a/chrome/browser/chromeos/external_metrics.cc
+++ b/chrome/browser/chromeos/external_metrics.cc
@@ -21,55 +21,36 @@
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/metrics/user_metrics.h"
-// Steps to add an action.
-//
-// 1. Enter a helper function that calls UserMetrics::RecordAction.
-//
-// 2. Add a line for that function in InitializeUserActions.
-//
-// 3. Enjoy the recompilation.
-//
-// TODO(semenzato): should see if it is possible to avoid recompiling code
-// every time a new user action is added, and register it in some other way.
-
namespace chromeos {
// The interval between external metrics collections, in milliseconds.
static const int kExternalMetricsCollectionIntervalMs = 30 * 1000;
-// There is one of the following functions for every user action as we have to
-// call RecordAction in a way that gets picked up by the processing scripts.
-static void RecordTabOverviewKeystroke() {
- UserMetrics::RecordAction(UserMetricsAction("TabOverview_Keystroke"));
-}
-
-static void RecordTabOverviewExitMouse() {
- UserMetrics::RecordAction(UserMetricsAction("TabOverview_ExitMouse"));
+ExternalMetrics::ExternalMetrics()
+ : test_recorder_(NULL) {
}
void ExternalMetrics::Start() {
- InitializeUserActions();
- ScheduleCollector();
-}
+ // Register user actions external to the browser.
+ // chrome/tools/extract_actions.py won't understand these lines, so all of
+ // these are explicitly added in that script.
+ // TODO(derat): We shouldn't need to verify actions before reporting them;
petkov 2011/01/21 18:03:42 Or we can modify the regular expression in extract
+ // remove all of this once http://crosbug.com/11125 is fixed.
+ valid_user_actions_.insert("Accel_NextWindow_Tab");
+ valid_user_actions_.insert("Accel_PrevWindow_Tab");
+ valid_user_actions_.insert("Accel_NextWindow_F5");
+ valid_user_actions_.insert("Accel_PrevWindow_F5");
+ valid_user_actions_.insert("Accel_BrightnessDown_F6");
+ valid_user_actions_.insert("Accel_BrightnessUp_F7");
-void ExternalMetrics::DefineUserAction(const std::string& name,
- RecordFunctionType f) {
- DCHECK(action_recorders_.find(name) == action_recorders_.end());
- action_recorders_[name] = f;
-}
-
-void ExternalMetrics::InitializeUserActions() {
- DefineUserAction("TabOverviewExitMouse", RecordTabOverviewExitMouse);
- DefineUserAction("TabOverviewKeystroke", RecordTabOverviewKeystroke);
+ ScheduleCollector();
}
void ExternalMetrics::RecordActionUI(std::string action_string) {
- base::hash_map<std::string, RecordFunctionType>::const_iterator iterator;
- iterator = action_recorders_.find(action_string);
- if (iterator == action_recorders_.end()) {
- LOG(ERROR) << "undefined UMA action: " << action_string;
+ if (valid_user_actions_.count(action_string)) {
+ UserMetrics::RecordComputedAction(action_string);
} else {
- iterator->second();
+ LOG(ERROR) << "undefined UMA action: " << action_string;
}
}
@@ -77,7 +58,7 @@ void ExternalMetrics::RecordAction(const char* action) {
std::string action_string(action);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- NewRunnableMethod(this, &ExternalMetrics::RecordActionUI, action));
+ NewRunnableMethod(this, &ExternalMetrics::RecordActionUI, action_string));
}
void ExternalMetrics::RecordHistogram(const char* histogram_data) {
« no previous file with comments | « chrome/browser/chromeos/external_metrics.h ('k') | chrome/tools/chromeactions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698