| Index: chrome/browser/download/chrome_download_manager_delegate.cc
|
| diff --git a/chrome/browser/download/chrome_download_manager_delegate.cc b/chrome/browser/download/chrome_download_manager_delegate.cc
|
| index f7342c81dbe2d6d4159aac1575dc3de5026e482f..880a02450d8c65fe77392065fabee7b2a7d5c83c 100644
|
| --- a/chrome/browser/download/chrome_download_manager_delegate.cc
|
| +++ b/chrome/browser/download/chrome_download_manager_delegate.cc
|
| @@ -58,10 +58,8 @@
|
| #include "chrome/browser/chromeos/drive/download_handler.h"
|
| #include "chrome/browser/chromeos/drive/file_system_util.h"
|
| #include "chrome/browser/download/download_file_picker_chromeos.h"
|
| -#include "chrome/browser/download/save_package_file_picker_chromeos.h"
|
| #endif
|
|
|
| -using content::BrowserContext;
|
| using content::BrowserThread;
|
| using content::DownloadId;
|
| using content::DownloadItem;
|
| @@ -183,16 +181,6 @@ base::FilePath GetPlatformDownloadPath(Profile* profile,
|
|
|
| } // namespace
|
|
|
| -// static
|
| -void ChromeDownloadManagerDelegate::RegisterUserPrefs(
|
| - PrefRegistrySyncable* registry) {
|
| - const base::FilePath& default_download_path =
|
| - download_util::GetDefaultDownloadDirectory();
|
| - registry->RegisterFilePathPref(prefs::kSaveFileDefaultDirectory,
|
| - default_download_path,
|
| - PrefRegistrySyncable::UNSYNCABLE_PREF);
|
| -}
|
| -
|
| ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile)
|
| : profile_(profile),
|
| next_download_id_(0),
|
| @@ -214,8 +202,8 @@ DownloadId ChromeDownloadManagerDelegate::GetNextId() {
|
| if (!profile_->IsOffTheRecord())
|
| return DownloadId(this, next_download_id_++);
|
|
|
| - return BrowserContext::GetDownloadManager(profile_->GetOriginalProfile())->
|
| - GetDelegate()->GetNextId();
|
| + return content::BrowserContext::GetDownloadManager(
|
| + profile_->GetOriginalProfile())->GetDelegate()->GetNextId();
|
| }
|
|
|
| bool ChromeDownloadManagerDelegate::DetermineDownloadTarget(
|
| @@ -368,28 +356,15 @@ bool ChromeDownloadManagerDelegate::GenerateFileHash() {
|
| }
|
|
|
| void ChromeDownloadManagerDelegate::GetSaveDir(
|
| - BrowserContext* browser_context,
|
| + content::BrowserContext* browser_context,
|
| base::FilePath* website_save_dir,
|
| base::FilePath* download_save_dir,
|
| bool* skip_dir_check) {
|
| Profile* profile = Profile::FromBrowserContext(browser_context);
|
| PrefService* prefs = profile->GetPrefs();
|
|
|
| - // Check whether the preference for the preferred directory for
|
| - // saving file has been explicitly set. If not, and the preference
|
| - // for the default download directory has been set, initialize it
|
| - // with the latter. Note that the defaults for both are the same.
|
| - const PrefService::Preference* download_default_directory =
|
| - prefs->FindPreference(prefs::kDownloadDefaultDirectory);
|
| - if (!download_default_directory->IsDefaultValue() &&
|
| - prefs->FindPreference(
|
| - prefs::kSaveFileDefaultDirectory)->IsDefaultValue()) {
|
| - prefs->Set(prefs::kSaveFileDefaultDirectory,
|
| - *(download_default_directory->GetValue()));
|
| - }
|
| -
|
| // Get the directory from preference.
|
| - *website_save_dir = prefs->GetFilePath(prefs::kSaveFileDefaultDirectory);
|
| + *website_save_dir = download_prefs_->SaveFilePath();
|
| DCHECK(!website_save_dir->empty());
|
|
|
| *download_save_dir = prefs->GetFilePath(prefs::kDownloadDefaultDirectory);
|
| @@ -407,13 +382,6 @@ void ChromeDownloadManagerDelegate::ChooseSavePath(
|
| bool can_save_as_complete,
|
| const content::SavePackagePathPickedCallback& callback) {
|
| // Deletes itself.
|
| -#if defined(OS_CHROMEOS)
|
| - new SavePackageFilePickerChromeOS(
|
| - web_contents,
|
| - suggested_path,
|
| - can_save_as_complete,
|
| - callback);
|
| -#else
|
| new SavePackageFilePicker(
|
| web_contents,
|
| suggested_path,
|
| @@ -421,7 +389,6 @@ void ChromeDownloadManagerDelegate::ChooseSavePath(
|
| can_save_as_complete,
|
| download_prefs_.get(),
|
| callback);
|
| -#endif
|
| }
|
|
|
| void ChromeDownloadManagerDelegate::OpenDownload(DownloadItem* download) {
|
| @@ -451,10 +418,6 @@ void ChromeDownloadManagerDelegate::CheckForFileExistence(
|
| callback);
|
| }
|
|
|
| -void ChromeDownloadManagerDelegate::ClearLastDownloadPath() {
|
| - last_download_path_.clear();
|
| -}
|
| -
|
| DownloadProtectionService*
|
| ChromeDownloadManagerDelegate::GetDownloadProtectionService() {
|
| #if defined(FULL_SAFE_BROWSING)
|
| @@ -635,8 +598,7 @@ void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone(
|
| bool visited_referrer_before) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
|
|
| - DownloadItem* download =
|
| - download_manager_->GetDownload(download_id);
|
| + DownloadItem* download = download_manager_->GetDownload(download_id);
|
| if (!download || (download->GetState() != DownloadItem::IN_PROGRESS))
|
| return;
|
|
|
| @@ -674,11 +636,8 @@ void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone(
|
| // Determine the proper path for a download, by either one of the following:
|
| // 1) using the default download directory.
|
| // 2) prompting the user.
|
| - base::FilePath target_directory;
|
| - if (should_prompt && !last_download_path_.empty())
|
| - target_directory = last_download_path_;
|
| - else
|
| - target_directory = download_prefs_->DownloadPath();
|
| + base::FilePath target_directory = should_prompt ?
|
| + download_prefs_->SaveFilePath() : download_prefs_->DownloadPath();
|
| suggested_path = target_directory.Append(generated_name);
|
| } else {
|
| DCHECK(!should_prompt);
|
| @@ -723,8 +682,8 @@ void ChromeDownloadManagerDelegate::OnExtensionOverridingFilename(
|
| const base::FilePath& changed_filename,
|
| DownloadPathReservationTracker::FilenameConflictAction conflict_action) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - DownloadItem* download =
|
| - download_manager_->GetDownload(continue_info.download_id);
|
| + DownloadItem* download = download_manager_->GetDownload(
|
| + continue_info.download_id);
|
| if (!download || (download->GetState() != DownloadItem::IN_PROGRESS))
|
| return;
|
|
|
| @@ -755,8 +714,7 @@ void ChromeDownloadManagerDelegate::ContinueDeterminingFilename(
|
| content::DownloadDangerType danger_type = continue_info.danger_type;
|
| bool visited_referrer_before = continue_info.visited_referrer_before;
|
| bool should_prompt = continue_info.should_prompt;
|
| - DownloadItem* download =
|
| - download_manager_->GetDownload(download_id);
|
| + DownloadItem* download = download_manager_->GetDownload(download_id);
|
| if (!download || (download->GetState() != DownloadItem::IN_PROGRESS))
|
| return;
|
|
|
| @@ -818,8 +776,7 @@ void ChromeDownloadManagerDelegate::SubstituteDriveDownloadPathCallback(
|
| content::DownloadDangerType danger_type,
|
| const base::FilePath& suggested_path) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - DownloadItem* download =
|
| - download_manager_->GetDownload(download_id);
|
| + DownloadItem* download = download_manager_->GetDownload(download_id);
|
| if (!download || (download->GetState() != DownloadItem::IN_PROGRESS))
|
| return;
|
|
|
| @@ -849,8 +806,7 @@ void ChromeDownloadManagerDelegate::OnPathReservationAvailable(
|
| const base::FilePath& reserved_path,
|
| bool reserved_path_verified) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - DownloadItem* download =
|
| - download_manager_->GetDownload(download_id);
|
| + DownloadItem* download = download_manager_->GetDownload(download_id);
|
| if (!download || (download->GetState() != DownloadItem::IN_PROGRESS))
|
| return;
|
| if (should_prompt || !reserved_path_verified) {
|
| @@ -876,8 +832,7 @@ void ChromeDownloadManagerDelegate::OnTargetPathDetermined(
|
| const base::FilePath& target_path) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| base::FilePath intermediate_path;
|
| - DownloadItem* download =
|
| - download_manager_->GetDownload(download_id);
|
| + DownloadItem* download = download_manager_->GetDownload(download_id);
|
| if (!download || (download->GetState() != DownloadItem::IN_PROGRESS))
|
| return;
|
|
|
| @@ -886,16 +841,17 @@ void ChromeDownloadManagerDelegate::OnTargetPathDetermined(
|
| if (!target_path.empty()) {
|
| intermediate_path = GetIntermediatePath(
|
| target_path, danger_type, !download->GetForcedFilePath().empty());
|
| -
|
| - // Retain the last directory. Exclude temporary downloads since the path
|
| - // likely points at the location of a temporary file.
|
| - // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a
|
| - // directory to persist. Or perhaps, if the Drive path
|
| - // substitution logic is moved here, then we would have a
|
| - // persistable path after the DownloadFilePicker is done.
|
| - if (disposition == DownloadItem::TARGET_DISPOSITION_PROMPT &&
|
| - !download->IsTemporary())
|
| - last_download_path_ = target_path.DirName();
|
| + if (!profile_->IsOffTheRecord()) {
|
| + base::FilePath target_dir = target_path.DirName();
|
| +#if defined(OS_CHROMEOS)
|
| + drive::DownloadHandler* drive_handler =
|
| + drive::DownloadHandler::GetForProfile(profile_);
|
| + if (drive_handler->IsDriveDownload(download)) {
|
| + target_dir = drive_handler->GetTargetPath(download);
|
| + }
|
| +#endif
|
| + download_prefs_->SetSaveFilePath(target_dir);
|
| + }
|
| }
|
| callback.Run(target_path, disposition, danger_type, intermediate_path);
|
| }
|
|
|