| 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/download_file_picker_chromeos.h" | 5 #include "chrome/browser/download/download_file_picker_chromeos.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/i18n/file_util_icu.h" | 8 #include "base/i18n/file_util_icu.h" |
| 9 #include "chrome/browser/chromeos/drive/drive_download_handler.h" | 9 #include "chrome/browser/chromeos/drive/drive_download_handler.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "content/public/browser/download_item.h" | 11 #include "content/public/browser/download_item.h" |
| 12 #include "content/public/browser/download_manager.h" | 12 #include "content/public/browser/download_manager.h" |
| 13 #include "ui/shell_dialogs/selected_file_info.h" | 13 #include "ui/shell_dialogs/selected_file_info.h" |
| 14 | 14 |
| 15 using content::DownloadItem; | 15 using content::DownloadItem; |
| 16 using content::DownloadManager; | 16 using content::DownloadManager; |
| 17 | 17 |
| 18 DownloadFilePickerChromeOS::DownloadFilePickerChromeOS() { | 18 DownloadFilePickerChromeOS::DownloadFilePickerChromeOS( |
| 19 DownloadItem* item, |
| 20 const base::FilePath& suggested_path, |
| 21 const FileSelectedCallback& callback) |
| 22 : DownloadFilePicker(item, suggested_path, callback) { |
| 19 } | 23 } |
| 20 | 24 |
| 21 DownloadFilePickerChromeOS::~DownloadFilePickerChromeOS() { | 25 DownloadFilePickerChromeOS::~DownloadFilePickerChromeOS() { |
| 22 } | 26 } |
| 23 | 27 |
| 24 void DownloadFilePickerChromeOS::InitSuggestedPath(DownloadItem* item, | 28 void DownloadFilePickerChromeOS::InitSuggestedPath(DownloadItem* item, |
| 25 const base::FilePath& path) { | 29 const base::FilePath& path) { |
| 26 // For Drive downloads, we should pass the drive path instead of the temporary | 30 // For Drive downloads, we should pass the drive path instead of the temporary |
| 27 // file path. | 31 // file path. |
| 28 Profile* profile = | 32 Profile* profile = |
| (...skipping 21 matching lines...) Expand all Loading... |
| 50 const ui::SelectedFileInfo& file_info, | 54 const ui::SelectedFileInfo& file_info, |
| 51 int index, | 55 int index, |
| 52 void* params) { | 56 void* params) { |
| 53 base::FilePath path = file_info.file_path; | 57 base::FilePath path = file_info.file_path; |
| 54 file_util::NormalizeFileNameEncoding(&path); | 58 file_util::NormalizeFileNameEncoding(&path); |
| 55 | 59 |
| 56 // Need to do this before we substitute with a temporary path. Otherwise we | 60 // Need to do this before we substitute with a temporary path. Otherwise we |
| 57 // won't be able to detect path changes. | 61 // won't be able to detect path changes. |
| 58 RecordFileSelected(path); | 62 RecordFileSelected(path); |
| 59 | 63 |
| 64 // TODO(asanka): Eliminate this substitution and rely on the local path |
| 65 // determination in DownloadTargetDeterminer. |
| 60 if (download_manager_) { | 66 if (download_manager_) { |
| 61 Profile* profile = | 67 Profile* profile = |
| 62 Profile::FromBrowserContext(download_manager_->GetBrowserContext()); | 68 Profile::FromBrowserContext(download_manager_->GetBrowserContext()); |
| 63 drive::DriveDownloadHandler* drive_download_handler = | 69 drive::DriveDownloadHandler* drive_download_handler = |
| 64 drive::DriveDownloadHandler::GetForProfile(profile); | 70 drive::DriveDownloadHandler::GetForProfile(profile); |
| 65 if (drive_download_handler) { | 71 if (drive_download_handler) { |
| 66 DownloadItem* download = download_manager_->GetDownload(download_id_); | 72 DownloadItem* download = download_manager_->GetDownload(download_id_); |
| 67 drive_download_handler->SubstituteDriveDownloadPath( | 73 drive_download_handler->SubstituteDriveDownloadPath( |
| 68 path, download, | 74 path, download, |
| 69 base::Bind(&DownloadFilePickerChromeOS::OnFileSelected, | 75 base::Bind(&DownloadFilePickerChromeOS::OnFileSelected, |
| 70 base::Unretained(this))); | 76 base::Unretained(this), path)); |
| 71 } else { | 77 } else { |
| 72 OnFileSelected(path); | 78 OnFileSelected(path, path); |
| 73 } | 79 } |
| 74 } else { | 80 } else { |
| 75 OnFileSelected(base::FilePath()); | 81 OnFileSelected(baes::FilePath(), base::FilePath()); |
| 76 } | 82 } |
| 77 // The OnFileSelected() call deletes |this| | 83 // The OnFileSelected() call deletes |this| |
| 78 } | 84 } |
| 85 |
| 86 // static |
| 87 void DownloadFilePicker::ShowFilePicker(DownloadItem* item, |
| 88 const base::FilePath& suggested_path, |
| 89 const FileSelectedCallback& callback) { |
| 90 new DownloadFilePickerChromeOS(item, suggested_path, callback); |
| 91 // DownloadFilePickerChromeOS deletes itself. |
| 92 } |
| OLD | NEW |