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

Side by Side 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: update extract_actions.py 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/tools/chromeactions.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/chromeos/external_metrics.h" 5 #include "chrome/browser/chromeos/external_metrics.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
11 #include <unistd.h> 11 #include <unistd.h>
12 #include <sys/file.h> 12 #include <sys/file.h>
13 #include <sys/stat.h> 13 #include <sys/stat.h>
14 #include <sys/types.h> 14 #include <sys/types.h>
15 15
16 #include "base/basictypes.h" 16 #include "base/basictypes.h"
17 #include "base/eintr_wrapper.h" 17 #include "base/eintr_wrapper.h"
18 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
19 #include "base/perftimer.h" 19 #include "base/perftimer.h"
20 #include "base/time.h" 20 #include "base/time.h"
21 #include "chrome/browser/browser_thread.h" 21 #include "chrome/browser/browser_thread.h"
22 #include "chrome/browser/metrics/user_metrics.h" 22 #include "chrome/browser/metrics/user_metrics.h"
23 23
24 // Steps to add an action.
25 //
26 // 1. Enter a helper function that calls UserMetrics::RecordAction.
27 //
28 // 2. Add a line for that function in InitializeUserActions.
29 //
30 // 3. Enjoy the recompilation.
31 //
32 // TODO(semenzato): should see if it is possible to avoid recompiling code
33 // every time a new user action is added, and register it in some other way.
34
35 namespace chromeos { 24 namespace chromeos {
36 25
37 // The interval between external metrics collections, in milliseconds. 26 // The interval between external metrics collections, in milliseconds.
38 static const int kExternalMetricsCollectionIntervalMs = 30 * 1000; 27 static const int kExternalMetricsCollectionIntervalMs = 30 * 1000;
39 28
40 // There is one of the following functions for every user action as we have to
41 // call RecordAction in a way that gets picked up by the processing scripts.
42 static void RecordTabOverviewKeystroke() {
43 UserMetrics::RecordAction(UserMetricsAction("TabOverview_Keystroke"));
44 }
45
46 static void RecordTabOverviewExitMouse() {
47 UserMetrics::RecordAction(UserMetricsAction("TabOverview_ExitMouse"));
48 }
49
50 void ExternalMetrics::Start() { 29 void ExternalMetrics::Start() {
51 InitializeUserActions();
52 ScheduleCollector(); 30 ScheduleCollector();
53 } 31 }
54 32
55 void ExternalMetrics::DefineUserAction(const std::string& name,
56 RecordFunctionType f) {
57 DCHECK(action_recorders_.find(name) == action_recorders_.end());
58 action_recorders_[name] = f;
59 }
60
61 void ExternalMetrics::InitializeUserActions() {
62 DefineUserAction("TabOverviewExitMouse", RecordTabOverviewExitMouse);
Daniel Erat 2011/01/20 00:44:23 I don't think that these exist anymore, so I'm not
petkov 2011/01/20 01:00:53 I'm not sure these ever existed...
63 DefineUserAction("TabOverviewKeystroke", RecordTabOverviewKeystroke);
64 }
65
66 void ExternalMetrics::RecordActionUI(std::string action_string) { 33 void ExternalMetrics::RecordActionUI(std::string action_string) {
67 base::hash_map<std::string, RecordFunctionType>::const_iterator iterator; 34 UserMetrics::RecordComputedAction(action_string);
68 iterator = action_recorders_.find(action_string);
69 if (iterator == action_recorders_.end()) {
70 LOG(ERROR) << "undefined UMA action: " << action_string;
71 } else {
72 iterator->second();
73 }
74 } 35 }
75 36
76 void ExternalMetrics::RecordAction(const char* action) { 37 void ExternalMetrics::RecordAction(const char* action) {
77 std::string action_string(action); 38 std::string action_string(action);
78 BrowserThread::PostTask( 39 BrowserThread::PostTask(
79 BrowserThread::UI, FROM_HERE, 40 BrowserThread::UI, FROM_HERE,
80 NewRunnableMethod(this, &ExternalMetrics::RecordActionUI, action)); 41 NewRunnableMethod(this, &ExternalMetrics::RecordActionUI, action_string));
81 } 42 }
82 43
83 void ExternalMetrics::RecordHistogram(const char* histogram_data) { 44 void ExternalMetrics::RecordHistogram(const char* histogram_data) {
84 int sample, min, max, nbuckets; 45 int sample, min, max, nbuckets;
85 char name[128]; // length must be consistent with sscanf format below. 46 char name[128]; // length must be consistent with sscanf format below.
86 int n = sscanf(histogram_data, "%127s %d %d %d %d", 47 int n = sscanf(histogram_data, "%127s %d %d %d %d",
87 name, &sample, &min, &max, &nbuckets); 48 name, &sample, &min, &max, &nbuckets);
88 if (n != 5) { 49 if (n != 5) {
89 LOG(ERROR) << "bad histogram request: " << histogram_data; 50 LOG(ERROR) << "bad histogram request: " << histogram_data;
90 return; 51 return;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 void ExternalMetrics::ScheduleCollector() { 191 void ExternalMetrics::ScheduleCollector() {
231 bool result; 192 bool result;
232 result = BrowserThread::PostDelayedTask( 193 result = BrowserThread::PostDelayedTask(
233 BrowserThread::FILE, FROM_HERE, NewRunnableMethod( 194 BrowserThread::FILE, FROM_HERE, NewRunnableMethod(
234 this, &chromeos::ExternalMetrics::CollectEventsAndReschedule), 195 this, &chromeos::ExternalMetrics::CollectEventsAndReschedule),
235 kExternalMetricsCollectionIntervalMs); 196 kExternalMetricsCollectionIntervalMs);
236 DCHECK(result); 197 DCHECK(result);
237 } 198 }
238 199
239 } // namespace chromeos 200 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/tools/chromeactions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698