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

Side by Side Diff: content/browser/download/download_stats.cc

Issue 7664019: Move download UMA functions to their own file in content. Also fire the chrome-only notification ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "content/browser/download/download_stats.h"
6
7 #include "base/metrics/histogram.h"
8 #include "base/string_util.h"
9
10 namespace download_stats {
11
12 // All possible error codes from the network module. Note that the error codes
13 // are all positive (since histograms expect positive sample values).
14 const int kAllNetErrorCodes[] = {
15 #define NET_ERROR(label, value) -(value),
16 #include "net/base/net_error_list.h"
17 #undef NET_ERROR
18 };
19
20 void RecordDownloadCount(DownloadCountTypes type) {
21 UMA_HISTOGRAM_ENUMERATION(
22 "Download.Counts", type, DOWNLOAD_COUNT_TYPES_LAST_ENTRY);
23 }
24
25 void RecordDownloadCompleted(const base::TimeTicks& start) {
26 RecordDownloadCount(COMPLETED_COUNT);
27 UMA_HISTOGRAM_LONG_TIMES("Download.Time", (base::TimeTicks::Now() - start));
28 }
29
30 void RecordDownloadInterrupted(int error, int64 received, int64 total) {
31 RecordDownloadCount(INTERRUPTED_COUNT);
32 UMA_HISTOGRAM_CUSTOM_ENUMERATION(
33 "Download.InterruptedError",
34 -error,
35 base::CustomHistogram::ArrayToCustomRanges(
36 kAllNetErrorCodes, arraysize(kAllNetErrorCodes)));
37
38 // The maximum should be 2^kBuckets, to have the logarithmic bucket
39 // boundaries fall on powers of 2.
40 static const int kBuckets = 30;
41 static const int64 kMaxKb = 1 << kBuckets; // One Terabyte, in Kilobytes.
42 int64 delta_bytes = total - received;
43 bool unknown_size = total <= 0;
44 int64 received_kb = received / 1024;
45 int64 total_kb = total / 1024;
46 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.InterruptedReceivedSizeK",
47 received_kb,
48 1,
49 kMaxKb,
50 kBuckets);
51 if (!unknown_size) {
52 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.InterruptedTotalSizeK",
53 total_kb,
54 1,
55 kMaxKb,
56 kBuckets);
57 if (delta_bytes >= 0) {
58 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.InterruptedOverrunBytes",
59 delta_bytes,
60 1,
61 kMaxKb,
62 kBuckets);
63 } else {
64 UMA_HISTOGRAM_CUSTOM_COUNTS("Download.InterruptedUnderrunBytes",
65 -delta_bytes,
66 1,
67 kMaxKb,
68 kBuckets);
69 }
70 }
71
72 UMA_HISTOGRAM_BOOLEAN("Download.InterruptedUnknownSize", unknown_size);
73 }
74
75 namespace {
76
77 enum DownloadContent {
78 DOWNLOAD_CONTENT_UNRECOGNIZED = 0,
79 DOWNLOAD_CONTENT_TEXT = 1,
80 DOWNLOAD_CONTENT_IMAGE = 2,
81 DOWNLOAD_CONTENT_AUDIO = 3,
82 DOWNLOAD_CONTENT_VIDEO = 4,
83 DOWNLOAD_CONTENT_OCTET_STREAM = 5,
84 DOWNLOAD_CONTENT_PDF = 6,
85 DOWNLOAD_CONTENT_DOC = 7,
86 DOWNLOAD_CONTENT_XLS = 8,
87 DOWNLOAD_CONTENT_PPT = 9,
88 DOWNLOAD_CONTENT_ARCHIVE = 10,
89 DOWNLOAD_CONTENT_EXE = 11,
90 DOWNLOAD_CONTENT_DMG = 12,
91 DOWNLOAD_CONTENT_CRX = 13,
92 DOWNLOAD_CONTENT_MAX = 14,
93 };
94
95 struct MimeTypeToDownloadContent {
96 const char* mime_type;
97 DownloadContent download_content;
98 };
99
100 static MimeTypeToDownloadContent kMapMimeTypeToDownloadContent[] = {
101 {"application/octet-stream", DOWNLOAD_CONTENT_OCTET_STREAM},
102 {"binary/octet-stream", DOWNLOAD_CONTENT_OCTET_STREAM},
103 {"application/pdf", DOWNLOAD_CONTENT_PDF},
104 {"application/msword", DOWNLOAD_CONTENT_DOC},
105 {"application/vnd.ms-excel", DOWNLOAD_CONTENT_XLS},
106 {"application/vns.ms-powerpoint", DOWNLOAD_CONTENT_PPT},
107 {"application/zip", DOWNLOAD_CONTENT_ARCHIVE},
108 {"application/x-gzip", DOWNLOAD_CONTENT_ARCHIVE},
109 {"application/x-rar-compressed", DOWNLOAD_CONTENT_ARCHIVE},
110 {"application/x-tar", DOWNLOAD_CONTENT_ARCHIVE},
111 {"application/x-bzip", DOWNLOAD_CONTENT_ARCHIVE},
112 {"application/x-exe", DOWNLOAD_CONTENT_EXE},
113 {"application/x-apple-diskimage", DOWNLOAD_CONTENT_DMG},
114 {"application/x-chrome-extension", DOWNLOAD_CONTENT_CRX},
115 };
116
117 } // namespace
118
119 void RecordDownloadMimeType(const std::string& mime_type_string) {
120 DownloadContent download_content = DOWNLOAD_CONTENT_UNRECOGNIZED;
121
122 // Look up exact matches.
123 for (size_t i = 0; i < arraysize(kMapMimeTypeToDownloadContent); ++i) {
124 const MimeTypeToDownloadContent& entry =
125 kMapMimeTypeToDownloadContent[i];
126 if (mime_type_string == entry.mime_type) {
127 download_content = entry.download_content;
128 break;
129 }
130 }
131
132 // Do partial matches.
133 if (download_content == DOWNLOAD_CONTENT_UNRECOGNIZED) {
134 if (StartsWithASCII(mime_type_string, "text/", true)) {
135 download_content = DOWNLOAD_CONTENT_TEXT;
136 } else if (StartsWithASCII(mime_type_string, "image/", true)) {
137 download_content = DOWNLOAD_CONTENT_IMAGE;
138 } else if (StartsWithASCII(mime_type_string, "audio/", true)) {
139 download_content = DOWNLOAD_CONTENT_AUDIO;
140 } else if (StartsWithASCII(mime_type_string, "video/", true)) {
141 download_content = DOWNLOAD_CONTENT_VIDEO;
142 }
143 }
144
145 // Record the value.
146 UMA_HISTOGRAM_ENUMERATION("Download.ContentType",
147 download_content,
148 DOWNLOAD_CONTENT_MAX);
149 }
150
151 } // namespace download_stats
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698