| 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 #include "chrome/browser/download/download_manager.h" | 5 #include "chrome/browser/download/download_manager.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 // We need to update the path uniquifier so that the UI shows the right | 834 // We need to update the path uniquifier so that the UI shows the right |
| 835 // name when calling GetFileName(). | 835 // name when calling GetFileName(). |
| 836 download->set_path_uniquifier(new_path_uniquifier); | 836 download->set_path_uniquifier(new_path_uniquifier); |
| 837 RenameDownload(download, new_path); | 837 RenameDownload(download, new_path); |
| 838 } | 838 } |
| 839 | 839 |
| 840 // Continue the download finished sequence. | 840 // Continue the download finished sequence. |
| 841 ContinueDownloadFinished(download); | 841 ContinueDownloadFinished(download); |
| 842 } | 842 } |
| 843 | 843 |
| 844 // static | |
| 845 void DownloadManager::OnCancelDownloadRequest(ResourceDispatcherHost* rdh, | |
| 846 int render_process_id, | |
| 847 int request_id) { | |
| 848 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | |
| 849 rdh->CancelRequest(render_process_id, request_id, false); | |
| 850 } | |
| 851 | |
| 852 void DownloadManager::DownloadCancelled(int32 download_id) { | 844 void DownloadManager::DownloadCancelled(int32 download_id) { |
| 853 DownloadMap::iterator it = in_progress_.find(download_id); | 845 DownloadMap::iterator it = in_progress_.find(download_id); |
| 854 if (it == in_progress_.end()) | 846 if (it == in_progress_.end()) |
| 855 return; | 847 return; |
| 856 DownloadItem* download = it->second; | 848 DownloadItem* download = it->second; |
| 857 | 849 |
| 858 // Clean up will happen when the history system create callback runs if we | 850 // Clean up will happen when the history system create callback runs if we |
| 859 // don't have a valid db_handle yet. | 851 // don't have a valid db_handle yet. |
| 860 if (download->db_handle() != kUninitializedHandle) { | 852 if (download->db_handle() != kUninitializedHandle) { |
| 861 in_progress_.erase(it); | 853 in_progress_.erase(it); |
| 862 UpdateHistoryForDownload(download); | 854 UpdateHistoryForDownload(download); |
| 863 } | 855 } |
| 864 | 856 |
| 865 DownloadCancelledInternal(download_id, | 857 DownloadCancelledInternal(download_id, |
| 866 download->render_process_id(), | 858 download->render_process_id(), |
| 867 download->request_id()); | 859 download->request_id()); |
| 868 UpdateAppIcon(); | 860 UpdateAppIcon(); |
| 869 } | 861 } |
| 870 | 862 |
| 871 void DownloadManager::DownloadCancelledInternal(int download_id, | 863 void DownloadManager::DownloadCancelledInternal(int download_id, |
| 872 int render_process_id, | 864 int render_process_id, |
| 873 int request_id) { | 865 int request_id) { |
| 874 // Cancel the network request. RDH is guaranteed to outlive the IO thread. | 866 // Cancel the network request. RDH is guaranteed to outlive the IO thread. |
| 875 ChromeThread::PostTask( | 867 ChromeThread::PostTask( |
| 876 ChromeThread::IO, FROM_HERE, | 868 ChromeThread::IO, FROM_HERE, |
| 877 NewRunnableFunction(&DownloadManager::OnCancelDownloadRequest, | 869 NewRunnableFunction(&download_util::CancelDownloadRequest, |
| 878 g_browser_process->resource_dispatcher_host(), | 870 g_browser_process->resource_dispatcher_host(), |
| 879 render_process_id, | 871 render_process_id, |
| 880 request_id)); | 872 request_id)); |
| 881 | 873 |
| 882 // Tell the file manager to cancel the download. | 874 // Tell the file manager to cancel the download. |
| 883 file_manager_->RemoveDownload(download_id, this); // On the UI thread | 875 file_manager_->RemoveDownload(download_id, this); // On the UI thread |
| 884 ChromeThread::PostTask( | 876 ChromeThread::PostTask( |
| 885 ChromeThread::FILE, FROM_HERE, | 877 ChromeThread::FILE, FROM_HERE, |
| 886 NewRunnableMethod( | 878 NewRunnableMethod( |
| 887 file_manager_, &DownloadFileManager::CancelDownload, download_id)); | 879 file_manager_, &DownloadFileManager::CancelDownload, download_id)); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 return RemoveDownloadsBetween(base::Time(), base::Time()); | 1034 return RemoveDownloadsBetween(base::Time(), base::Time()); |
| 1043 } | 1035 } |
| 1044 | 1036 |
| 1045 // Initiate a download of a specific URL. We send the request to the | 1037 // Initiate a download of a specific URL. We send the request to the |
| 1046 // ResourceDispatcherHost, and let it send us responses like a regular | 1038 // ResourceDispatcherHost, and let it send us responses like a regular |
| 1047 // download. | 1039 // download. |
| 1048 void DownloadManager::DownloadUrl(const GURL& url, | 1040 void DownloadManager::DownloadUrl(const GURL& url, |
| 1049 const GURL& referrer, | 1041 const GURL& referrer, |
| 1050 const std::string& referrer_charset, | 1042 const std::string& referrer_charset, |
| 1051 TabContents* tab_contents) { | 1043 TabContents* tab_contents) { |
| 1052 file_manager_->DownloadUrl(url, | 1044 DownloadUrlToFile(url, referrer, referrer_charset, DownloadSaveInfo(), |
| 1053 referrer, | 1045 tab_contents); |
| 1054 referrer_charset, | |
| 1055 DownloadSaveInfo(), | |
| 1056 tab_contents->GetRenderProcessHost()->id(), | |
| 1057 tab_contents->render_view_host()->routing_id(), | |
| 1058 request_context_getter_); | |
| 1059 } | 1046 } |
| 1060 | 1047 |
| 1061 void DownloadManager::DownloadUrlToFile(const GURL& url, | 1048 void DownloadManager::DownloadUrlToFile(const GURL& url, |
| 1062 const GURL& referrer, | 1049 const GURL& referrer, |
| 1063 const std::string& referrer_charset, | 1050 const std::string& referrer_charset, |
| 1064 const DownloadSaveInfo& save_info, | 1051 const DownloadSaveInfo& save_info, |
| 1065 TabContents* tab_contents) { | 1052 TabContents* tab_contents) { |
| 1066 DCHECK(tab_contents); | 1053 DCHECK(tab_contents); |
| 1067 file_manager_->DownloadUrl(url, | 1054 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, |
| 1068 referrer, | 1055 NewRunnableFunction(&download_util::DownloadUrl, |
| 1069 referrer_charset, | 1056 url, |
| 1070 save_info, | 1057 referrer, |
| 1071 tab_contents->GetRenderProcessHost()->id(), | 1058 referrer_charset, |
| 1072 tab_contents->render_view_host()->routing_id(), | 1059 save_info, |
| 1073 request_context_getter_); | 1060 g_browser_process->resource_dispatcher_host(), |
| 1061 tab_contents->GetRenderProcessHost()->id(), |
| 1062 tab_contents->render_view_host()->routing_id(), |
| 1063 request_context_getter_)); |
| 1074 } | 1064 } |
| 1075 | 1065 |
| 1076 void DownloadManager::GenerateExtension( | 1066 void DownloadManager::GenerateExtension( |
| 1077 const FilePath& file_name, | 1067 const FilePath& file_name, |
| 1078 const std::string& mime_type, | 1068 const std::string& mime_type, |
| 1079 FilePath::StringType* generated_extension) { | 1069 FilePath::StringType* generated_extension) { |
| 1080 // We're worried about three things here: | 1070 // We're worried about three things here: |
| 1081 // | 1071 // |
| 1082 // 1) Security. Many sites let users upload content, such as buddy icons, to | 1072 // 1) Security. Many sites let users upload content, such as buddy icons, to |
| 1083 // their web sites. We want to mitigate the case where an attacker | 1073 // their web sites. We want to mitigate the case where an attacker |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1608 observing_download_manager_->NotifyModelChanged(); | 1598 observing_download_manager_->NotifyModelChanged(); |
| 1609 } | 1599 } |
| 1610 | 1600 |
| 1611 void DownloadManager::OtherDownloadManagerObserver::SetDownloads( | 1601 void DownloadManager::OtherDownloadManagerObserver::SetDownloads( |
| 1612 std::vector<DownloadItem*>& downloads) { | 1602 std::vector<DownloadItem*>& downloads) { |
| 1613 } | 1603 } |
| 1614 | 1604 |
| 1615 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { | 1605 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { |
| 1616 observed_download_manager_ = NULL; | 1606 observed_download_manager_ = NULL; |
| 1617 } | 1607 } |
| OLD | NEW |