| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Download utilities. | 5 // Download utilities. |
| 6 | 6 |
| 7 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ | 7 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ |
| 8 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ | 8 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ |
| 9 #pragma once | 9 #pragma once |
| 10 | 10 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 int GetBigProgressIconOffset(); | 105 int GetBigProgressIconOffset(); |
| 106 | 106 |
| 107 const int kSmallProgressIconOffset = | 107 const int kSmallProgressIconOffset = |
| 108 (kSmallProgressIconSize - kSmallIconSize) / 2; | 108 (kSmallProgressIconSize - kSmallIconSize) / 2; |
| 109 | 109 |
| 110 enum PaintDownloadProgressSize { | 110 enum PaintDownloadProgressSize { |
| 111 SMALL = 0, | 111 SMALL = 0, |
| 112 BIG | 112 BIG |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 // We keep a count of how often various events occur in the | |
| 116 // histogram "Download.Counts". | |
| 117 enum DownloadCountTypes { | |
| 118 // The download was initiated by navigating to a URL (e.g. by user | |
| 119 // click). | |
| 120 INITIATED_BY_NAVIGATION_COUNT = 0, | |
| 121 | |
| 122 // The download was initiated by invoking a context menu within a page. | |
| 123 INITIATED_BY_CONTEXT_MENU_COUNT, | |
| 124 | |
| 125 // The download was initiated when the SavePackage system rejected | |
| 126 // a Save Page As ... by returning false from | |
| 127 // SavePackage::IsSaveableContents(). | |
| 128 INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT, | |
| 129 | |
| 130 // The download was initiated by a drag and drop from a drag-and-drop | |
| 131 // enabled web application. | |
| 132 INITIATED_BY_DRAG_N_DROP_COUNT, | |
| 133 | |
| 134 // The download was initiated by explicit RPC from the renderer process | |
| 135 // (e.g. by Alt-click). | |
| 136 INITIATED_BY_RENDERER_COUNT, | |
| 137 | |
| 138 // Downloads that made it to DownloadResourceHandler -- all of the | |
| 139 // above minus those blocked by DownloadThrottlingResourceHandler. | |
| 140 UNTHROTTLED_COUNT, | |
| 141 | |
| 142 // Downloads that actually complete. | |
| 143 COMPLETED_COUNT, | |
| 144 | |
| 145 // Downloads that are cancelled before completion (user action or error). | |
| 146 CANCELLED_COUNT, | |
| 147 | |
| 148 // Downloads that are started. Should be equal to UNTHROTTLED_COUNT. | |
| 149 START_COUNT, | |
| 150 | |
| 151 // Downloads that were interrupted by the OS. | |
| 152 INTERRUPTED_COUNT, | |
| 153 | |
| 154 DOWNLOAD_COUNT_TYPES_LAST_ENTRY | |
| 155 }; | |
| 156 | |
| 157 // Increment one of the above counts. | |
| 158 void RecordDownloadCount(DownloadCountTypes type); | |
| 159 | |
| 160 // Record COMPLETED_COUNT and how long the download took. | |
| 161 void RecordDownloadCompleted(const base::TimeTicks& start); | |
| 162 | |
| 163 // Record INTERRUPTED_COUNT, |error|, |received| and |total| bytes. | |
| 164 void RecordDownloadInterrupted(int error, int64 received, int64 total); | |
| 165 | |
| 166 // Records the mime type of the download. | |
| 167 void RecordDownloadMimeType(const std::string& mime_type); | |
| 168 | |
| 169 // Paint the common download animation progress foreground and background, | 115 // Paint the common download animation progress foreground and background, |
| 170 // clipping the foreground to 'percent' full. If percent is -1, then we don't | 116 // clipping the foreground to 'percent' full. If percent is -1, then we don't |
| 171 // know the total size, so we just draw a rotating segment until we're done. | 117 // know the total size, so we just draw a rotating segment until we're done. |
| 172 // | 118 // |
| 173 // |containing_view| is the View subclass within which the progress animation | 119 // |containing_view| is the View subclass within which the progress animation |
| 174 // is drawn (generally either DownloadItemTabView or DownloadItemView). We | 120 // is drawn (generally either DownloadItemTabView or DownloadItemView). We |
| 175 // require the containing View in addition to the canvas because if we are | 121 // require the containing View in addition to the canvas because if we are |
| 176 // drawing in a right-to-left locale, we need to mirror the position of the | 122 // drawing in a right-to-left locale, we need to mirror the position of the |
| 177 // progress animation within the containing View. | 123 // progress animation within the containing View. |
| 178 void PaintDownloadProgress(gfx::Canvas* canvas, | 124 void PaintDownloadProgress(gfx::Canvas* canvas, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 // Download the URL. Must be called on the IO thread. | 188 // Download the URL. Must be called on the IO thread. |
| 243 void DownloadUrl(const GURL& url, | 189 void DownloadUrl(const GURL& url, |
| 244 const GURL& referrer, | 190 const GURL& referrer, |
| 245 const std::string& referrer_charset, | 191 const std::string& referrer_charset, |
| 246 const DownloadSaveInfo& save_info, | 192 const DownloadSaveInfo& save_info, |
| 247 ResourceDispatcherHost* rdh, | 193 ResourceDispatcherHost* rdh, |
| 248 int render_process_host_id, | 194 int render_process_host_id, |
| 249 int render_view_id, | 195 int render_view_id, |
| 250 const content::ResourceContext* context); | 196 const content::ResourceContext* context); |
| 251 | 197 |
| 252 // Sends a notification on downloads being initiated | |
| 253 // Must be called on the UI thread. | |
| 254 void NotifyDownloadInitiated(int render_process_id, int render_view_id); | |
| 255 | |
| 256 // Same as GetUniquePathNumber, except that it also checks the existence | 198 // Same as GetUniquePathNumber, except that it also checks the existence |
| 257 // of its .crdownload intermediate path. | 199 // of its .crdownload intermediate path. |
| 258 // If |path| does not exist, 0 is returned. If it fails to find such | 200 // If |path| does not exist, 0 is returned. If it fails to find such |
| 259 // a number, -1 is returned. | 201 // a number, -1 is returned. |
| 260 int GetUniquePathNumberWithCrDownload(const FilePath& path); | 202 int GetUniquePathNumberWithCrDownload(const FilePath& path); |
| 261 | 203 |
| 262 // Returns a .crdownload intermediate path for the |suggested_path|. | 204 // Returns a .crdownload intermediate path for the |suggested_path|. |
| 263 FilePath GetCrDownloadPath(const FilePath& suggested_path); | 205 FilePath GetCrDownloadPath(const FilePath& suggested_path); |
| 264 | 206 |
| 265 } // namespace download_util | 207 } // namespace download_util |
| 266 | 208 |
| 267 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ | 209 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ |
| OLD | NEW |