Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 924 // name when calling GetFileName(). | 924 // name when calling GetFileName(). |
| 925 download->set_path_uniquifier(new_path_uniquifier); | 925 download->set_path_uniquifier(new_path_uniquifier); |
| 926 RenameDownload(download, new_path); | 926 RenameDownload(download, new_path); |
| 927 } | 927 } |
| 928 | 928 |
| 929 // Continue the download finished sequence. | 929 // Continue the download finished sequence. |
| 930 ContinueDownloadFinished(download); | 930 ContinueDownloadFinished(download); |
| 931 } | 931 } |
| 932 | 932 |
| 933 // static | 933 // static |
| 934 // We have to tell the ResourceDispatcherHost to cancel the download from this | |
| 935 // thread, since we can't forward tasks from the file thread to the IO thread | |
| 936 // reliably (crash on shutdown race condition). | |
| 937 void DownloadManager::CancelDownloadRequest(int render_process_id, | |
| 938 int request_id) { | |
| 939 ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host(); | |
| 940 base::Thread* io_thread = g_browser_process->io_thread(); | |
| 941 if (!io_thread || !rdh) | |
| 942 return; | |
| 943 io_thread->message_loop()->PostTask(FROM_HERE, | |
| 944 NewRunnableFunction(&DownloadManager::OnCancelDownloadRequest, | |
| 945 rdh, | |
| 946 render_process_id, | |
| 947 request_id)); | |
| 948 } | |
| 949 | |
| 950 // static | |
| 951 void DownloadManager::OnCancelDownloadRequest(ResourceDispatcherHost* rdh, | 934 void DownloadManager::OnCancelDownloadRequest(ResourceDispatcherHost* rdh, |
| 952 int render_process_id, | 935 int render_process_id, |
| 953 int request_id) { | 936 int request_id) { |
| 937 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | |
| 954 rdh->CancelRequest(render_process_id, request_id, false); | 938 rdh->CancelRequest(render_process_id, request_id, false); |
| 955 } | 939 } |
| 956 | 940 |
| 957 void DownloadManager::DownloadCancelled(int32 download_id) { | 941 void DownloadManager::DownloadCancelled(int32 download_id) { |
| 958 DownloadMap::iterator it = in_progress_.find(download_id); | 942 DownloadMap::iterator it = in_progress_.find(download_id); |
| 959 if (it == in_progress_.end()) | 943 if (it == in_progress_.end()) |
| 960 return; | 944 return; |
| 961 DownloadItem* download = it->second; | 945 DownloadItem* download = it->second; |
| 962 | 946 |
| 963 // Clean up will happen when the history system create callback runs if we | 947 // Clean up will happen when the history system create callback runs if we |
| 964 // don't have a valid db_handle yet. | 948 // don't have a valid db_handle yet. |
| 965 if (download->db_handle() != kUninitializedHandle) { | 949 if (download->db_handle() != kUninitializedHandle) { |
| 966 in_progress_.erase(it); | 950 in_progress_.erase(it); |
| 967 UpdateHistoryForDownload(download); | 951 UpdateHistoryForDownload(download); |
| 968 } | 952 } |
| 969 | 953 |
| 970 DownloadCancelledInternal(download_id, | 954 DownloadCancelledInternal(download_id, |
| 971 download->render_process_id(), | 955 download->render_process_id(), |
| 972 download->request_id()); | 956 download->request_id()); |
| 973 } | 957 } |
| 974 | 958 |
| 975 void DownloadManager::DownloadCancelledInternal(int download_id, | 959 void DownloadManager::DownloadCancelledInternal(int download_id, |
| 976 int render_process_id, | 960 int render_process_id, |
| 977 int request_id) { | 961 int request_id) { |
| 978 // Cancel the network request. | 962 // Cancel the network request. RDH is guaranteed to outlive the IO thread. |
| 979 CancelDownloadRequest(render_process_id, request_id); | 963 ChromeThread::PostTask( |
| 964 ChromeThread::IO, FROM_HERE, | |
| 965 NewRunnableFunction(&DownloadManager::OnCancelDownloadRequest, | |
| 966 g_browser_process->resource_dispatcher_host(), | |
| 967 render_process_id, | |
| 968 request_id)); | |
| 980 | 969 |
| 981 // Tell the file manager to cancel the download. | 970 // Tell the file manager to cancel the download. |
| 982 file_manager_->RemoveDownload(download_id, this); // On the UI thread | 971 file_manager_->RemoveDownload(download_id, this); // On the UI thread |
| 983 file_loop_->PostTask(FROM_HERE, | 972 file_loop_->PostTask(FROM_HERE, |
| 984 NewRunnableMethod(file_manager_, | 973 NewRunnableMethod(file_manager_, |
| 985 &DownloadFileManager::CancelDownload, | 974 &DownloadFileManager::CancelDownload, |
| 986 download_id)); | 975 download_id)); |
| 987 } | 976 } |
| 988 | 977 |
| 989 void DownloadManager::PauseDownload(int32 download_id, bool pause) { | 978 void DownloadManager::PauseDownload(int32 download_id, bool pause) { |
| 990 DownloadMap::iterator it = in_progress_.find(download_id); | 979 DownloadMap::iterator it = in_progress_.find(download_id); |
| 991 if (it != in_progress_.end()) { | 980 if (it == in_progress_.end()) |
| 992 DownloadItem* download = it->second; | 981 return; |
| 993 if (pause == download->is_paused()) | |
| 994 return; | |
| 995 | 982 |
| 996 // Inform the ResourceDispatcherHost of the new pause state. | 983 DownloadItem* download = it->second; |
| 997 base::Thread* io_thread = g_browser_process->io_thread(); | 984 if (pause == download->is_paused()) |
| 998 ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host(); | 985 return; |
| 999 if (!io_thread || !rdh) | |
| 1000 return; | |
| 1001 | 986 |
| 1002 io_thread->message_loop()->PostTask(FROM_HERE, | 987 // Inform the ResourceDispatcherHost of the new pause state. |
| 1003 NewRunnableFunction(&DownloadManager::OnPauseDownloadRequest, | 988 ChromeThread::PostTask( |
| 1004 rdh, | 989 ChromeThread::IO, FROM_HERE, |
| 1005 download->render_process_id(), | 990 NewRunnableFunction(&DownloadManager::OnPauseDownloadRequest, |
|
darin (slow to review)
2009/10/27 00:06:52
nit: indentation
jam
2009/10/27 02:38:18
Done.
| |
| 1006 download->request_id(), | 991 g_browser_process->resource_dispatcher_host(), |
| 1007 pause)); | 992 download->render_process_id(), |
| 1008 } | 993 download->request_id(), |
| 994 pause)); | |
| 1009 } | 995 } |
| 1010 | 996 |
| 1011 // static | 997 // static |
| 1012 void DownloadManager::OnPauseDownloadRequest(ResourceDispatcherHost* rdh, | 998 void DownloadManager::OnPauseDownloadRequest(ResourceDispatcherHost* rdh, |
| 1013 int render_process_id, | 999 int render_process_id, |
| 1014 int request_id, | 1000 int request_id, |
| 1015 bool pause) { | 1001 bool pause) { |
| 1016 rdh->PauseRequest(render_process_id, request_id, pause); | 1002 rdh->PauseRequest(render_process_id, request_id, pause); |
| 1017 } | 1003 } |
| 1018 | 1004 |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1549 | 1535 |
| 1550 if (contents) | 1536 if (contents) |
| 1551 contents->OnStartDownload(download); | 1537 contents->OnStartDownload(download); |
| 1552 } | 1538 } |
| 1553 | 1539 |
| 1554 // Clears the last download path, used to initialize "save as" dialogs. | 1540 // Clears the last download path, used to initialize "save as" dialogs. |
| 1555 void DownloadManager::ClearLastDownloadPath() { | 1541 void DownloadManager::ClearLastDownloadPath() { |
| 1556 last_download_path_ = FilePath(); | 1542 last_download_path_ = FilePath(); |
| 1557 } | 1543 } |
| 1558 | 1544 |
| OLD | NEW |