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 // Holds helpers for gathering UMA stats about downloads. 6 7 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_STATS_H_ 8 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_STATS_H_ 9 10 #include <string> 11 12 #include "base/basictypes.h" 13 #include "content/common/content_export.h" 14 #include "content/public/browser/download_danger_type.h" 15 #include "content/public/browser/download_interrupt_reasons.h" 16 17 namespace base { 18 class FilePath; 19 class Time; 20 class TimeDelta; 21 class TimeTicks; 22 } 23 24 namespace content { 25 26 // We keep a count of how often various events occur in the 27 // histogram "Download.Counts". 28 enum DownloadCountTypes { 29 // Stale enum values left around so that values passed to UMA don't 30 // change. 31 DOWNLOAD_COUNT_UNUSED_0 = 0, 32 DOWNLOAD_COUNT_UNUSED_1, 33 DOWNLOAD_COUNT_UNUSED_2, 34 DOWNLOAD_COUNT_UNUSED_3, 35 DOWNLOAD_COUNT_UNUSED_4, 36 37 // Downloads that made it to DownloadResourceHandler 38 UNTHROTTLED_COUNT, 39 40 // Downloads that actually complete. 41 COMPLETED_COUNT, 42 43 // Downloads that are cancelled before completion (user action or error). 44 CANCELLED_COUNT, 45 46 // Downloads that are started. Should be equal to UNTHROTTLED_COUNT. 47 START_COUNT, 48 49 // Downloads that were interrupted by the OS. 50 INTERRUPTED_COUNT, 51 52 // (Deprecated) Write sizes for downloads. 53 // This is equal to the number of samples in Download.WriteSize histogram. 54 DOWNLOAD_COUNT_UNUSED_10, 55 56 // (Deprecated) Counts iterations of the BaseFile::AppendDataToFile() loop. 57 // This is equal to the number of samples in Download.WriteLoopCount 58 // histogram. 59 DOWNLOAD_COUNT_UNUSED_11, 60 61 // Counts interruptions that happened at the end of the download. 62 INTERRUPTED_AT_END_COUNT, 63 64 // Counts errors due to writes to BaseFiles that have been detached already. 65 // This can happen when saving web pages as complete packages. It happens 66 // when we get messages to append data to files that have already finished and 67 // been detached, but haven't yet been removed from the list of files in 68 // progress. 69 APPEND_TO_DETACHED_FILE_COUNT, 70 71 // Counts the number of instances where the downloaded file is missing after a 72 // successful invocation of ScanAndSaveDownloadedFile(). 73 FILE_MISSING_AFTER_SUCCESSFUL_SCAN_COUNT, 74 75 // (Deprecated) Count of downloads with a strong ETag and specified 76 // 'Accept-Ranges: bytes'. 77 DOWNLOAD_COUNT_UNUSED_15, 78 79 // Count of downloads that didn't have a valid WebContents at the time it was 80 // interrupted. 81 INTERRUPTED_WITHOUT_WEBCONTENTS, 82 83 // Count of downloads that supplies a strong validator (implying byte-wise 84 // equivalence) and has a 'Accept-Ranges: bytes' header. These downloads are 85 // candidates for partial resumption. 86 STRONG_VALIDATOR_AND_ACCEPTS_RANGES, 87 88 DOWNLOAD_COUNT_TYPES_LAST_ENTRY 89 }; 90 91 enum DownloadSource { 92 // The download was initiated when the SavePackage system rejected 93 // a Save Page As ... by returning false from 94 // SavePackage::IsSaveableContents(). 95 INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML = 0, 96 97 // The download was initiated by a drag and drop from a drag-and-drop 98 // enabled web application. 99 INITIATED_BY_DRAG_N_DROP, 100 101 // The download was initiated by explicit RPC from the renderer process 102 // (e.g. by Alt-click) through the IPC ViewHostMsg_DownloadUrl. 103 INITIATED_BY_RENDERER, 104 105 // Fomerly INITIATED_BY_PEPPER_SAVE. 106 DOWNLOAD_SOURCE_UNUSED_3, 107 108 // A request that was initiated as a result of resuming an interrupted 109 // download. 110 INITIATED_BY_RESUMPTION, 111 112 DOWNLOAD_SOURCE_LAST_ENTRY 113 }; 114 115 enum DownloadDiscardReason { 116 // The download is being discarded due to a user action. 117 DOWNLOAD_DISCARD_DUE_TO_USER_ACTION, 118 119 // The download is being discarded due to the browser being shut down. 120 DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN 121 }; 122 123 // Increment one of the above counts. 124 void RecordDownloadCount(DownloadCountTypes type); 125 126 // Record initiation of a download from a specific source. 127 void RecordDownloadSource(DownloadSource source); 128 129 // Record COMPLETED_COUNT and how long the download took. 130 void RecordDownloadCompleted(const base::TimeTicks& start, int64 download_len); 131 132 // Record INTERRUPTED_COUNT, |reason|, |received| and |total| bytes. 133 void RecordDownloadInterrupted(DownloadInterruptReason reason, 134 int64 received, 135 int64 total); 136 137 // Record that a download has been classified as malicious. 138 void RecordMaliciousDownloadClassified(DownloadDangerType danger_type); 139 140 // Record a dangerous download accept event. 141 void RecordDangerousDownloadAccept( 142 DownloadDangerType danger_type, 143 const base::FilePath& file_path); 144 145 // Record a dangerous download discard event. 146 void RecordDangerousDownloadDiscard( 147 DownloadDiscardReason reason, 148 DownloadDangerType danger_type, 149 const base::FilePath& file_path); 150 151 // Records the mime type of the download. 152 void RecordDownloadMimeType(const std::string& mime_type); 153 154 // Records usage of Content-Disposition header. 155 void RecordDownloadContentDisposition(const std::string& content_disposition); 156 157 // Record WRITE_SIZE_COUNT and data_len. 158 void RecordDownloadWriteSize(size_t data_len); 159 160 // Record WRITE_LOOP_COUNT and number of loops. 161 void RecordDownloadWriteLoopCount(int count); 162 163 // Record the number of buffers piled up by the IO thread 164 // before the file thread gets to draining them. 165 void RecordFileThreadReceiveBuffers(size_t num_buffers); 166 167 // Record the bandwidth seen in DownloadResourceHandler 168 // |actual_bandwidth| and |potential_bandwidth| are in bytes/second. 169 void RecordBandwidth(double actual_bandwidth, double potential_bandwidth); 170 171 // Record the time of both the first open and all subsequent opens since the 172 // download completed. 173 void RecordOpen(const base::Time& end, bool first); 174 175 // Record whether or not the server accepts ranges, and the download size. Also 176 // counts if a strong validator is supplied. The combination of range request 177 // support and ETag indicates downloads that are candidates for partial 178 // resumption. 179 void RecordAcceptsRanges(const std::string& accepts_ranges, 180 int64 download_len, 181 bool has_strong_validator); 182 183 // Record the number of downloads removed by ClearAll. 184 void RecordClearAllSize(int size); 185 186 // Record the number of completed unopened downloads when a download is opened. 187 void RecordOpensOutstanding(int size); 188 189 // Record how long we block the file thread at a time. 190 void RecordContiguousWriteTime(base::TimeDelta time_blocked); 191 192 // Record the percentage of time we had to block the network (i.e. 193 // how often, for each download, something other than the network 194 // was the bottleneck). 195 void RecordNetworkBlockage(base::TimeDelta resource_handler_lifetime, 196 base::TimeDelta resource_handler_blocked_time); 197 198 // Record overall bandwidth stats at the file end. 199 void RecordFileBandwidth(size_t length, 200 base::TimeDelta disk_write_time, 201 base::TimeDelta elapsed_time); 202 203 // Record the result of a download file rename. 204 void RecordDownloadFileRenameResultAfterRetry( 205 base::TimeDelta time_since_first_failure, 206 DownloadInterruptReason interrupt_reason); 207 208 enum SavePackageEvent { 209 // The user has started to save a page as a package. 210 SAVE_PACKAGE_STARTED, 211 212 // The save package operation was cancelled. 213 SAVE_PACKAGE_CANCELLED, 214 215 // The save package operation finished without being cancelled. 216 SAVE_PACKAGE_FINISHED, 217 218 // The save package tried to write to an already completed file. 219 SAVE_PACKAGE_WRITE_TO_COMPLETED, 220 221 // The save package tried to write to an already failed file. 222 SAVE_PACKAGE_WRITE_TO_FAILED, 223 224 SAVE_PACKAGE_LAST_ENTRY 225 }; 226 227 void RecordSavePackageEvent(SavePackageEvent event); 228 229 enum OriginStateOnResumption { 230 ORIGIN_STATE_ON_RESUMPTION_ADDITIONAL_REDIRECTS = 1<<0, 231 ORIGIN_STATE_ON_RESUMPTION_VALIDATORS_CHANGED = 1<<1, 232 ORIGIN_STATE_ON_RESUMPTION_CONTENT_DISPOSITION_CHANGED = 1<<2, 233 ORIGIN_STATE_ON_RESUMPTION_MAX = 1<<3 234 }; 235 236 // Record the state of the origin information across a download resumption 237 // request. |state| is a combination of values from OriginStateOnResumption 238 // enum. 239 void RecordOriginStateOnResumption(bool is_partial, 240 int state); 241 242 } // namespace content 243 244 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_STATS_H_ 245