| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // Objects that handle file operations for downloads, on the download thread. | 5 // Objects that handle file operations for downloads, on the download thread. |
| 6 // | 6 // |
| 7 // The DownloadFileManager owns a set of DownloadFile objects, each of which | 7 // The DownloadFileManager owns a set of DownloadFile objects, each of which |
| 8 // represent one in progress download and performs the disk IO for that | 8 // represent one in progress download and performs the disk IO for that |
| 9 // download. The DownloadFileManager itself is a singleton object owned by the | 9 // download. The DownloadFileManager itself is a singleton object owned by the |
| 10 // ResourceDispatcherHost. | 10 // ResourceDispatcherHost. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 // ID (unique integer created in the IO thread) to the DownloadManager for the | 35 // ID (unique integer created in the IO thread) to the DownloadManager for the |
| 36 // tab (profile) where the download was initiated. In the event of a tab closure | 36 // tab (profile) where the download was initiated. In the event of a tab closure |
| 37 // during a download, the DownloadFileManager will continue to route data to the | 37 // during a download, the DownloadFileManager will continue to route data to the |
| 38 // appropriate DownloadManager. In progress downloads are cancelled for a | 38 // appropriate DownloadManager. In progress downloads are cancelled for a |
| 39 // DownloadManager that exits (such as when closing a profile). | 39 // DownloadManager that exits (such as when closing a profile). |
| 40 | 40 |
| 41 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ | 41 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ |
| 42 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ | 42 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ |
| 43 | 43 |
| 44 #include <map> | 44 #include <map> |
| 45 #include <string> |
| 45 #include <vector> | 46 #include <vector> |
| 46 | 47 |
| 47 #include "app/gfx/native_widget_types.h" | 48 #include "app/gfx/native_widget_types.h" |
| 48 #include "base/basictypes.h" | 49 #include "base/basictypes.h" |
| 49 #include "base/file_path.h" | 50 #include "base/file_path.h" |
| 50 #include "base/hash_tables.h" | 51 #include "base/hash_tables.h" |
| 51 #include "base/lock.h" | 52 #include "base/lock.h" |
| 52 #include "base/ref_counted.h" | 53 #include "base/ref_counted.h" |
| 53 #include "base/timer.h" | 54 #include "base/timer.h" |
| 54 #include "googleurl/src/gurl.h" | 55 #include "googleurl/src/gurl.h" |
| 55 | 56 |
| 56 namespace net { | 57 namespace net { |
| 57 class IOBuffer; | 58 class IOBuffer; |
| 58 } | 59 } |
| 59 struct DownloadCreateInfo; | 60 struct DownloadCreateInfo; |
| 60 class DownloadManager; | 61 class DownloadManager; |
| 61 class MessageLoop; | 62 class MessageLoop; |
| 62 class ResourceDispatcherHost; | 63 class ResourceDispatcherHost; |
| 63 class URLRequestContext; | 64 class URLRequestContextGetter; |
| 64 | 65 |
| 65 // DownloadBuffer -------------------------------------------------------------- | 66 // DownloadBuffer -------------------------------------------------------------- |
| 66 | 67 |
| 67 // This container is created and populated on the io_thread, and passed to the | 68 // This container is created and populated on the io_thread, and passed to the |
| 68 // file_thread for writing. In order to avoid flooding the file_thread with too | 69 // file_thread for writing. In order to avoid flooding the file_thread with too |
| 69 // many small write messages, each write is appended to the DownloadBuffer while | 70 // many small write messages, each write is appended to the DownloadBuffer while |
| 70 // waiting for the task to run on the file_thread. Access to the write buffers | 71 // waiting for the task to run on the file_thread. Access to the write buffers |
| 71 // is synchronized via the lock. Each entry in 'contents' represents one data | 72 // is synchronized via the lock. Each entry in 'contents' represents one data |
| 72 // buffer and its size in bytes. | 73 // buffer and its size in bytes. |
| 73 | 74 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 183 |
| 183 // Handlers for notifications sent from the download thread and run on | 184 // Handlers for notifications sent from the download thread and run on |
| 184 // the UI thread. | 185 // the UI thread. |
| 185 void OnStartDownload(DownloadCreateInfo* info); | 186 void OnStartDownload(DownloadCreateInfo* info); |
| 186 void OnDownloadFinished(int id, int64 bytes_so_far); | 187 void OnDownloadFinished(int id, int64 bytes_so_far); |
| 187 | 188 |
| 188 // Download the URL. Called on the UI thread and forwarded to the | 189 // Download the URL. Called on the UI thread and forwarded to the |
| 189 // ResourceDispatcherHost on the IO thread. | 190 // ResourceDispatcherHost on the IO thread. |
| 190 void DownloadUrl(const GURL& url, | 191 void DownloadUrl(const GURL& url, |
| 191 const GURL& referrer, | 192 const GURL& referrer, |
| 193 const std::string& referrer_charset, |
| 192 int render_process_host_id, | 194 int render_process_host_id, |
| 193 int render_view_id, | 195 int render_view_id, |
| 194 URLRequestContext* request_context); | 196 URLRequestContextGetter* request_context_getter); |
| 195 | 197 |
| 196 // Run on the IO thread to initiate the download of a URL. | 198 // Run on the IO thread to initiate the download of a URL. |
| 197 void OnDownloadUrl(const GURL& url, | 199 void OnDownloadUrl(const GURL& url, |
| 198 const GURL& referrer, | 200 const GURL& referrer, |
| 201 const std::string& referrer_charset, |
| 199 int render_process_host_id, | 202 int render_process_host_id, |
| 200 int render_view_id, | 203 int render_view_id, |
| 201 URLRequestContext* request_context); | 204 URLRequestContextGetter* request_context_getter); |
| 202 | 205 |
| 203 // Called on the UI thread to remove a download item or manager. | 206 // Called on the UI thread to remove a download item or manager. |
| 204 void RemoveDownloadManager(DownloadManager* manager); | 207 void RemoveDownloadManager(DownloadManager* manager); |
| 205 void RemoveDownload(int id, DownloadManager* manager); | 208 void RemoveDownload(int id, DownloadManager* manager); |
| 206 | 209 |
| 207 #if !defined(OS_MACOSX) | 210 #if !defined(OS_MACOSX) |
| 208 // The open and show methods run on the file thread, which does not work on | 211 // The open and show methods run on the file thread, which does not work on |
| 209 // Mac OS X (which uses the UI thread for opens). | 212 // Mac OS X (which uses the UI thread for opens). |
| 210 | 213 |
| 211 // Handler for shell operations sent from the UI to the download thread. | 214 // Handler for shell operations sent from the UI to the download thread. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 // Used for progress updates on the UI thread, mapping download->id() to bytes | 287 // Used for progress updates on the UI thread, mapping download->id() to bytes |
| 285 // received so far. Written to by the file thread and read by the UI thread. | 288 // received so far. Written to by the file thread and read by the UI thread. |
| 286 typedef base::hash_map<int, int64> ProgressMap; | 289 typedef base::hash_map<int, int64> ProgressMap; |
| 287 ProgressMap ui_progress_; | 290 ProgressMap ui_progress_; |
| 288 Lock progress_lock_; | 291 Lock progress_lock_; |
| 289 | 292 |
| 290 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager); | 293 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager); |
| 291 }; | 294 }; |
| 292 | 295 |
| 293 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ | 296 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ |
| OLD | NEW |