Chromium Code Reviews| 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 // The DownloadManager object manages the process of downloading, including | 5 // The DownloadManager object manages the process of downloading, including |
| 6 // updates to the history system and providing the information for displaying | 6 // updates to the history system and providing the information for displaying |
| 7 // the downloads view in the Destinations tab. There is one DownloadManager per | 7 // the downloads view in the Destinations tab. There is one DownloadManager per |
| 8 // active profile in Chrome. | 8 // active profile in Chrome. |
| 9 // | 9 // |
| 10 // Download observers: | 10 // Download observers: |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 #include <vector> | 34 #include <vector> |
| 35 | 35 |
| 36 #include "base/basictypes.h" | 36 #include "base/basictypes.h" |
| 37 #include "base/file_path.h" | 37 #include "base/file_path.h" |
| 38 #include "base/gtest_prod_util.h" | 38 #include "base/gtest_prod_util.h" |
| 39 #include "base/memory/ref_counted.h" | 39 #include "base/memory/ref_counted.h" |
| 40 #include "base/memory/weak_ptr.h" | 40 #include "base/memory/weak_ptr.h" |
| 41 #include "base/observer_list.h" | 41 #include "base/observer_list.h" |
| 42 #include "base/scoped_ptr.h" | 42 #include "base/scoped_ptr.h" |
| 43 #include "base/time.h" | 43 #include "base/time.h" |
| 44 #include "chrome/browser/download/download_item.h" | |
| 44 #include "chrome/browser/download/download_status_updater_delegate.h" | 45 #include "chrome/browser/download/download_status_updater_delegate.h" |
| 45 #include "chrome/browser/download/download_process_handle.h" | 46 #include "chrome/browser/download/download_process_handle.h" |
| 46 #include "chrome/browser/ui/shell_dialogs.h" | 47 #include "chrome/browser/ui/shell_dialogs.h" |
| 47 #include "content/browser/browser_thread.h" | 48 #include "content/browser/browser_thread.h" |
| 48 | 49 |
| 49 class DownloadFileManager; | 50 class DownloadFileManager; |
| 50 class DownloadHistory; | 51 class DownloadHistory; |
| 51 class DownloadItem; | |
| 52 class DownloadPrefs; | 52 class DownloadPrefs; |
| 53 class DownloadStatusUpdater; | 53 class DownloadStatusUpdater; |
| 54 class GURL; | 54 class GURL; |
| 55 class Profile; | 55 class Profile; |
| 56 class ResourceDispatcherHost; | 56 class ResourceDispatcherHost; |
| 57 class TabContents; | 57 class TabContents; |
| 58 struct DownloadCreateInfo; | 58 struct DownloadCreateInfo; |
| 59 struct DownloadHistoryInfo; | |
| 59 struct DownloadSaveInfo; | 60 struct DownloadSaveInfo; |
| 60 | 61 |
| 61 // Browser's download manager: manages all downloads and destination view. | 62 // Browser's download manager: manages all downloads and destination view. |
| 62 class DownloadManager | 63 class DownloadManager |
| 63 : public base::RefCountedThreadSafe<DownloadManager, | 64 : public base::RefCountedThreadSafe<DownloadManager, |
| 64 BrowserThread::DeleteOnUIThread>, | 65 BrowserThread::DeleteOnUIThread>, |
| 65 public DownloadStatusUpdaterDelegate, | 66 public DownloadStatusUpdaterDelegate, |
| 66 public SelectFileDialog::Listener { | 67 public SelectFileDialog::Listener { |
| 67 public: | 68 public: |
| 68 explicit DownloadManager(DownloadStatusUpdater* status_updater); | 69 explicit DownloadManager(DownloadStatusUpdater* status_updater); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 | 108 |
| 108 // Returns all non-temporary downloads matching |query|. Empty query matches | 109 // Returns all non-temporary downloads matching |query|. Empty query matches |
| 109 // everything. | 110 // everything. |
| 110 void SearchDownloads(const string16& query, | 111 void SearchDownloads(const string16& query, |
| 111 std::vector<DownloadItem*>* result); | 112 std::vector<DownloadItem*>* result); |
| 112 | 113 |
| 113 // Returns true if initialized properly. | 114 // Returns true if initialized properly. |
| 114 bool Init(Profile* profile); | 115 bool Init(Profile* profile); |
| 115 | 116 |
| 116 // Notifications sent from the download thread to the UI thread | 117 // Notifications sent from the download thread to the UI thread |
| 117 void StartDownload(DownloadCreateInfo* info); | 118 void StartDownload(int32 id); |
| 118 void UpdateDownload(int32 download_id, int64 size); | 119 void UpdateDownload(int32 download_id, int64 size); |
| 119 // |hash| is sha256 hash for the downloaded file. It is empty when the hash | 120 // |hash| is sha256 hash for the downloaded file. It is empty when the hash |
| 120 // is not available. | 121 // is not available. |
| 121 void OnResponseCompleted(int32 download_id, int64 size, int os_error, | 122 void OnResponseCompleted(int32 download_id, int64 size, int os_error, |
| 122 const std::string& hash); | 123 const std::string& hash); |
| 123 | 124 |
| 124 // Called from a view when a user clicks a UI button or link. | 125 // Called from a view when a user clicks a UI button or link. |
| 125 void DownloadCancelled(int32 download_id); | 126 void DownloadCancelled(int32 download_id); |
| 126 void PauseDownload(int32 download_id, bool pause); | 127 void PauseDownload(int32 download_id, bool pause); |
| 127 void RemoveDownload(int64 download_handle); | 128 void RemoveDownload(int64 download_handle); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 TabContents* tab_contents); | 184 TabContents* tab_contents); |
| 184 | 185 |
| 185 // Allow objects to observe the download creation process. | 186 // Allow objects to observe the download creation process. |
| 186 void AddObserver(Observer* observer); | 187 void AddObserver(Observer* observer); |
| 187 | 188 |
| 188 // Remove a download observer from ourself. | 189 // Remove a download observer from ourself. |
| 189 void RemoveObserver(Observer* observer); | 190 void RemoveObserver(Observer* observer); |
| 190 | 191 |
| 191 // Methods called on completion of a query sent to the history system. | 192 // Methods called on completion of a query sent to the history system. |
| 192 void OnQueryDownloadEntriesComplete( | 193 void OnQueryDownloadEntriesComplete( |
| 193 std::vector<DownloadCreateInfo>* entries); | 194 std::vector<DownloadHistoryInfo>* entries); |
| 194 void OnCreateDownloadEntryComplete( | 195 void OnCreateDownloadEntryComplete(int32 download_id, int64 db_handle); |
| 195 DownloadCreateInfo info, int64 db_handle); | |
| 196 | 196 |
| 197 // Display a new download in the appropriate browser UI. | 197 // Display a new download in the appropriate browser UI. |
| 198 void ShowDownloadInBrowser(DownloadProcessHandle* process_handle, | 198 void ShowDownloadInBrowser(DownloadItem* download); |
| 199 DownloadItem* download); | |
| 200 | 199 |
| 201 // The number of in progress (including paused) downloads. | 200 // The number of in progress (including paused) downloads. |
| 202 int in_progress_count() const { | 201 int in_progress_count() const { |
| 203 return static_cast<int>(in_progress_.size()); | 202 return static_cast<int>(in_progress_.size()); |
| 204 } | 203 } |
| 205 | 204 |
| 206 Profile* profile() { return profile_; } | 205 Profile* profile() { return profile_; } |
| 207 | 206 |
| 208 DownloadHistory* download_history() { return download_history_.get(); } | 207 DownloadHistory* download_history() { return download_history_.get(); } |
| 209 | 208 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 225 virtual int64 GetTotalDownloadBytes(); | 224 virtual int64 GetTotalDownloadBytes(); |
| 226 | 225 |
| 227 // Overridden from SelectFileDialog::Listener: | 226 // Overridden from SelectFileDialog::Listener: |
| 228 virtual void FileSelected(const FilePath& path, int index, void* params); | 227 virtual void FileSelected(const FilePath& path, int index, void* params); |
| 229 virtual void FileSelectionCanceled(void* params); | 228 virtual void FileSelectionCanceled(void* params); |
| 230 | 229 |
| 231 // Called when the user has validated the download of a dangerous file. | 230 // Called when the user has validated the download of a dangerous file. |
| 232 void DangerousDownloadValidated(DownloadItem* download); | 231 void DangerousDownloadValidated(DownloadItem* download); |
| 233 | 232 |
| 234 // Callback function after url is checked with safebrowsing service. | 233 // Callback function after url is checked with safebrowsing service. |
| 235 void CheckDownloadUrlDone(DownloadCreateInfo* info, bool is_dangerous_url); | 234 void CheckDownloadUrlDone(int32 download_id, bool is_dangerous_url); |
| 236 | 235 |
| 237 // Callback function after download file hash is checked with safebrowsing | 236 // Callback function after download file hash is checked with safebrowsing |
| 238 // service. | 237 // service. |
| 239 void CheckDownloadHashDone(int32 download_id, bool is_dangerous_hash); | 238 void CheckDownloadHashDone(int32 download_id, bool is_dangerous_hash); |
| 240 | 239 |
| 241 private: | 240 private: |
| 242 // For testing. | 241 // For testing. |
| 243 friend class DownloadManagerTest; | 242 friend class DownloadManagerTest; |
| 244 friend class MockDownloadManager; | 243 friend class MockDownloadManager; |
| 245 | 244 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 266 | 265 |
| 267 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 266 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
| 268 friend class DeleteTask<DownloadManager>; | 267 friend class DeleteTask<DownloadManager>; |
| 269 friend class OtherDownloadManagerObserver; | 268 friend class OtherDownloadManagerObserver; |
| 270 | 269 |
| 271 ~DownloadManager(); | 270 ~DownloadManager(); |
| 272 | 271 |
| 273 // Called on the download thread to check whether the suggested file path | 272 // Called on the download thread to check whether the suggested file path |
| 274 // exists. We don't check if the file exists on the UI thread to avoid UI | 273 // exists. We don't check if the file exists on the UI thread to avoid UI |
| 275 // stalls from interacting with the file system. | 274 // stalls from interacting with the file system. |
| 276 void CheckIfSuggestedPathExists(DownloadCreateInfo* info, | 275 void CheckIfSuggestedPathExists(int32 download_id, |
| 276 DownloadItem::DownloadStateInfo state, | |
| 277 const FilePath& default_path); | 277 const FilePath& default_path); |
| 278 | 278 |
| 279 // Called on the UI thread once the DownloadManager has determined whether the | 279 // Called on the UI thread once the DownloadManager has determined whether the |
| 280 // suggested file path exists. | 280 // suggested file path exists. |
| 281 void OnPathExistenceAvailable(DownloadCreateInfo* info); | 281 void OnPathExistenceAvailable(int32 download_id, |
| 282 DownloadItem::DownloadStateInfo new_state); | |
| 282 | 283 |
| 283 // Called back after a target path for the file to be downloaded to has been | 284 // Called back after a target path for the file to be downloaded to has been |
| 284 // determined, either automatically based on the suggested file name, or by | 285 // determined, either automatically based on the suggested file name, or by |
| 285 // the user in a Save As dialog box. | 286 // the user in a Save As dialog box. |
| 286 void AttachDownloadItem(DownloadCreateInfo* info); | 287 void ContinueDownloadWithPath(int32 download_id, const FilePath& chosen_file); |
| 287 | 288 |
| 288 // Download cancel helper function. | 289 // Download cancel helper function. |
| 289 // |process_handle| is passed by value because it is ultimately passed to | 290 // |process_handle| is passed by value because it is ultimately passed to |
| 290 // other threads, and this way we don't have to worry about object lifetimes. | 291 // other threads, and this way we don't have to worry about object lifetimes. |
| 291 void DownloadCancelledInternal(int download_id, | 292 void DownloadCancelledInternal(int download_id, |
| 292 DownloadProcessHandle process_handle); | 293 DownloadProcessHandle process_handle); |
| 293 | 294 |
| 294 // All data has been downloaded. | 295 // All data has been downloaded. |
| 295 // |hash| is sha256 hash for the downloaded file. It is empty when the hash | 296 // |hash| is sha256 hash for the downloaded file. It is empty when the hash |
| 296 // is not available. | 297 // is not available. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 307 // |process_handle| is passed by value because this is called from other | 308 // |process_handle| is passed by value because this is called from other |
| 308 // threads, and this way we don't have to worry about object lifetimes. | 309 // threads, and this way we don't have to worry about object lifetimes. |
| 309 void PauseDownloadRequest(ResourceDispatcherHost* rdh, | 310 void PauseDownloadRequest(ResourceDispatcherHost* rdh, |
| 310 DownloadProcessHandle process_handle, | 311 DownloadProcessHandle process_handle, |
| 311 bool pause); | 312 bool pause); |
| 312 | 313 |
| 313 // Inform observers that the model has changed. | 314 // Inform observers that the model has changed. |
| 314 void NotifyModelChanged(); | 315 void NotifyModelChanged(); |
| 315 | 316 |
| 316 DownloadItem* GetDownloadItem(int id); | 317 DownloadItem* GetDownloadItem(int id); |
| 318 DownloadItem* GetActiveDownloadItem(int id); | |
|
Paweł Hajdan Jr.
2011/05/19 16:18:25
It is definitely worth to document what's the diff
ahendrickson
2011/05/19 20:16:49
Done.
| |
| 317 | 319 |
| 318 // Debugging routine to confirm relationship between below | 320 // Debugging routine to confirm relationship between below |
| 319 // containers; no-op if NDEBUG. | 321 // containers; no-op if NDEBUG. |
| 320 void AssertContainersConsistent() const; | 322 void AssertContainersConsistent() const; |
| 321 | 323 |
| 322 // |downloads_| is the owning set for all downloads known to the | 324 // |downloads_| is the owning set for all downloads known to the |
| 323 // DownloadManager. This includes downloads started by the user in | 325 // DownloadManager. This includes downloads started by the user in |
| 324 // this session, downloads initialized from the history system, and | 326 // this session, downloads initialized from the history system, and |
| 325 // "save page as" downloads. All other DownloadItem containers in | 327 // "save page as" downloads. All other DownloadItem containers in |
| 326 // the DownloadManager are maps; they do not own the DownloadItems. | 328 // the DownloadManager are maps; they do not own the DownloadItems. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 // The "Save As" dialog box used to ask the user where a file should be | 394 // The "Save As" dialog box used to ask the user where a file should be |
| 393 // saved. | 395 // saved. |
| 394 scoped_refptr<SelectFileDialog> select_file_dialog_; | 396 scoped_refptr<SelectFileDialog> select_file_dialog_; |
| 395 | 397 |
| 396 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; | 398 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; |
| 397 | 399 |
| 398 DISALLOW_COPY_AND_ASSIGN(DownloadManager); | 400 DISALLOW_COPY_AND_ASSIGN(DownloadManager); |
| 399 }; | 401 }; |
| 400 | 402 |
| 401 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 403 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
| OLD | NEW |