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 #include "chrome/browser/download/download_manager.h" | 5 #include "chrome/browser/download/download_manager.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 742 | 742 |
| 743 // Clean up will happen when the history system create callback runs if we | 743 // Clean up will happen when the history system create callback runs if we |
| 744 // don't have a valid db_handle yet. | 744 // don't have a valid db_handle yet. |
| 745 if (download->db_handle() != DownloadHistory::kUninitializedHandle) { | 745 if (download->db_handle() != DownloadHistory::kUninitializedHandle) { |
| 746 in_progress_.erase(it); | 746 in_progress_.erase(it); |
| 747 active_downloads_.erase(download_id); | 747 active_downloads_.erase(download_id); |
| 748 UpdateAppIcon(); // Reflect removal from in_progress_. | 748 UpdateAppIcon(); // Reflect removal from in_progress_. |
| 749 download_history_->UpdateEntry(download); | 749 download_history_->UpdateEntry(download); |
| 750 } | 750 } |
| 751 | 751 |
| 752 DownloadCancelledInternal(download_id, download->process_handle()); | 752 DownloadCancelledInternal(download_id, download->process_handle()); |
|
Paweł Hajdan Jr.
2011/06/04 08:58:51
It seems this is the only place that calls Downloa
Randy Smith (Not in Mondays)
2011/06/07 22:41:11
It's also called from FileSelectionCancelled, at l
| |
| 753 } | 753 } |
| 754 | 754 |
| 755 void DownloadManager::DownloadCancelledInternal( | 755 void DownloadManager::DownloadCancelledInternal( |
| 756 int download_id, DownloadProcessHandle process_handle) { | 756 int download_id, DownloadProcessHandle process_handle) { |
| 757 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 757 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 758 // Cancel the network request. RDH is guaranteed to outlive the IO thread. | 758 process_handle.CancelRequest(); |
|
hendrickson_a
2011/06/04 16:01:45
I'd like this comment to be preserved (in download
Randy Smith (Not in Mondays)
2011/06/07 22:41:11
Done.
| |
| 759 download_util::CancelDownloadRequest( | |
| 760 g_browser_process->resource_dispatcher_host(), process_handle); | |
| 761 | 759 |
| 762 BrowserThread::PostTask( | 760 BrowserThread::PostTask( |
| 763 BrowserThread::FILE, FROM_HERE, | 761 BrowserThread::FILE, FROM_HERE, |
| 764 NewRunnableMethod( | 762 NewRunnableMethod( |
| 765 file_manager_, &DownloadFileManager::CancelDownload, download_id)); | 763 file_manager_, &DownloadFileManager::CancelDownload, download_id)); |
| 766 } | 764 } |
| 767 | 765 |
| 768 void DownloadManager::OnDownloadError(int32 download_id, | 766 void DownloadManager::OnDownloadError(int32 download_id, |
| 769 int64 size, | 767 int64 size, |
| 770 int os_error) { | 768 int os_error) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 794 UpdateAppIcon(); // Reflect removal from in_progress_. | 792 UpdateAppIcon(); // Reflect removal from in_progress_. |
| 795 download_history_->UpdateEntry(download); | 793 download_history_->UpdateEntry(download); |
| 796 } | 794 } |
| 797 | 795 |
| 798 BrowserThread::PostTask( | 796 BrowserThread::PostTask( |
| 799 BrowserThread::FILE, FROM_HERE, | 797 BrowserThread::FILE, FROM_HERE, |
| 800 NewRunnableMethod( | 798 NewRunnableMethod( |
| 801 file_manager_, &DownloadFileManager::CancelDownload, download_id)); | 799 file_manager_, &DownloadFileManager::CancelDownload, download_id)); |
| 802 } | 800 } |
| 803 | 801 |
| 804 void DownloadManager::PauseDownload(int32 download_id, bool pause) { | |
| 805 DownloadMap::iterator it = in_progress_.find(download_id); | |
| 806 if (it == in_progress_.end()) | |
| 807 return; | |
| 808 | |
| 809 DownloadItem* download = it->second; | |
| 810 if (pause == download->is_paused()) | |
| 811 return; | |
| 812 | |
| 813 BrowserThread::PostTask( | |
| 814 BrowserThread::IO, FROM_HERE, | |
| 815 NewRunnableMethod(this, | |
| 816 &DownloadManager::PauseDownloadRequest, | |
| 817 g_browser_process->resource_dispatcher_host(), | |
| 818 download->process_handle(), | |
| 819 pause)); | |
| 820 } | |
| 821 | |
| 822 void DownloadManager::UpdateAppIcon() { | 802 void DownloadManager::UpdateAppIcon() { |
| 823 if (status_updater_) | 803 if (status_updater_) |
| 824 status_updater_->Update(); | 804 status_updater_->Update(); |
| 825 } | 805 } |
| 826 | 806 |
| 827 void DownloadManager::PauseDownloadRequest(ResourceDispatcherHost* rdh, | |
| 828 DownloadProcessHandle process_handle, | |
| 829 bool pause) { | |
| 830 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 831 rdh->PauseRequest(process_handle.child_id(), | |
| 832 process_handle.request_id(), | |
| 833 pause); | |
| 834 } | |
| 835 | |
| 836 void DownloadManager::RemoveDownload(int64 download_handle) { | 807 void DownloadManager::RemoveDownload(int64 download_handle) { |
| 837 DownloadMap::iterator it = history_downloads_.find(download_handle); | 808 DownloadMap::iterator it = history_downloads_.find(download_handle); |
| 838 if (it == history_downloads_.end()) | 809 if (it == history_downloads_.end()) |
| 839 return; | 810 return; |
| 840 | 811 |
| 841 // Make history update. | 812 // Make history update. |
| 842 DownloadItem* download = it->second; | 813 DownloadItem* download = it->second; |
| 843 download_history_->RemoveEntry(download); | 814 download_history_->RemoveEntry(download); |
| 844 | 815 |
| 845 // Remove from our tables and delete. | 816 // Remove from our tables and delete. |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1277 observed_download_manager_->RemoveObserver(this); | 1248 observed_download_manager_->RemoveObserver(this); |
| 1278 } | 1249 } |
| 1279 | 1250 |
| 1280 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { | 1251 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { |
| 1281 observing_download_manager_->NotifyModelChanged(); | 1252 observing_download_manager_->NotifyModelChanged(); |
| 1282 } | 1253 } |
| 1283 | 1254 |
| 1284 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { | 1255 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { |
| 1285 observed_download_manager_ = NULL; | 1256 observed_download_manager_ = NULL; |
| 1286 } | 1257 } |
| OLD | NEW |