| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 #include "base/basictypes.h" | 47 #include "base/basictypes.h" |
| 48 #include "base/hash_tables.h" | 48 #include "base/hash_tables.h" |
| 49 #include "base/lock.h" | 49 #include "base/lock.h" |
| 50 #include "base/ref_counted.h" | 50 #include "base/ref_counted.h" |
| 51 #include "base/thread.h" | 51 #include "base/thread.h" |
| 52 #include "base/timer.h" | 52 #include "base/timer.h" |
| 53 #include "chrome/browser/history/download_types.h" | 53 #include "chrome/browser/history/download_types.h" |
| 54 | 54 |
| 55 class DownloadManager; | 55 class DownloadManager; |
| 56 class FilePath; |
| 56 class GURL; | 57 class GURL; |
| 57 class MessageLoop; | 58 class MessageLoop; |
| 58 class ResourceDispatcherHost; | 59 class ResourceDispatcherHost; |
| 59 class URLRequestContext; | 60 class URLRequestContext; |
| 60 | 61 |
| 61 // DownloadBuffer -------------------------------------------------------------- | 62 // DownloadBuffer -------------------------------------------------------------- |
| 62 | 63 |
| 63 // This container is created and populated on the io_thread, and passed to the | 64 // This container is created and populated on the io_thread, and passed to the |
| 64 // file_thread for writing. In order to avoid flooding the file_thread with too | 65 // file_thread for writing. In order to avoid flooding the file_thread with too |
| 65 // many small write messages, each write is appended to the DownloadBuffer while | 66 // many small write messages, each write is appended to the DownloadBuffer while |
| (...skipping 20 matching lines...) Expand all Loading... |
| 86 | 87 |
| 87 bool Initialize(); | 88 bool Initialize(); |
| 88 | 89 |
| 89 // Write a new chunk of data to the file. Returns true on success. | 90 // Write a new chunk of data to the file. Returns true on success. |
| 90 bool AppendDataToFile(const char* data, int data_len); | 91 bool AppendDataToFile(const char* data, int data_len); |
| 91 | 92 |
| 92 // Abort the download and automatically close the file. | 93 // Abort the download and automatically close the file. |
| 93 void Cancel(); | 94 void Cancel(); |
| 94 | 95 |
| 95 // Rename the download file. Returns 'true' if the rename was successful. | 96 // Rename the download file. Returns 'true' if the rename was successful. |
| 96 bool Rename(const std::wstring& full_path); | 97 bool Rename(const FilePath& full_path); |
| 97 | 98 |
| 98 // Accessors. | 99 // Accessors. |
| 99 int64 bytes_so_far() const { return bytes_so_far_; } | 100 int64 bytes_so_far() const { return bytes_so_far_; } |
| 100 int id() const { return id_; } | 101 int id() const { return id_; } |
| 101 std::wstring full_path() const { return full_path_; } | 102 FilePath full_path() const { return full_path_; } |
| 102 int render_process_id() const { return render_process_id_; } | 103 int render_process_id() const { return render_process_id_; } |
| 103 int render_view_id() const { return render_view_id_; } | 104 int render_view_id() const { return render_view_id_; } |
| 104 int request_id() const { return request_id_; } | 105 int request_id() const { return request_id_; } |
| 105 bool path_renamed() const { return path_renamed_; } | 106 bool path_renamed() const { return path_renamed_; } |
| 106 bool in_progress() const { return file_ != NULL; } | 107 bool in_progress() const { return file_ != NULL; } |
| 107 void set_in_progress(bool in_progress) { in_progress_ = in_progress; } | 108 void set_in_progress(bool in_progress) { in_progress_ = in_progress; } |
| 108 | 109 |
| 109 private: | 110 private: |
| 110 // Open or Close the OS file handle. The file is opened in the constructor | 111 // Open or Close the OS file handle. The file is opened in the constructor |
| 111 // based on creation information passed to it, and automatically closed in | 112 // based on creation information passed to it, and automatically closed in |
| (...skipping 13 matching lines...) Expand all Loading... |
| 125 int render_view_id_; | 126 int render_view_id_; |
| 126 | 127 |
| 127 // Handle for informing the ResourceDispatcherHost of a UI based cancel. | 128 // Handle for informing the ResourceDispatcherHost of a UI based cancel. |
| 128 int request_id_; | 129 int request_id_; |
| 129 | 130 |
| 130 // Amount of data received up to this point. We may not know in advance how | 131 // Amount of data received up to this point. We may not know in advance how |
| 131 // much data to expect since some servers don't provide that information. | 132 // much data to expect since some servers don't provide that information. |
| 132 int64 bytes_so_far_; | 133 int64 bytes_so_far_; |
| 133 | 134 |
| 134 // Full path to the downloaded file. | 135 // Full path to the downloaded file. |
| 135 std::wstring full_path_; | 136 FilePath full_path_; |
| 136 | 137 |
| 137 // Whether the download is still using its initial temporary path. | 138 // Whether the download is still using its initial temporary path. |
| 138 bool path_renamed_; | 139 bool path_renamed_; |
| 139 | 140 |
| 140 // Whether the download is still receiving data. | 141 // Whether the download is still receiving data. |
| 141 bool in_progress_; | 142 bool in_progress_; |
| 142 | 143 |
| 143 DISALLOW_EVIL_CONSTRUCTORS(DownloadFile); | 144 DISALLOW_EVIL_CONSTRUCTORS(DownloadFile); |
| 144 }; | 145 }; |
| 145 | 146 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 const GURL& referrer, | 186 const GURL& referrer, |
| 186 int render_process_host_id, | 187 int render_process_host_id, |
| 187 int render_view_id, | 188 int render_view_id, |
| 188 URLRequestContext* request_context); | 189 URLRequestContext* request_context); |
| 189 | 190 |
| 190 // Called on the UI thread to remove a download item or manager. | 191 // Called on the UI thread to remove a download item or manager. |
| 191 void RemoveDownloadManager(DownloadManager* manager); | 192 void RemoveDownloadManager(DownloadManager* manager); |
| 192 void RemoveDownload(int id, DownloadManager* manager); | 193 void RemoveDownload(int id, DownloadManager* manager); |
| 193 | 194 |
| 194 // Handler for shell operations sent from the UI to the download thread. | 195 // Handler for shell operations sent from the UI to the download thread. |
| 195 void OnShowDownloadInShell(const std::wstring full_path); | 196 void OnShowDownloadInShell(const FilePath& full_path); |
| 196 // Handler to open or execute a downloaded file. | 197 // Handler to open or execute a downloaded file. |
| 197 void OnOpenDownloadInShell(const std::wstring full_path, | 198 void OnOpenDownloadInShell(const FilePath& full_path, |
| 198 const std::wstring& url, HWND parent_window); | 199 const std::wstring& url, HWND parent_window); |
| 199 | 200 |
| 200 // The download manager has provided a final name for a download. Sent from | 201 // The download manager has provided a final name for a download. Sent from |
| 201 // the UI thread and run on the download thread. | 202 // the UI thread and run on the download thread. |
| 202 void OnFinalDownloadName(int id, const std::wstring& full_path); | 203 void OnFinalDownloadName(int id, const FilePath& full_path); |
| 203 | 204 |
| 204 // Timer notifications. | 205 // Timer notifications. |
| 205 void UpdateInProgressDownloads(); | 206 void UpdateInProgressDownloads(); |
| 206 | 207 |
| 207 MessageLoop* file_loop() const { return file_loop_; } | 208 MessageLoop* file_loop() const { return file_loop_; } |
| 208 | 209 |
| 209 // Called by the download manager at initialization to ensure the default | 210 // Called by the download manager to delete non validated dangerous downloads. |
| 210 // download directory exists. | 211 static void DeleteFile(const FilePath& path); |
| 211 void CreateDirectory(const std::wstring& directory); | |
| 212 | |
| 213 // Called by the donwload manager to delete non validated dangerous downloads. | |
| 214 void DeleteFile(const std::wstring& path); | |
| 215 | 212 |
| 216 private: | 213 private: |
| 217 // Timer helpers for updating the UI about the current progress of a download. | 214 // Timer helpers for updating the UI about the current progress of a download. |
| 218 void StartUpdateTimer(); | 215 void StartUpdateTimer(); |
| 219 void StopUpdateTimer(); | 216 void StopUpdateTimer(); |
| 220 | 217 |
| 221 // Clean up helper that runs on the download thread. | 218 // Clean up helper that runs on the download thread. |
| 222 void OnShutdown(); | 219 void OnShutdown(); |
| 223 | 220 |
| 224 // Called only on UI thread to get the DownloadManager for a tab's profile. | 221 // Called only on UI thread to get the DownloadManager for a tab's profile. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // Used for progress updates on the UI thread, mapping download->id() to bytes | 264 // Used for progress updates on the UI thread, mapping download->id() to bytes |
| 268 // received so far. Written to by the file thread and read by the UI thread. | 265 // received so far. Written to by the file thread and read by the UI thread. |
| 269 typedef base::hash_map<int, int64> ProgressMap; | 266 typedef base::hash_map<int, int64> ProgressMap; |
| 270 ProgressMap ui_progress_; | 267 ProgressMap ui_progress_; |
| 271 Lock progress_lock_; | 268 Lock progress_lock_; |
| 272 | 269 |
| 273 DISALLOW_EVIL_CONSTRUCTORS(DownloadFileManager); | 270 DISALLOW_EVIL_CONSTRUCTORS(DownloadFileManager); |
| 274 }; | 271 }; |
| 275 | 272 |
| 276 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H__ | 273 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H__ |
| OLD | NEW |