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