OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 #include "web_intents_reporting.h" | |
6 | |
7 #include "base/metrics/histogram.h" | |
8 #include "base/string_util.h" | |
9 #include "chrome/browser/intents/web_intents_util.h" | |
10 #include "net/base/mime_util.h" | |
11 #include "webkit/glue/web_intent_data.h" | |
12 | |
13 namespace web_intents { | |
14 namespace { | |
15 | |
16 struct TypeMapping { | |
17 const char* name; | |
18 const TypeId id; | |
19 }; | |
20 | |
21 const TypeMapping kTypeMap[] = { | |
22 { "application", TYPE_ID_APPLICATION }, | |
23 { "audio", TYPE_ID_AUDIO }, | |
24 { "example", TYPE_ID_EXAMPLE }, | |
25 { "image", TYPE_ID_IMAGE }, | |
26 { "message", TYPE_ID_MESSAGE }, | |
27 { "model", TYPE_ID_MODEL }, | |
28 { "multipart", TYPE_ID_MULTIPART }, | |
29 { "text", TYPE_ID_TEXT }, | |
30 { "video", TYPE_ID_VIDEO }, | |
31 }; | |
32 | |
33 // The number of buckets for the histogram of the duration of time spent in a | |
34 // service. | |
35 const int kServiceActiveTimeNumBuckets = 10; | |
36 | |
37 // The lower bound on the tracked duration of time spent in a service. | |
38 // This bound is in seconds. | |
39 const int kServiceActiveDurationMinSeconds = 1; | |
40 | |
41 // The upper bound on the tracked duration of time spent in a service. | |
42 // This bound is in seconds. | |
43 const int kServiceActiveDurationMaxSeconds = 3600; | |
44 | |
45 // UMA bucket range for custom histograms. | |
46 // | |
47 // TODO(rouslan): Remove this once we've migrated to sparse histograms. See | |
48 // http://crbug.com/153891 before changing anything. | |
49 std::vector<int> GetUmaBucketsCustomRange() { | |
50 // Please update these numbers if you add more actions or types. | |
51 const int kNumActions = 7; | |
52 const int kNumTypes = 10; | |
53 std::vector<int> range; | |
54 for (int i = 1; i <= kNumActions; i++) { | |
55 for (int j = 1; j <= kNumTypes; j++) { | |
56 range.push_back(i << 8 | j); | |
57 } | |
58 } | |
59 return range; | |
60 } | |
61 | |
62 // Returns the ActionMapping for |action| if one exists, or NULL. | |
63 TypeId ToTypeId(const string16& type) { | |
64 const std::string iana_type = net::GetIANAMediaType(UTF16ToASCII(type)); | |
65 for (size_t i = 0; i < arraysize(kTypeMap); ++i) { | |
66 if (iana_type == kTypeMap[i].name) { | |
67 return kTypeMap[i].id; | |
68 } | |
69 } | |
70 return TYPE_ID_CUSTOM; | |
71 } | |
72 | |
73 // Records the number of services installed at the time the picker | |
74 // is shown to the user. Drops the size into one of several buckets. | |
75 void RecordInstalledServiceCount(const UMABucket bucket, size_t installed) { | |
76 if (installed == 0) { | |
77 UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.Service.NumInstalled.0.v0", | |
78 bucket, GetUmaBucketsCustomRange()); | |
79 } else if (installed >= 1 && installed <= 4) { | |
80 UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.Service.NumInstalled.1-4.v0", | |
81 bucket, GetUmaBucketsCustomRange()); | |
82 } else if (installed >= 5 && installed <= 8) { | |
83 UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.Service.NumInstalled.5-8.v0", | |
84 bucket, GetUmaBucketsCustomRange()); | |
85 } else { | |
86 UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.Service.NumInstalled.9+.v0", | |
87 bucket, GetUmaBucketsCustomRange()); | |
88 } | |
89 } | |
90 | |
91 } // namespace | |
92 | |
93 UMABucket ToUMABucket(const string16& action, const string16& type) { | |
94 ActionId action_id = ToActionId(action); | |
95 TypeId type_id = ToTypeId(type); | |
96 short bucket_id = (action_id << 8) | type_id; | |
97 DCHECK(bucket_id > 256); | |
98 return static_cast<UMABucket>(bucket_id); | |
99 } | |
100 | |
101 void RecordIntentsDispatchDisabled() { | |
102 UMA_HISTOGRAM_COUNTS("WebIntents.DispatchDisabled", 1); | |
103 } | |
104 | |
105 void RecordIntentDispatchRequested() { | |
106 UMA_HISTOGRAM_COUNTS("WebIntents.Dispatch", 1); | |
107 } | |
108 | |
109 void RecordIntentDispatched(const UMABucket bucket) { | |
110 UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.IntentDispatched.v0", | |
111 bucket, GetUmaBucketsCustomRange()); | |
112 } | |
113 | |
114 void RecordPickerShow(const UMABucket bucket, size_t installed) { | |
115 UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.Picker.Show.v0", | |
116 bucket, GetUmaBucketsCustomRange()); | |
117 RecordInstalledServiceCount(bucket, installed); | |
118 } | |
119 | |
120 void RecordPickerCancel(const UMABucket bucket) { | |
121 UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.Picker.Cancel.v0", | |
122 bucket, GetUmaBucketsCustomRange()); | |
123 } | |
124 | |
125 void RecordServiceInvoke(const UMABucket bucket) { | |
126 UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.Service.Invoked.v0", | |
127 bucket, GetUmaBucketsCustomRange()); | |
128 } | |
129 | |
130 void RecordChooseAnotherService(const UMABucket bucket) { | |
131 UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.Service.ChooseAnother.v0", | |
132 bucket, GetUmaBucketsCustomRange()); | |
133 } | |
134 | |
135 void RecordCWSExtensionInstalled(const UMABucket bucket) { | |
136 UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.Service.CWSInstall.v0", | |
137 bucket, GetUmaBucketsCustomRange()); | |
138 } | |
139 | |
140 void RecordServiceActiveDuration( | |
141 webkit_glue::WebIntentReplyType reply_type, | |
142 const base::TimeDelta& duration) { | |
143 switch (reply_type) { | |
144 case webkit_glue::WEB_INTENT_REPLY_SUCCESS: | |
145 UMA_HISTOGRAM_CUSTOM_TIMES("WebIntents.Service.ActiveDuration.Success", | |
146 duration, | |
147 base::TimeDelta::FromSeconds(kServiceActiveDurationMinSeconds), | |
148 base::TimeDelta::FromSeconds(kServiceActiveDurationMaxSeconds), | |
149 kServiceActiveTimeNumBuckets); | |
150 break; | |
151 case webkit_glue::WEB_INTENT_REPLY_INVALID: | |
152 case webkit_glue::WEB_INTENT_REPLY_FAILURE: | |
153 case webkit_glue::WEB_INTENT_PICKER_CANCELLED: | |
154 case webkit_glue::WEB_INTENT_SERVICE_CONTENTS_CLOSED: | |
155 UMA_HISTOGRAM_CUSTOM_TIMES("WebIntents.Service.ActiveDuration.Failure", | |
156 duration, | |
157 base::TimeDelta::FromSeconds(kServiceActiveDurationMinSeconds), | |
158 base::TimeDelta::FromSeconds(kServiceActiveDurationMaxSeconds), | |
159 kServiceActiveTimeNumBuckets); | |
160 break; | |
161 default: | |
162 NOTREACHED(); | |
163 break; | |
164 } | |
165 } | |
166 | |
167 } // namespace web_intents | |
OLD | NEW |