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