| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 class ResourceDispatcherHost; | 50 class ResourceDispatcherHost; |
| 51 class URLRequestContextGetter; | 51 class URLRequestContextGetter; |
| 52 class TabContents; | 52 class TabContents; |
| 53 struct DownloadSaveInfo; | 53 struct DownloadSaveInfo; |
| 54 | 54 |
| 55 // Browser's download manager: manages all downloads and destination view. | 55 // Browser's download manager: manages all downloads and destination view. |
| 56 class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>, | 56 class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>, |
| 57 public SelectFileDialog::Listener { | 57 public SelectFileDialog::Listener { |
| 58 // For testing. | 58 // For testing. |
| 59 friend class DownloadManagerTest; | 59 friend class DownloadManagerTest; |
| 60 friend class MockDownloadManager; |
| 60 | 61 |
| 61 public: | 62 public: |
| 62 // A fake download table ID which representas a download that has started, | 63 // A fake download table ID which representas a download that has started, |
| 63 // but is not yet in the table. | 64 // but is not yet in the table. |
| 64 static const int kUninitializedHandle; | 65 static const int kUninitializedHandle; |
| 65 | 66 |
| 66 DownloadManager(); | 67 DownloadManager(); |
| 67 | 68 |
| 68 static void RegisterUserPrefs(PrefService* prefs); | 69 static void RegisterUserPrefs(PrefService* prefs); |
| 69 | 70 |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 // suggested file path exists. | 312 // suggested file path exists. |
| 312 void OnPathExistenceAvailable(DownloadCreateInfo* info); | 313 void OnPathExistenceAvailable(DownloadCreateInfo* info); |
| 313 | 314 |
| 314 // Called back after a target path for the file to be downloaded to has been | 315 // Called back after a target path for the file to be downloaded to has been |
| 315 // determined, either automatically based on the suggested file name, or by | 316 // determined, either automatically based on the suggested file name, or by |
| 316 // the user in a Save As dialog box. | 317 // the user in a Save As dialog box. |
| 317 void ContinueStartDownload(DownloadCreateInfo* info, | 318 void ContinueStartDownload(DownloadCreateInfo* info, |
| 318 const FilePath& target_path); | 319 const FilePath& target_path); |
| 319 | 320 |
| 320 // Update the history service for a particular download. | 321 // Update the history service for a particular download. |
| 321 void UpdateHistoryForDownload(DownloadItem* download); | 322 // Marked virtual for testing. |
| 323 virtual void UpdateHistoryForDownload(DownloadItem* download); |
| 322 void RemoveDownloadFromHistory(DownloadItem* download); | 324 void RemoveDownloadFromHistory(DownloadItem* download); |
| 323 void RemoveDownloadsFromHistoryBetween(const base::Time remove_begin, | 325 void RemoveDownloadsFromHistoryBetween(const base::Time remove_begin, |
| 324 const base::Time remove_before); | 326 const base::Time remove_before); |
| 325 | 327 |
| 326 // Create an extension based on the file name and mime type. | 328 // Create an extension based on the file name and mime type. |
| 327 static void GenerateExtension(const FilePath& file_name, | 329 static void GenerateExtension(const FilePath& file_name, |
| 328 const std::string& mime_type, | 330 const std::string& mime_type, |
| 329 FilePath::StringType* generated_extension); | 331 FilePath::StringType* generated_extension); |
| 330 | 332 |
| 331 // Create a file name based on the response from the server. | 333 // Create a file name based on the response from the server. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 344 static void OnPauseDownloadRequest(ResourceDispatcherHost* rdh, | 346 static void OnPauseDownloadRequest(ResourceDispatcherHost* rdh, |
| 345 int render_process_id, | 347 int render_process_id, |
| 346 int request_id, | 348 int request_id, |
| 347 bool pause); | 349 bool pause); |
| 348 | 350 |
| 349 // Performs the last steps required when a download has been completed. | 351 // Performs the last steps required when a download has been completed. |
| 350 // It is necessary to break down the flow when a download is finished as | 352 // It is necessary to break down the flow when a download is finished as |
| 351 // dangerous downloads are downloaded to temporary files that need to be | 353 // dangerous downloads are downloaded to temporary files that need to be |
| 352 // renamed on the file thread first. | 354 // renamed on the file thread first. |
| 353 // Invoked on the UI thread. | 355 // Invoked on the UI thread. |
| 354 void ContinueDownloadFinished(DownloadItem* download); | 356 // Marked virtual for testing. |
| 357 virtual void ContinueDownloadFinished(DownloadItem* download); |
| 355 | 358 |
| 356 // Renames a finished dangerous download from its temporary file name to its | 359 // Renames a finished dangerous download from its temporary file name to its |
| 357 // real file name. | 360 // real file name. |
| 358 // Invoked on the file thread. | 361 // Invoked on the file thread. |
| 359 void ProceedWithFinishedDangerousDownload(int64 download_handle, | 362 void ProceedWithFinishedDangerousDownload(int64 download_handle, |
| 360 const FilePath& path, | 363 const FilePath& path, |
| 361 const FilePath& original_name); | 364 const FilePath& original_name); |
| 362 | 365 |
| 363 // Invoked on the UI thread when a dangerous downloaded file has been renamed. | 366 // Invoked on the UI thread when a dangerous downloaded file has been renamed. |
| 364 void DangerousDownloadRenamed(int64 download_handle, | 367 void DangerousDownloadRenamed(int64 download_handle, |
| 365 bool success, | 368 bool success, |
| 366 const FilePath& new_path, | 369 const FilePath& new_path, |
| 367 int new_path_uniquifier); | 370 int new_path_uniquifier); |
| 368 | 371 |
| 369 // Checks whether a file represents a risk if downloaded. | 372 // Checks whether a file represents a risk if downloaded. |
| 370 bool IsDangerous(const FilePath& file_name); | 373 bool IsDangerous(const FilePath& file_name); |
| 371 | 374 |
| 372 // Updates the app icon about the overall download progress. | 375 // Updates the app icon about the overall download progress. |
| 373 void UpdateAppIcon(); | 376 // Marked virtual for testing. |
| 377 virtual void UpdateAppIcon(); |
| 374 | 378 |
| 375 // Changes the paths and file name of the specified |download|, propagating | 379 // Changes the paths and file name of the specified |download|, propagating |
| 376 // the change to the history system. | 380 // the change to the history system. |
| 377 void RenameDownload(DownloadItem* download, const FilePath& new_path); | 381 void RenameDownload(DownloadItem* download, const FilePath& new_path); |
| 378 | 382 |
| 379 // Inform observers that the model has changed. | 383 // Inform observers that the model has changed. |
| 380 void NotifyModelChanged(); | 384 void NotifyModelChanged(); |
| 381 | 385 |
| 382 // 'downloads_' is map of all downloads in this profile. The key is the handle | 386 // 'downloads_' is map of all downloads in this profile. The key is the handle |
| 383 // returned by the history system, which is unique across sessions. This map | 387 // returned by the history system, which is unique across sessions. This map |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 // Downloads are expected to have unique handles, so FakeDbHandleGenerator | 463 // Downloads are expected to have unique handles, so FakeDbHandleGenerator |
| 460 // automatically decrement the handle value on every use. | 464 // automatically decrement the handle value on every use. |
| 461 FakeDbHandleGenerator fake_db_handle_; | 465 FakeDbHandleGenerator fake_db_handle_; |
| 462 | 466 |
| 463 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; | 467 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; |
| 464 | 468 |
| 465 DISALLOW_COPY_AND_ASSIGN(DownloadManager); | 469 DISALLOW_COPY_AND_ASSIGN(DownloadManager); |
| 466 }; | 470 }; |
| 467 | 471 |
| 468 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 472 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
| OLD | NEW |