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

Side by Side Diff: ios/chrome/browser/metrics/first_user_action_recorder.h

Issue 2585233003: Upstream Chrome on iOS source code [2/11]. (Closed)
Patch Set: Created 4 years 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
OLDNEW
(Empty)
1 // Copyright 2013 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 IOS_CHROME_BROWSER_METRICS_FIRST_USER_ACTION_RECORDER_H_
6 #define IOS_CHROME_BROWSER_METRICS_FIRST_USER_ACTION_RECORDER_H_
7
8 #include <vector>
9
10 #include "base/metrics/user_metrics.h"
11 #include "base/time/time.h"
12
13 // Histogram names (visible for testing only).
14 // Each is a 2-element array where the first element is the
15 // name of the histogram for handsets and the second is the name of the
16 // histogram for tablets.
17
18 // The histogram to plot background duration before 'new task' actions.
19 extern const char* kFirstUserActionNewTaskHistogramName[];
20
21 // The histogram to plot background duration before 'continuation' actions.
22 extern const char* kFirstUserActionContinuationHistogramName[];
23
24 // The histogram to plot background duration before 'expiration' actions.
25 extern const char* kFirstUserActionExpirationHistogramName[];
26
27 // The name of the histogram to plot the type of first user action (see
28 // |FirstUserActionType|).
29 extern const char* kFirstUserActionTypeHistogramName[];
30
31 // Since it logs user actions while it exists, it should only be instantiated
32 // while metrics recording is enabled.
33 class FirstUserActionRecorder {
34 public:
35 // Indicies of the histogram name arrays for each device family.
36 enum DeviceFamilyIndex { HANDSET = 0, TABLET = 1 };
37
38 // Values of the first user action type histogram.
39 enum FirstUserActionType {
40 NEW_TASK = 0,
41 CONTINUATION,
42 EXPIRATION,
43 START_ON_NTP,
44 FIRST_USER_ACTION_TYPE_COUNT,
45 };
46
47 explicit FirstUserActionRecorder(base::TimeDelta background_duration);
48 virtual ~FirstUserActionRecorder();
49
50 // Records that no applicable user action occurred.
51 void Expire();
52
53 // Records that the app started with the NTP active.
54 void RecordStartOnNTP();
55
56 private:
57 // Records metrics if |action_name| indicates the start of a new task or the
58 // continuation of an existing task.
59 void OnUserAction(const std::string& action_name);
60
61 // Records the appropriate metrics for the given action type.
62 void RecordAction(const FirstUserActionType& action_type,
63 const std::string& log_message);
64
65 // Returns true if the specified action should be processed, or false if the
66 // action should be ignored.
67 bool ShouldProcessAction(const std::string& action_name);
68
69 // Returns true if the given array contains the given string.
70 bool ArrayContainsString(const char* to_search[],
71 const size_t to_search_size,
72 const char* to_find);
73
74 // True if running on a tablet.
75 const DeviceFamilyIndex device_family_;
76
77 // True if this instance has recorded a 'new task' or 'continuation task'
78 // metric.
79 bool recorded_action_;
80
81 // True if this instance has rethrown an action.
82 bool action_pending_;
83
84 // The amount of time the app was in the background before this recorder was
85 // created.
86 base::TimeDelta background_duration_;
87
88 // The callback to invoke when an action is recorded.
89 base::ActionCallback action_callback_;
90
91 DISALLOW_COPY_AND_ASSIGN(FirstUserActionRecorder);
92 };
93
94 #endif // IOS_CHROME_BROWSER_METRICS_FIRST_USER_ACTION_RECORDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698