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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
|
// 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 "content/browser/download/download_stats.h"
#include "base/metrics/histogram.h"
#include "base/string_util.h"
#include "content/browser/download/download_resource_handler.h"
#include "content/public/browser/download_interrupt_reasons.h"
#include "net/http/http_content_disposition.h"
namespace content {
namespace {
// All possible error codes from the network module. Note that the error codes
// are all positive (since histograms expect positive sample values).
const int kAllInterruptReasonCodes[] = {
#define INTERRUPT_REASON(label, value) (value),
#include "content/public/browser/download_interrupt_reason_values.h"
#undef INTERRUPT_REASON
};
// These values are based on net::HttpContentDisposition::ParseResult values.
// Values other than HEADER_PRESENT and IS_VALID are only measured if |IS_VALID|
// is true.
enum ContentDispositionCountTypes {
// Count of downloads which had a Content-Disposition headers. The total
// number of downloads is measured by UNTHROTTLED_COUNT.
CONTENT_DISPOSITION_HEADER_PRESENT = 0,
// At least one of 'name', 'filename' or 'filenae*' attributes were valid and
// yielded a non-empty filename.
CONTENT_DISPOSITION_IS_VALID,
// The following enum values correspond to
// net::HttpContentDisposition::ParseResult.
CONTENT_DISPOSITION_HAS_DISPOSITION_TYPE,
CONTENT_DISPOSITION_HAS_UNKNOWN_TYPE,
CONTENT_DISPOSITION_HAS_NAME,
CONTENT_DISPOSITION_HAS_FILENAME,
CONTENT_DISPOSITION_HAS_EXT_FILENAME,
CONTENT_DISPOSITION_HAS_NON_ASCII_STRINGS,
CONTENT_DISPOSITION_HAS_PERCENT_ENCODED_STRINGS,
CONTENT_DISPOSITION_HAS_RFC2047_ENCODED_STRINGS,
// Only have the 'name' attribute is present.
CONTENT_DISPOSITION_HAS_NAME_ONLY,
CONTENT_DISPOSITION_LAST_ENTRY
};
void RecordContentDispositionCount(ContentDispositionCountTypes type,
bool record) {
if (!record)
return;
UMA_HISTOGRAM_ENUMERATION(
"Download.ContentDisposition", type, CONTENT_DISPOSITION_LAST_ENTRY);
}
void RecordContentDispositionCountFlag(
ContentDispositionCountTypes type,
int flags_to_test,
net::HttpContentDisposition::ParseResultFlags flag) {
RecordContentDispositionCount(type, (flags_to_test & flag) == flag);
}
} // namespace
void RecordDownloadCount(DownloadCountTypes type) {
UMA_HISTOGRAM_ENUMERATION(
"Download.Counts", type, DOWNLOAD_COUNT_TYPES_LAST_ENTRY);
}
void RecordDownloadSource(DownloadSource source) {
UMA_HISTOGRAM_ENUMERATION(
"Download.Sources", source, DOWNLOAD_SOURCE_LAST_ENTRY);
}
void RecordDownloadCompleted(const base::TimeTicks& start, int64 download_len) {
RecordDownloadCount(COMPLETED_COUNT);
UMA_HISTOGRAM_LONG_TIMES("Download.Time", (base::TimeTicks::Now() - start));
int64 max = 1024 * 1024 * 1024; // One Terabyte.
download_len /= 1024; // In Kilobytes
UMA_HISTOGRAM_CUSTOM_COUNTS("Download.DownloadSize",
download_len,
1,
max,
256);
}
void RecordDownloadInterrupted(DownloadInterruptReason reason,
int64 received,
int64 total) {
RecordDownloadCount(INTERRUPTED_COUNT);
UMA_HISTOGRAM_CUSTOM_ENUMERATION(
"Download.InterruptedReason",
reason,
base::CustomHistogram::ArrayToCustomRanges(
kAllInterruptReasonCodes, arraysize(kAllInterruptReasonCodes)));
// The maximum should be 2^kBuckets, to have the logarithmic bucket
// boundaries fall on powers of 2.
static const int kBuckets = 30;
static const int64 kMaxKb = 1 << kBuckets; // One Terabyte, in Kilobytes.
int64 delta_bytes = total - received;
bool unknown_size = total <= 0;
int64 received_kb = received / 1024;
int64 total_kb = total / 1024;
UMA_HISTOGRAM_CUSTOM_COUNTS("Download.InterruptedReceivedSizeK",
received_kb,
1,
kMaxKb,
kBuckets);
if (!unknown_size) {
UMA_HISTOGRAM_CUSTOM_COUNTS("Download.InterruptedTotalSizeK",
total_kb,
1,
kMaxKb,
kBuckets);
if (delta_bytes == 0) {
RecordDownloadCount(INTERRUPTED_AT_END_COUNT);
UMA_HISTOGRAM_CUSTOM_ENUMERATION(
"Download.InterruptedAtEndReason",
reason,
base::CustomHistogram::ArrayToCustomRanges(
kAllInterruptReasonCodes,
arraysize(kAllInterruptReasonCodes)));
} else if (delta_bytes > 0) {
UMA_HISTOGRAM_CUSTOM_COUNTS("Download.InterruptedOverrunBytes",
delta_bytes,
1,
kMaxKb,
kBuckets);
} else {
UMA_HISTOGRAM_CUSTOM_COUNTS("Download.InterruptedUnderrunBytes",
-delta_bytes,
1,
kMaxKb,
kBuckets);
}
}
UMA_HISTOGRAM_BOOLEAN("Download.InterruptedUnknownSize", unknown_size);
}
void RecordDownloadWriteSize(size_t data_len) {
RecordDownloadCount(WRITE_SIZE_COUNT);
int max = 1024 * 1024; // One Megabyte.
UMA_HISTOGRAM_CUSTOM_COUNTS("Download.WriteSize", data_len, 1, max, 256);
}
void RecordDownloadWriteLoopCount(int count) {
RecordDownloadCount(WRITE_LOOP_COUNT);
UMA_HISTOGRAM_ENUMERATION("Download.WriteLoopCount", count, 20);
}
void RecordAcceptsRanges(const std::string& accepts_ranges,
int64 download_len) {
int64 max = 1024 * 1024 * 1024; // One Terabyte.
download_len /= 1024; // In Kilobytes
static const int kBuckets = 50;
if (LowerCaseEqualsASCII(accepts_ranges, "none")) {
UMA_HISTOGRAM_CUSTOM_COUNTS("Download.AcceptRangesNone.KBytes",
download_len,
1,
max,
kBuckets);
} else if (LowerCaseEqualsASCII(accepts_ranges, "bytes")) {
UMA_HISTOGRAM_CUSTOM_COUNTS("Download.AcceptRangesBytes.KBytes",
download_len,
1,
max,
kBuckets);
} else {
UMA_HISTOGRAM_CUSTOM_COUNTS("Download.AcceptRangesMissingOrInvalid.KBytes",
download_len,
1,
max,
kBuckets);
}
}
namespace {
enum DownloadContent {
DOWNLOAD_CONTENT_UNRECOGNIZED = 0,
DOWNLOAD_CONTENT_TEXT = 1,
DOWNLOAD_CONTENT_IMAGE = 2,
DOWNLOAD_CONTENT_AUDIO = 3,
DOWNLOAD_CONTENT_VIDEO = 4,
DOWNLOAD_CONTENT_OCTET_STREAM = 5,
DOWNLOAD_CONTENT_PDF = 6,
DOWNLOAD_CONTENT_DOC = 7,
DOWNLOAD_CONTENT_XLS = 8,
DOWNLOAD_CONTENT_PPT = 9,
DOWNLOAD_CONTENT_ARCHIVE = 10,
DOWNLOAD_CONTENT_EXE = 11,
DOWNLOAD_CONTENT_DMG = 12,
DOWNLOAD_CONTENT_CRX = 13,
DOWNLOAD_CONTENT_MAX = 14,
};
struct MimeTypeToDownloadContent {
const char* mime_type;
DownloadContent download_content;
};
static MimeTypeToDownloadContent kMapMimeTypeToDownloadContent[] = {
{"application/octet-stream", DOWNLOAD_CONTENT_OCTET_STREAM},
{"binary/octet-stream", DOWNLOAD_CONTENT_OCTET_STREAM},
{"application/pdf", DOWNLOAD_CONTENT_PDF},
{"application/msword", DOWNLOAD_CONTENT_DOC},
{"application/vnd.ms-excel", DOWNLOAD_CONTENT_XLS},
{"application/vns.ms-powerpoint", DOWNLOAD_CONTENT_PPT},
{"application/zip", DOWNLOAD_CONTENT_ARCHIVE},
{"application/x-gzip", DOWNLOAD_CONTENT_ARCHIVE},
{"application/x-rar-compressed", DOWNLOAD_CONTENT_ARCHIVE},
{"application/x-tar", DOWNLOAD_CONTENT_ARCHIVE},
{"application/x-bzip", DOWNLOAD_CONTENT_ARCHIVE},
{"application/x-exe", DOWNLOAD_CONTENT_EXE},
{"application/x-apple-diskimage", DOWNLOAD_CONTENT_DMG},
{"application/x-chrome-extension", DOWNLOAD_CONTENT_CRX},
};
enum DownloadImage {
DOWNLOAD_IMAGE_UNRECOGNIZED = 0,
DOWNLOAD_IMAGE_GIF = 1,
DOWNLOAD_IMAGE_JPEG = 2,
DOWNLOAD_IMAGE_PNG = 3,
DOWNLOAD_IMAGE_TIFF = 4,
DOWNLOAD_IMAGE_ICON = 5,
DOWNLOAD_IMAGE_WEBP = 6,
DOWNLOAD_IMAGE_MAX = 7,
};
struct MimeTypeToDownloadImage {
const char* mime_type;
DownloadImage download_image;
};
static MimeTypeToDownloadImage kMapMimeTypeToDownloadImage[] = {
{"image/gif", DOWNLOAD_IMAGE_GIF},
{"image/jpeg", DOWNLOAD_IMAGE_JPEG},
{"image/png", DOWNLOAD_IMAGE_PNG},
{"image/tiff", DOWNLOAD_IMAGE_TIFF},
{"image/vnd.microsoft.icon", DOWNLOAD_IMAGE_ICON},
{"image/webp", DOWNLOAD_IMAGE_WEBP},
};
void RecordDownloadImageType(const std::string& mime_type_string) {
DownloadImage download_image = DOWNLOAD_IMAGE_UNRECOGNIZED;
// Look up exact matches.
for (size_t i = 0; i < arraysize(kMapMimeTypeToDownloadImage); ++i) {
const MimeTypeToDownloadImage& entry = kMapMimeTypeToDownloadImage[i];
if (mime_type_string == entry.mime_type) {
download_image = entry.download_image;
break;
}
}
UMA_HISTOGRAM_ENUMERATION("Download.ContentImageType",
download_image,
DOWNLOAD_IMAGE_MAX);
}
} // namespace
void RecordDownloadMimeType(const std::string& mime_type_string) {
DownloadContent download_content = DOWNLOAD_CONTENT_UNRECOGNIZED;
// Look up exact matches.
for (size_t i = 0; i < arraysize(kMapMimeTypeToDownloadContent); ++i) {
const MimeTypeToDownloadContent& entry = kMapMimeTypeToDownloadContent[i];
if (mime_type_string == entry.mime_type) {
download_content = entry.download_content;
break;
}
}
// Do partial matches.
if (download_content == DOWNLOAD_CONTENT_UNRECOGNIZED) {
if (StartsWithASCII(mime_type_string, "text/", true)) {
download_content = DOWNLOAD_CONTENT_TEXT;
} else if (StartsWithASCII(mime_type_string, "image/", true)) {
download_content = DOWNLOAD_CONTENT_IMAGE;
RecordDownloadImageType(mime_type_string);
} else if (StartsWithASCII(mime_type_string, "audio/", true)) {
download_content = DOWNLOAD_CONTENT_AUDIO;
} else if (StartsWithASCII(mime_type_string, "video/", true)) {
download_content = DOWNLOAD_CONTENT_VIDEO;
}
}
// Record the value.
UMA_HISTOGRAM_ENUMERATION("Download.ContentType",
download_content,
DOWNLOAD_CONTENT_MAX);
}
void RecordDownloadContentDisposition(
const std::string& content_disposition_string) {
if (content_disposition_string.empty())
return;
net::HttpContentDisposition content_disposition(
content_disposition_string, "");
int result = content_disposition.parse_result_flags();
bool is_valid = !content_disposition.filename().empty();
RecordContentDispositionCount(CONTENT_DISPOSITION_HEADER_PRESENT, true);
RecordContentDispositionCount(CONTENT_DISPOSITION_IS_VALID, is_valid);
if (!is_valid)
return;
RecordContentDispositionCountFlag(
CONTENT_DISPOSITION_HAS_DISPOSITION_TYPE, result,
net::HttpContentDisposition::HAS_DISPOSITION_TYPE);
RecordContentDispositionCountFlag(
CONTENT_DISPOSITION_HAS_UNKNOWN_TYPE, result,
net::HttpContentDisposition::HAS_UNKNOWN_DISPOSITION_TYPE);
RecordContentDispositionCountFlag(
CONTENT_DISPOSITION_HAS_NAME, result,
net::HttpContentDisposition::HAS_NAME);
RecordContentDispositionCountFlag(
CONTENT_DISPOSITION_HAS_FILENAME, result,
net::HttpContentDisposition::HAS_FILENAME);
RecordContentDispositionCountFlag(
CONTENT_DISPOSITION_HAS_EXT_FILENAME, result,
net::HttpContentDisposition::HAS_EXT_FILENAME);
RecordContentDispositionCountFlag(
CONTENT_DISPOSITION_HAS_NON_ASCII_STRINGS, result,
net::HttpContentDisposition::HAS_NON_ASCII_STRINGS);
RecordContentDispositionCountFlag(
CONTENT_DISPOSITION_HAS_PERCENT_ENCODED_STRINGS, result,
net::HttpContentDisposition::HAS_PERCENT_ENCODED_STRINGS);
RecordContentDispositionCountFlag(
CONTENT_DISPOSITION_HAS_RFC2047_ENCODED_STRINGS, result,
net::HttpContentDisposition::HAS_RFC2047_ENCODED_STRINGS);
RecordContentDispositionCount(
CONTENT_DISPOSITION_HAS_NAME_ONLY,
(result & (net::HttpContentDisposition::HAS_NAME |
net::HttpContentDisposition::HAS_FILENAME |
net::HttpContentDisposition::HAS_EXT_FILENAME)) ==
net::HttpContentDisposition::HAS_NAME);
}
void RecordFileThreadReceiveBuffers(size_t num_buffers) {
UMA_HISTOGRAM_CUSTOM_COUNTS(
"Download.FileThreadReceiveBuffers", num_buffers, 1,
100, 100);
}
void RecordBandwidth(double actual_bandwidth, double potential_bandwidth) {
UMA_HISTOGRAM_CUSTOM_COUNTS(
"Download.ActualBandwidth", actual_bandwidth, 1, 1000000000, 50);
UMA_HISTOGRAM_CUSTOM_COUNTS(
"Download.PotentialBandwidth", potential_bandwidth, 1, 1000000000, 50);
UMA_HISTOGRAM_PERCENTAGE(
"Download.BandwidthUsed",
(int) ((actual_bandwidth * 100)/ potential_bandwidth));
}
void RecordOpen(const base::Time& end, bool first) {
if (!end.is_null()) {
UMA_HISTOGRAM_LONG_TIMES("Download.OpenTime", (base::Time::Now() - end));
if (first) {
UMA_HISTOGRAM_LONG_TIMES("Download.FirstOpenTime",
(base::Time::Now() - end));
}
}
}
void RecordClearAllSize(int size) {
UMA_HISTOGRAM_CUSTOM_COUNTS("Download.ClearAllSize",
size,
0/*min*/,
(1 << 10)/*max*/,
32/*num_buckets*/);
}
void RecordOpensOutstanding(int size) {
UMA_HISTOGRAM_CUSTOM_COUNTS("Download.OpensOutstanding",
size,
0/*min*/,
(1 << 10)/*max*/,
64/*num_buckets*/);
}
void RecordContiguousWriteTime(base::TimeDelta time_blocked) {
UMA_HISTOGRAM_TIMES("Download.FileThreadBlockedTime", time_blocked);
}
// Record what percentage of the time we have the network flow controlled.
void RecordNetworkBlockage(base::TimeDelta resource_handler_lifetime,
base::TimeDelta resource_handler_blocked_time) {
int percentage = 0;
// Avoid division by zero errors.
if (resource_handler_blocked_time != base::TimeDelta()) {
percentage =
resource_handler_blocked_time * 100 / resource_handler_lifetime;
}
UMA_HISTOGRAM_COUNTS_100("Download.ResourceHandlerBlockedPercentage",
percentage);
}
void RecordFileBandwidth(size_t length,
base::TimeDelta disk_write_time,
base::TimeDelta elapsed_time) {
size_t elapsed_time_ms = elapsed_time.InMilliseconds();
if (0u == elapsed_time_ms)
elapsed_time_ms = 1;
size_t disk_write_time_ms = disk_write_time.InMilliseconds();
if (0u == disk_write_time_ms)
disk_write_time_ms = 1;
UMA_HISTOGRAM_CUSTOM_COUNTS(
"Download.BandwidthOverallBytesPerSecond",
(1000 * length / elapsed_time_ms), 1, 50000000, 50);
UMA_HISTOGRAM_CUSTOM_COUNTS(
"Download.BandwidthDiskBytesPerSecond",
(1000 * length / disk_write_time_ms), 1, 50000000, 50);
UMA_HISTOGRAM_COUNTS_100("Download.DiskBandwidthUsedPercentage",
disk_write_time_ms * 100 / elapsed_time_ms);
}
void RecordSavePackageEvent(SavePackageEvent event) {
UMA_HISTOGRAM_ENUMERATION("Download.SavePackage",
event,
SAVE_PACKAGE_LAST_ENTRY);
}
} // namespace content
|