OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/download/download_manager_impl.h" | 5 #include "content/browser/download/download_manager_impl.h" |
6 | 6 |
7 #include <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 | 353 |
354 VLOG(20) << __FUNCTION__ << "()" | 354 VLOG(20) << __FUNCTION__ << "()" |
355 << " download = " << download->DebugString(true); | 355 << " download = " << download->DebugString(true); |
356 | 356 |
357 FilePath suggested_path = download->GetSuggestedPath(); | 357 FilePath suggested_path = download->GetSuggestedPath(); |
358 | 358 |
359 if (download->PromptUserForSaveLocation()) { | 359 if (download->PromptUserForSaveLocation()) { |
360 // We must ask the user for the place to put the download. | 360 // We must ask the user for the place to put the download. |
361 WebContents* contents = download->GetWebContents(); | 361 WebContents* contents = download->GetWebContents(); |
362 | 362 |
363 // |id_ptr| will be deleted in either FileSelected() or | |
364 // FileSelectionCancelled(). | |
365 int32* id_ptr = new int32; | |
366 *id_ptr = download_id; | |
367 FilePath target_path; | 363 FilePath target_path; |
368 // If |download| is a potentially dangerous file, then |suggested_path| | 364 // If |download| is a potentially dangerous file, then |suggested_path| |
369 // contains the intermediate name instead of the final download | 365 // contains the intermediate name instead of the final download |
370 // filename. The latter is GetTargetName(). | 366 // filename. The latter is GetTargetName(). |
371 if (download->GetDangerType() != | 367 if (download->GetDangerType() != |
372 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) | 368 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) |
373 target_path = suggested_path.DirName().Append(download->GetTargetName()); | 369 target_path = suggested_path.DirName().Append(download->GetTargetName()); |
374 else | 370 else |
375 target_path = suggested_path; | 371 target_path = suggested_path; |
376 | 372 |
377 delegate_->ChooseDownloadPath(contents, target_path, | 373 delegate_->ChooseDownloadPath(contents, target_path, |
378 reinterpret_cast<void*>(id_ptr)); | 374 download_id); |
379 FOR_EACH_OBSERVER(Observer, observers_, | 375 FOR_EACH_OBSERVER(Observer, observers_, |
380 SelectFileDialogDisplayed(this, download_id)); | 376 SelectFileDialogDisplayed(this, download_id)); |
381 } else { | 377 } else { |
382 // No prompting for download, just continue with the suggested name. | 378 // No prompting for download, just continue with the suggested name. |
383 ContinueDownloadWithPath(download, suggested_path); | 379 ContinueDownloadWithPath(download, suggested_path); |
384 } | 380 } |
385 } | 381 } |
386 | 382 |
387 content::BrowserContext* DownloadManagerImpl::GetBrowserContext() const { | 383 content::BrowserContext* DownloadManagerImpl::GetBrowserContext() const { |
388 return browser_context_; | 384 return browser_context_; |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 // TODO: It is the responsibility of the observers to query the | 851 // TODO: It is the responsibility of the observers to query the |
856 // DownloadManager. Remove the following call from here and update all | 852 // DownloadManager. Remove the following call from here and update all |
857 // observers. | 853 // observers. |
858 observer->ModelChanged(this); | 854 observer->ModelChanged(this); |
859 } | 855 } |
860 | 856 |
861 void DownloadManagerImpl::RemoveObserver(Observer* observer) { | 857 void DownloadManagerImpl::RemoveObserver(Observer* observer) { |
862 observers_.RemoveObserver(observer); | 858 observers_.RemoveObserver(observer); |
863 } | 859 } |
864 | 860 |
865 void DownloadManagerImpl::FileSelected(const FilePath& path, void* params) { | 861 void DownloadManagerImpl::FileSelected(const FilePath& path, |
| 862 int32 download_id) { |
866 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 863 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
867 | 864 |
868 int32* id_ptr = reinterpret_cast<int32*>(params); | |
869 DCHECK(id_ptr != NULL); | |
870 int32 download_id = *id_ptr; | |
871 delete id_ptr; | |
872 | |
873 DownloadItem* download = GetActiveDownloadItem(download_id); | 865 DownloadItem* download = GetActiveDownloadItem(download_id); |
874 if (!download) | 866 if (!download) |
875 return; | 867 return; |
876 VLOG(20) << __FUNCTION__ << "()" << " path = \"" << path.value() << "\"" | 868 VLOG(20) << __FUNCTION__ << "()" << " path = \"" << path.value() << "\"" |
877 << " download = " << download->DebugString(true); | 869 << " download = " << download->DebugString(true); |
878 | 870 |
879 if (download->PromptUserForSaveLocation()) | 871 if (download->PromptUserForSaveLocation()) |
880 last_download_path_ = path.DirName(); | 872 last_download_path_ = path.DirName(); |
881 | 873 |
882 // Make sure the initial file name is set only once. | 874 // Make sure the initial file name is set only once. |
883 ContinueDownloadWithPath(download, path); | 875 ContinueDownloadWithPath(download, path); |
884 } | 876 } |
885 | 877 |
886 void DownloadManagerImpl::FileSelectionCanceled(void* params) { | 878 void DownloadManagerImpl::FileSelectionCanceled(int32 download_id) { |
887 // The user didn't pick a place to save the file, so need to cancel the | 879 // The user didn't pick a place to save the file, so need to cancel the |
888 // download that's already in progress to the temporary location. | 880 // download that's already in progress to the temporary location. |
889 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 881 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
890 int32* id_ptr = reinterpret_cast<int32*>(params); | |
891 DCHECK(id_ptr != NULL); | |
892 int32 download_id = *id_ptr; | |
893 delete id_ptr; | |
894 | 882 |
895 DownloadItem* download = GetActiveDownloadItem(download_id); | 883 DownloadItem* download = GetActiveDownloadItem(download_id); |
896 if (!download) | 884 if (!download) |
897 return; | 885 return; |
898 | 886 |
899 VLOG(20) << __FUNCTION__ << "()" | 887 VLOG(20) << __FUNCTION__ << "()" |
900 << " download = " << download->DebugString(true); | 888 << " download = " << download->DebugString(true); |
901 | 889 |
902 download->Cancel(true); | 890 download->Cancel(true); |
903 } | 891 } |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1171 it != history_downloads_.end(); ++it) { | 1159 it != history_downloads_.end(); ++it) { |
1172 if (it->second->IsComplete() && !it->second->GetOpened()) | 1160 if (it->second->IsComplete() && !it->second->GetOpened()) |
1173 ++num_unopened; | 1161 ++num_unopened; |
1174 } | 1162 } |
1175 download_stats::RecordOpensOutstanding(num_unopened); | 1163 download_stats::RecordOpensOutstanding(num_unopened); |
1176 } | 1164 } |
1177 | 1165 |
1178 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) { | 1166 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) { |
1179 file_manager_ = file_manager; | 1167 file_manager_ = file_manager; |
1180 } | 1168 } |
OLD | NEW |