Chromium Code Reviews| 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 "chrome/browser/download/chrome_download_manager_delegate.h" | 5 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 } | 128 } |
| 129 | 129 |
| 130 DownloadId ChromeDownloadManagerDelegate::GetNextId() { | 130 DownloadId ChromeDownloadManagerDelegate::GetNextId() { |
| 131 if (!profile_->IsOffTheRecord()) | 131 if (!profile_->IsOffTheRecord()) |
| 132 return DownloadId(this, next_download_id_++); | 132 return DownloadId(this, next_download_id_++); |
| 133 | 133 |
| 134 return BrowserContext::GetDownloadManager(profile_->GetOriginalProfile())-> | 134 return BrowserContext::GetDownloadManager(profile_->GetOriginalProfile())-> |
| 135 GetDelegate()->GetNextId(); | 135 GetDelegate()->GetNextId(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 bool ChromeDownloadManagerDelegate::ShouldStartDownload(int32 download_id) { | 138 bool ChromeDownloadManagerDelegate::DetermineDownloadTarget( |
| 139 // We create a download item and store it in our download map, and inform the | 139 DownloadItem* download, |
| 140 // history system of a new download. Since this method can be called while the | 140 const content::DownloadTargetCallback& callback) { |
| 141 // history service thread is still reading the persistent state, we do not | |
| 142 // insert the new DownloadItem into 'history_downloads_' or inform our | |
| 143 // observers at this point. OnCreateDownloadEntryComplete() handles that | |
| 144 // finalization of the the download creation as a callback from the history | |
| 145 // thread. | |
| 146 DownloadItem* download = | |
| 147 download_manager_->GetActiveDownloadItem(download_id); | |
| 148 if (!download) | |
| 149 return false; | |
| 150 | |
| 151 #if defined(ENABLE_SAFE_BROWSING) | 141 #if defined(ENABLE_SAFE_BROWSING) |
| 152 DownloadProtectionService* service = GetDownloadProtectionService(); | 142 DownloadProtectionService* service = GetDownloadProtectionService(); |
| 153 if (service) { | 143 if (service) { |
| 154 VLOG(2) << __FUNCTION__ << "() Start SB URL check for download = " | 144 VLOG(2) << __FUNCTION__ << "() Start SB URL check for download = " |
| 155 << download->DebugString(false); | 145 << download->DebugString(false); |
| 156 service->CheckDownloadUrl( | 146 service->CheckDownloadUrl( |
| 157 DownloadProtectionService::DownloadInfo::FromDownloadItem(*download), | 147 DownloadProtectionService::DownloadInfo::FromDownloadItem(*download), |
| 158 base::Bind( | 148 base::Bind( |
| 159 &ChromeDownloadManagerDelegate::CheckDownloadUrlDone, | 149 &ChromeDownloadManagerDelegate::CheckDownloadUrlDone, |
| 160 this, | 150 this, |
| 161 download->GetId())); | 151 download->GetId(), |
| 162 return false; | 152 callback)); |
| 153 return true; | |
| 163 } | 154 } |
| 164 #endif | 155 #endif |
| 165 CheckDownloadUrlDone(download_id, DownloadProtectionService::SAFE); | 156 CheckDownloadUrlDone(download->GetId(), callback, |
| 166 return false; | 157 DownloadProtectionService::SAFE); |
| 158 return true; | |
| 167 } | 159 } |
| 168 | 160 |
| 169 void ChromeDownloadManagerDelegate::ChooseDownloadPath(DownloadItem* item) { | 161 void ChromeDownloadManagerDelegate::ChooseDownloadPath( |
| 162 DownloadItem* item, | |
| 163 const FilePath& suggested_path, | |
| 164 const base::Callback<void(const FilePath&)>& file_selected_callback) { | |
| 170 // Deletes itself. | 165 // Deletes itself. |
| 171 DownloadFilePicker* file_picker = | 166 DownloadFilePicker* file_picker = |
| 172 #if defined(OS_CHROMEOS) | 167 #if defined(OS_CHROMEOS) |
| 173 new DownloadFilePickerChromeOS(); | 168 new DownloadFilePickerChromeOS(); |
| 174 #else | 169 #else |
| 175 new DownloadFilePicker(); | 170 new DownloadFilePicker(); |
| 176 #endif | 171 #endif |
| 177 file_picker->Init(download_manager_, item); | 172 file_picker->Init(download_manager_, item, suggested_path, |
| 173 file_selected_callback); | |
| 178 } | 174 } |
| 179 | 175 |
| 180 FilePath ChromeDownloadManagerDelegate::GetIntermediatePath( | 176 FilePath ChromeDownloadManagerDelegate::GetIntermediatePath( |
| 181 const DownloadItem& download) { | 177 const FilePath& target_path, |
| 178 content::DownloadDangerType danger_type) { | |
| 182 // If the download is not dangerous, just append .crdownload to the target | 179 // If the download is not dangerous, just append .crdownload to the target |
| 183 // path. | 180 // path. |
| 184 if (download.GetDangerType() == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) | 181 if (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) |
| 185 return download_util::GetCrDownloadPath(download.GetTargetFilePath()); | 182 return download_util::GetCrDownloadPath(target_path); |
| 186 | 183 |
| 187 // If the download is potentially dangerous we create a filename of the form | 184 // If the download is potentially dangerous we create a filename of the form |
| 188 // 'Unconfirmed <random>.crdownload'. | 185 // 'Unconfirmed <random>.crdownload'. |
| 189 FilePath::StringType file_name; | 186 FilePath::StringType file_name; |
| 190 FilePath dir = download.GetTargetFilePath().DirName(); | 187 FilePath dir = target_path.DirName(); |
| 191 #if defined(OS_WIN) | 188 #if defined(OS_WIN) |
| 192 string16 unconfirmed_prefix = | 189 string16 unconfirmed_prefix = |
| 193 l10n_util::GetStringUTF16(IDS_DOWNLOAD_UNCONFIRMED_PREFIX); | 190 l10n_util::GetStringUTF16(IDS_DOWNLOAD_UNCONFIRMED_PREFIX); |
| 194 #else | 191 #else |
| 195 std::string unconfirmed_prefix = | 192 std::string unconfirmed_prefix = |
| 196 l10n_util::GetStringUTF8(IDS_DOWNLOAD_UNCONFIRMED_PREFIX); | 193 l10n_util::GetStringUTF8(IDS_DOWNLOAD_UNCONFIRMED_PREFIX); |
| 197 #endif | 194 #endif |
| 198 base::SStringPrintf( | 195 base::SStringPrintf( |
| 199 &file_name, | 196 &file_name, |
| 200 unconfirmed_prefix.append( | 197 unconfirmed_prefix.append( |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 const content::SavePackagePathPickedCallback& callback) { | 470 const content::SavePackagePathPickedCallback& callback) { |
| 474 // Deletes itself. | 471 // Deletes itself. |
| 475 #if defined(OS_CHROMEOS) | 472 #if defined(OS_CHROMEOS) |
| 476 new SavePackageFilePickerChromeOS(web_contents, suggested_path, callback); | 473 new SavePackageFilePickerChromeOS(web_contents, suggested_path, callback); |
| 477 #else | 474 #else |
| 478 new SavePackageFilePicker(web_contents, suggested_path, default_extension, | 475 new SavePackageFilePicker(web_contents, suggested_path, default_extension, |
| 479 can_save_as_complete, download_prefs_.get(), callback); | 476 can_save_as_complete, download_prefs_.get(), callback); |
| 480 #endif | 477 #endif |
| 481 } | 478 } |
| 482 | 479 |
| 480 void ChromeDownloadManagerDelegate::ClearLastDownloadPath() { | |
| 481 last_download_path_.clear(); | |
| 482 } | |
| 483 | |
| 483 DownloadProtectionService* | 484 DownloadProtectionService* |
| 484 ChromeDownloadManagerDelegate::GetDownloadProtectionService() { | 485 ChromeDownloadManagerDelegate::GetDownloadProtectionService() { |
| 485 #if defined(ENABLE_SAFE_BROWSING) | 486 #if defined(ENABLE_SAFE_BROWSING) |
| 486 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); | 487 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); |
| 487 if (sb_service && sb_service->download_protection_service() && | 488 if (sb_service && sb_service->download_protection_service() && |
| 488 profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) { | 489 profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) { |
| 489 return sb_service->download_protection_service(); | 490 return sb_service->download_protection_service(); |
| 490 } | 491 } |
| 491 #endif | 492 #endif |
| 492 return NULL; | 493 return NULL; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 return !download.HasUserGesture() || !visited_referrer_before; | 526 return !download.HasUserGesture() || !visited_referrer_before; |
| 526 | 527 |
| 527 return danger_level == download_util::Dangerous; | 528 return danger_level == download_util::Dangerous; |
| 528 } | 529 } |
| 529 | 530 |
| 530 void ChromeDownloadManagerDelegate::GetReservedPath( | 531 void ChromeDownloadManagerDelegate::GetReservedPath( |
| 531 DownloadItem& download, | 532 DownloadItem& download, |
| 532 const FilePath& target_path, | 533 const FilePath& target_path, |
| 533 const FilePath& default_download_path, | 534 const FilePath& default_download_path, |
| 534 bool should_uniquify_path, | 535 bool should_uniquify_path, |
| 535 const DownloadPathReservationTracker::ReservedPathCallback callback) { | 536 const DownloadPathReservationTracker::ReservedPathCallback& callback) { |
| 536 DownloadPathReservationTracker::GetReservedPath( | 537 DownloadPathReservationTracker::GetReservedPath( |
| 537 download, target_path, default_download_path, should_uniquify_path, | 538 download, target_path, default_download_path, should_uniquify_path, |
| 538 callback); | 539 callback); |
| 539 } | 540 } |
| 540 | 541 |
| 541 void ChromeDownloadManagerDelegate::CheckDownloadUrlDone( | 542 void ChromeDownloadManagerDelegate::CheckDownloadUrlDone( |
| 542 int32 download_id, | 543 int32 download_id, |
| 544 const content::DownloadTargetCallback& callback, | |
| 543 DownloadProtectionService::DownloadCheckResult result) { | 545 DownloadProtectionService::DownloadCheckResult result) { |
| 544 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 545 DownloadItem* download = | 547 DownloadItem* download = |
| 546 download_manager_->GetActiveDownloadItem(download_id); | 548 download_manager_->GetActiveDownloadItem(download_id); |
| 547 if (!download) | 549 if (!download) |
| 548 return; | 550 return; |
| 549 | 551 |
| 550 VLOG(2) << __FUNCTION__ << "() download = " << download->DebugString(false) | 552 VLOG(2) << __FUNCTION__ << "() download = " << download->DebugString(false) |
| 551 << " verdict = " << result; | 553 << " verdict = " << result; |
| 552 content::DownloadDangerType danger_type = download->GetDangerType(); | 554 content::DownloadDangerType danger_type = download->GetDangerType(); |
| 553 if (result != DownloadProtectionService::SAFE) | 555 if (result != DownloadProtectionService::SAFE) |
| 554 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL; | 556 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL; |
| 555 | 557 |
| 556 download_history_->CheckVisitedReferrerBefore( | 558 download_history_->CheckVisitedReferrerBefore( |
| 557 download_id, download->GetReferrerUrl(), | 559 download_id, download->GetReferrerUrl(), |
| 558 base::Bind(&ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone, | 560 base::Bind(&ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone, |
| 559 base::Unretained(this), download_id, danger_type)); | 561 base::Unretained(this), download_id, callback, danger_type)); |
| 560 } | 562 } |
| 561 | 563 |
| 562 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( | 564 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( |
| 563 int32 download_id, | 565 int32 download_id, |
| 564 DownloadProtectionService::DownloadCheckResult result) { | 566 DownloadProtectionService::DownloadCheckResult result) { |
| 565 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); | 567 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); |
| 566 if (!item) | 568 if (!item) |
| 567 return; | 569 return; |
| 568 | 570 |
| 569 VLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false) | 571 VLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 int download_id = crx_installers_[installer]; | 609 int download_id = crx_installers_[installer]; |
| 608 crx_installers_.erase(installer.get()); | 610 crx_installers_.erase(installer.get()); |
| 609 | 611 |
| 610 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); | 612 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); |
| 611 if (item) | 613 if (item) |
| 612 item->DelayedDownloadOpened(installer->did_handle_successfully()); | 614 item->DelayedDownloadOpened(installer->did_handle_successfully()); |
| 613 } | 615 } |
| 614 | 616 |
| 615 void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( | 617 void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( |
| 616 int32 download_id, | 618 int32 download_id, |
| 619 const content::DownloadTargetCallback& callback, | |
| 617 content::DownloadDangerType danger_type, | 620 content::DownloadDangerType danger_type, |
| 618 bool visited_referrer_before) { | 621 bool visited_referrer_before) { |
| 619 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 622 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 620 | 623 |
| 621 DownloadItem* download = | 624 DownloadItem* download = |
| 622 download_manager_->GetActiveDownloadItem(download_id); | 625 download_manager_->GetActiveDownloadItem(download_id); |
| 623 if (!download) | 626 if (!download) |
| 624 return; | 627 return; |
| 625 | 628 |
| 626 bool should_prompt = (download->GetTargetDisposition() == | 629 bool should_prompt = (download->GetTargetDisposition() == |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 648 !ShouldOpenFileBasedOnExtension(generated_name)) | 651 !ShouldOpenFileBasedOnExtension(generated_name)) |
| 649 should_prompt = true; | 652 should_prompt = true; |
| 650 } | 653 } |
| 651 if (download_prefs_->IsDownloadPathManaged()) | 654 if (download_prefs_->IsDownloadPathManaged()) |
| 652 should_prompt = false; | 655 should_prompt = false; |
| 653 | 656 |
| 654 // Determine the proper path for a download, by either one of the following: | 657 // Determine the proper path for a download, by either one of the following: |
| 655 // 1) using the default download directory. | 658 // 1) using the default download directory. |
| 656 // 2) prompting the user. | 659 // 2) prompting the user. |
| 657 FilePath target_directory; | 660 FilePath target_directory; |
| 658 if (should_prompt && !download_manager_->LastDownloadPath().empty()) | 661 if (should_prompt && !last_download_path_.empty()) |
| 659 target_directory = download_manager_->LastDownloadPath(); | 662 target_directory = last_download_path_; |
| 660 else | 663 else |
| 661 target_directory = download_prefs_->download_path(); | 664 target_directory = download_prefs_->download_path(); |
| 662 suggested_path = target_directory.Append(generated_name); | 665 suggested_path = target_directory.Append(generated_name); |
| 663 } else { | 666 } else { |
| 664 DCHECK(!should_prompt); | 667 DCHECK(!should_prompt); |
| 665 suggested_path = download->GetForcedFilePath(); | 668 suggested_path = download->GetForcedFilePath(); |
| 666 } | 669 } |
| 667 | 670 |
| 668 // If the download hasn't already been marked dangerous (could be | 671 // If the download hasn't already been marked dangerous (could be |
| 669 // DANGEROUS_URL), check if it is a dangerous file. | 672 // DANGEROUS_URL), check if it is a dangerous file. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 692 } else { | 695 } else { |
| 693 // Currently we only expect this case. | 696 // Currently we only expect this case. |
| 694 DCHECK_EQ(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, danger_type); | 697 DCHECK_EQ(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, danger_type); |
| 695 } | 698 } |
| 696 | 699 |
| 697 #if defined (OS_CHROMEOS) | 700 #if defined (OS_CHROMEOS) |
| 698 gdata::GDataDownloadObserver::SubstituteGDataDownloadPath( | 701 gdata::GDataDownloadObserver::SubstituteGDataDownloadPath( |
| 699 profile_, suggested_path, download, | 702 profile_, suggested_path, download, |
| 700 base::Bind( | 703 base::Bind( |
| 701 &ChromeDownloadManagerDelegate::SubstituteGDataDownloadPathCallback, | 704 &ChromeDownloadManagerDelegate::SubstituteGDataDownloadPathCallback, |
| 702 this, download->GetId(), should_prompt, is_forced_path, danger_type)); | 705 this, download->GetId(), callback, should_prompt, is_forced_path, |
| 706 danger_type)); | |
| 703 #else | 707 #else |
| 704 GetReservedPath( | 708 GetReservedPath( |
| 705 *download, suggested_path, download_prefs_->download_path(), | 709 *download, suggested_path, download_prefs_->download_path(), |
| 706 !is_forced_path, | 710 !is_forced_path, |
| 707 base::Bind(&ChromeDownloadManagerDelegate::OnPathReservationAvailable, | 711 base::Bind(&ChromeDownloadManagerDelegate::OnPathReservationAvailable, |
| 708 this, download->GetId(), should_prompt, danger_type)); | 712 this, download->GetId(), callback, should_prompt, |
| 713 danger_type)); | |
| 709 #endif | 714 #endif |
| 710 } | 715 } |
| 711 | 716 |
| 712 #if defined (OS_CHROMEOS) | 717 #if defined (OS_CHROMEOS) |
| 718 // TODO(asanka): Merge this logic with the logic in DownloadFilePickerChromeOS. | |
|
Randy Smith (Not in Mondays)
2012/07/12 17:01:22
Probably worth pulling Achuith into the review at
asanka
2012/07/18 21:50:56
Yeah. Hopefully we can get it down to a single GDa
| |
| 713 void ChromeDownloadManagerDelegate::SubstituteGDataDownloadPathCallback( | 719 void ChromeDownloadManagerDelegate::SubstituteGDataDownloadPathCallback( |
| 714 int32 download_id, | 720 int32 download_id, |
| 721 const content::DownloadTargetCallback& callback, | |
| 715 bool should_prompt, | 722 bool should_prompt, |
| 716 bool is_forced_path, | 723 bool is_forced_path, |
| 717 content::DownloadDangerType danger_type, | 724 content::DownloadDangerType danger_type, |
| 718 const FilePath& suggested_path) { | 725 const FilePath& suggested_path) { |
| 719 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 726 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 720 DownloadItem* download = | 727 DownloadItem* download = |
| 721 download_manager_->GetActiveDownloadItem(download_id); | 728 download_manager_->GetActiveDownloadItem(download_id); |
| 722 if (!download) | 729 if (!download) |
| 723 return; | 730 return; |
| 724 | 731 |
| 725 GetReservedPath( | 732 GetReservedPath( |
| 726 *download, suggested_path, download_prefs_->download_path(), | 733 *download, suggested_path, download_prefs_->download_path(), |
| 727 !is_forced_path, | 734 !is_forced_path, |
| 728 base::Bind(&ChromeDownloadManagerDelegate::OnPathReservationAvailable, | 735 base::Bind(&ChromeDownloadManagerDelegate::OnPathReservationAvailable, |
| 729 this, download->GetId(), should_prompt, danger_type)); | 736 this, download->GetId(), callback, should_prompt, |
| 737 danger_type)); | |
| 730 } | 738 } |
| 731 #endif | 739 #endif |
| 732 | 740 |
| 733 void ChromeDownloadManagerDelegate::OnPathReservationAvailable( | 741 void ChromeDownloadManagerDelegate::OnPathReservationAvailable( |
| 734 int32 download_id, | 742 int32 download_id, |
| 743 const content::DownloadTargetCallback& callback, | |
| 735 bool should_prompt, | 744 bool should_prompt, |
| 736 content::DownloadDangerType danger_type, | 745 content::DownloadDangerType danger_type, |
| 737 const FilePath& target_path, | 746 const FilePath& reserved_path, |
| 738 bool target_path_verified) { | 747 bool reserved_path_verified) { |
| 739 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 748 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 740 DownloadItem* download = | 749 DownloadItem* download = |
| 741 download_manager_->GetActiveDownloadItem(download_id); | 750 download_manager_->GetActiveDownloadItem(download_id); |
| 742 if (!download) | 751 if (!download) |
| 743 return; | 752 return; |
| 744 DownloadItem::TargetDisposition disposition; | 753 if (should_prompt || !reserved_path_verified) { |
| 745 // If the target path could not be verified then the path was non-existant, | 754 // If the target path could not be verified then the path was non-existant, |
| 746 // non writeable or could not be uniquified. Prompt the user. | 755 // non writeable or could not be uniquified. Prompt the user. |
| 747 if (should_prompt || !target_path_verified) | 756 ChooseDownloadPath( |
| 748 disposition = DownloadItem::TARGET_DISPOSITION_PROMPT; | 757 download, reserved_path, |
| 749 else | 758 base::Bind(&ChromeDownloadManagerDelegate::OnTargetPathDetermined, |
| 750 disposition = DownloadItem::TARGET_DISPOSITION_OVERWRITE; | 759 this, download_id, callback, |
| 751 download->OnTargetPathDetermined(target_path, disposition, danger_type); | 760 DownloadItem::TARGET_DISPOSITION_PROMPT, danger_type)); |
| 752 download_manager_->RestartDownload(download_id); | 761 } else { |
| 762 OnTargetPathDetermined(download_id, callback, | |
| 763 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 764 danger_type, reserved_path); | |
| 765 } | |
| 766 } | |
| 767 | |
| 768 void ChromeDownloadManagerDelegate::OnTargetPathDetermined( | |
| 769 int32 download_id, | |
| 770 const content::DownloadTargetCallback& callback, | |
| 771 DownloadItem::TargetDisposition disposition, | |
| 772 content::DownloadDangerType danger_type, | |
| 773 const FilePath& target_path) { | |
| 774 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 775 DownloadItem* download = | |
| 776 download_manager_->GetActiveDownloadItem(download_id); | |
| 777 if (!download) | |
| 778 return; | |
| 779 | |
| 780 // If |target_path| is empty, then that means that the user wants to cancel | |
| 781 // the download. | |
| 782 if (target_path.empty()) { | |
| 783 DCHECK_EQ(DownloadItem::TARGET_DISPOSITION_PROMPT, disposition); | |
| 784 download->Cancel(true); | |
| 785 return; | |
| 786 } | |
| 787 | |
| 788 // Retain the last directory. Exclude temporary downloads since the path | |
| 789 // likely points at the location of a temporary file. | |
| 790 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a | |
| 791 // directory to persist. Or perhaps, if the GData path | |
| 792 // substitution logic is moved here, then we would have a | |
| 793 // persistable path after the DownloadFilePicker is done. | |
|
Randy Smith (Not in Mondays)
2012/07/12 17:01:22
This is only for GData, right? It should go away
asanka
2012/07/18 21:50:56
Yeah. I didn't want to do it here since such a fix
| |
| 794 if (disposition == DownloadItem::TARGET_DISPOSITION_PROMPT && | |
| 795 !download->IsTemporary()) | |
| 796 last_download_path_ = target_path.DirName(); | |
| 797 | |
| 798 FilePath intermediate_path = GetIntermediatePath(target_path, danger_type); | |
| 799 callback.Run(target_path, disposition, danger_type, intermediate_path); | |
| 753 } | 800 } |
| 754 | 801 |
| 755 void ChromeDownloadManagerDelegate::OnItemAddedToPersistentStore( | 802 void ChromeDownloadManagerDelegate::OnItemAddedToPersistentStore( |
| 756 int32 download_id, int64 db_handle) { | 803 int32 download_id, int64 db_handle) { |
| 757 // It's not immediately obvious, but HistoryBackend::CreateDownload() can | 804 // It's not immediately obvious, but HistoryBackend::CreateDownload() can |
| 758 // call this function with an invalid |db_handle|. For instance, this can | 805 // call this function with an invalid |db_handle|. For instance, this can |
| 759 // happen when the history database is offline. We cannot have multiple | 806 // happen when the history database is offline. We cannot have multiple |
| 760 // DownloadItems with the same invalid db_handle, so we need to assign a | 807 // DownloadItems with the same invalid db_handle, so we need to assign a |
| 761 // unique |db_handle| here. | 808 // unique |db_handle| here. |
| 762 if (db_handle == DownloadItem::kUninitializedHandle) | 809 if (db_handle == DownloadItem::kUninitializedHandle) |
| 763 db_handle = download_history_->GetNextFakeDbHandle(); | 810 db_handle = download_history_->GetNextFakeDbHandle(); |
| 764 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); | 811 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); |
| 765 } | 812 } |
| OLD | NEW |