Commit 4dd107ee authored by Austin Tankiang's avatar Austin Tankiang Committed by Commit Bot

Remove drive path handling from download manager

With the change to DriveFS, drive paths no longer need to be special
cased, and can be treated as local paths.

Bug: 1003238
Change-Id: I6fb5851e08df7a967e328622b467aa9518d1f965
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1832958Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Austin Tankiang <austinct@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703578}
parent 0b5884d7
......@@ -94,11 +94,6 @@
#include "chrome/browser/ui/browser_finder.h"
#endif
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/drive/download_handler.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/browser/extensions/api/downloads/downloads_api.h"
#include "chrome/browser/extensions/crx_installer.h"
......@@ -161,24 +156,10 @@ enum PlatformDownloadPathType {
// Returns a path in the form that that is expected by platform_util::OpenItem /
// platform_util::ShowItemInFolder / DownloadTargetDeterminer.
//
// DownloadItems corresponding to Drive downloads use a temporary file as the
// target path. The paths returned by DownloadItem::GetFullPath() /
// GetTargetFilePath() refer to this temporary file. This function looks up the
// corresponding path in Drive for these downloads.
//
// How the platform path is determined is based on PlatformDownloadPathType.
base::FilePath GetPlatformDownloadPath(Profile* profile,
const DownloadItem* download,
PlatformDownloadPathType path_type) {
#if defined(OS_CHROMEOS)
// Drive downloads always return the target path for all types.
drive::DownloadHandler* drive_download_handler =
drive::DownloadHandler::GetForProfile(profile);
if (drive_download_handler &&
drive_download_handler->IsDriveDownload(download))
return drive_download_handler->GetTargetPath(download);
#endif
if (path_type == PLATFORM_TARGET_PATH)
return download->GetTargetFilePath();
return download->GetFullPath();
......@@ -624,15 +605,10 @@ bool ChromeDownloadManagerDelegate::InterceptDownloadIfApplicable(
void ChromeDownloadManagerDelegate::GetSaveDir(
content::BrowserContext* browser_context,
base::FilePath* website_save_dir,
base::FilePath* download_save_dir,
bool* skip_dir_check) {
base::FilePath* download_save_dir) {
*website_save_dir = download_prefs_->SaveFilePath();
DCHECK(!website_save_dir->empty());
*download_save_dir = download_prefs_->DownloadPath();
*skip_dir_check = false;
#if defined(OS_CHROMEOS)
*skip_dir_check = drive::util::IsUnderDriveMountPoint(*website_save_dir);
#endif
}
void ChromeDownloadManagerDelegate::ChooseSavePath(
......@@ -775,16 +751,6 @@ void ContinueCheckingForFileExistence(
void ChromeDownloadManagerDelegate::CheckForFileExistence(
DownloadItem* download,
content::CheckForFileExistenceCallback callback) {
#if defined(OS_CHROMEOS)
drive::DownloadHandler* drive_download_handler =
drive::DownloadHandler::GetForProfile(profile_);
if (drive_download_handler &&
drive_download_handler->IsDriveDownload(download)) {
drive_download_handler->CheckForFileExistence(download,
std::move(callback));
return;
}
#endif
base::PostTaskAndReplyWithResult(
disk_access_task_runner_.get(), FROM_HERE,
base::BindOnce(&base::PathExists, download->GetTargetFilePath()),
......@@ -850,12 +816,7 @@ void ChromeDownloadManagerDelegate::ReserveVirtualPath(
const DownloadTargetDeterminerDelegate::ReservedPathCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!virtual_path.empty());
#if defined(OS_CHROMEOS)
if (drive::util::IsUnderDriveMountPoint(virtual_path)) {
callback.Run(PathValidationResult::SUCCESS, virtual_path);
return;
}
#endif
base::FilePath document_dir;
base::PathService::Get(chrome::DIR_USER_DOCUMENTS, &document_dir);
DownloadPathReservationTracker::GetReservedPath(
......@@ -1095,15 +1056,6 @@ void ChromeDownloadManagerDelegate::DetermineLocalPath(
const base::FilePath& virtual_path,
const DownloadTargetDeterminerDelegate::LocalPathCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
#if defined(OS_CHROMEOS)
drive::DownloadHandler* drive_download_handler =
drive::DownloadHandler::GetForProfile(profile_);
if (drive_download_handler) {
drive_download_handler->SubstituteDriveDownloadPath(
virtual_path, download, callback);
return;
}
#endif
callback.Run(virtual_path);
}
......
......@@ -101,8 +101,7 @@ class ChromeDownloadManagerDelegate
content::WebContents* web_contents) override;
void GetSaveDir(content::BrowserContext* browser_context,
base::FilePath* website_save_dir,
base::FilePath* download_save_dir,
bool* skip_dir_check) override;
base::FilePath* download_save_dir) override;
void ChooseSavePath(
content::WebContents* web_contents,
const base::FilePath& suggested_path,
......
......@@ -25,7 +25,6 @@
#include "url/gurl.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/drive/download_handler.h"
#include "content/public/browser/download_item_utils.h"
#endif
......@@ -48,16 +47,6 @@ void DragDownloadItem(const download::DownloadItem* download,
*views::Widget::GetTopLevelWidgetForNativeView(view), data.get());
base::FilePath full_path = download->GetTargetFilePath();
#if defined(OS_CHROMEOS)
// Overwrite |full_path| with drive cache file path when appropriate.
Profile* profile = Profile::FromBrowserContext(
content::DownloadItemUtils::GetBrowserContext(download));
drive::DownloadHandler* drive_download_handler =
drive::DownloadHandler::GetForProfile(profile);
if (drive_download_handler &&
drive_download_handler->IsDriveDownload(download))
full_path = drive_download_handler->GetCacheFilePath(download);
#endif
std::vector<ui::FileInfo> file_infos;
file_infos.push_back(
ui::FileInfo(full_path, download->GetFileNameToReportUser()));
......
......@@ -32,11 +32,6 @@
#include "content/public/browser/web_contents.h"
#include "ui/base/l10n/l10n_util.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/drive/download_handler.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
#endif
using content::RenderProcessHost;
using content::SavePageType;
using content::WebContents;
......@@ -51,29 +46,6 @@ void OnSavePackageDownloadCreated(download::DownloadItem* download) {
ChromeDownloadManagerDelegate::DisableSafeBrowsing(download);
}
#if defined(OS_CHROMEOS)
void OnSavePackageDownloadCreatedChromeOS(Profile* profile,
const base::FilePath& drive_path,
download::DownloadItem* download) {
drive::DownloadHandler::GetForProfile(profile)->SetDownloadParams(
drive_path, download);
OnSavePackageDownloadCreated(download);
}
// Trampoline callback between SubstituteDriveDownloadPath() and |callback|.
void ContinueSettingUpDriveDownload(
const content::SavePackagePathPickedCallback& callback,
content::SavePageType save_type,
Profile* profile,
const base::FilePath& drive_path,
const base::FilePath& drive_tmp_download_path) {
if (drive_tmp_download_path.empty()) // Substitution failed.
return;
callback.Run(drive_tmp_download_path, save_type, base::Bind(
&OnSavePackageDownloadCreatedChromeOS, profile, drive_path));
}
#endif
// Adds "Webpage, HTML Only" type to FileTypeInfo.
void AddHtmlOnlyFileTypeInfo(
ui::SelectFileDialog::FileTypeInfo* file_type_info,
......@@ -291,27 +263,6 @@ void SavePackageFilePicker::FileSelected(
download_prefs_->SetSaveFilePath(path_copy.DirName());
#if defined(OS_CHROMEOS)
if (drive::util::IsUnderDriveMountPoint(path_copy)) {
// Here's a map to the callback chain:
// SubstituteDriveDownloadPath ->
// ContinueSettingUpDriveDownload ->
// callback_ = SavePackage::OnPathPicked ->
// download_created_callback = OnSavePackageDownloadCreatedChromeOS
Profile* profile = Profile::FromBrowserContext(
process->GetBrowserContext());
drive::DownloadHandler* drive_download_handler =
drive::DownloadHandler::GetForProfile(profile);
drive_download_handler->SubstituteDriveDownloadPath(
path_copy, NULL, base::Bind(&ContinueSettingUpDriveDownload,
callback_,
save_type,
profile,
path_copy));
return;
}
#endif
callback_.Run(path_copy, save_type,
base::Bind(&OnSavePackageDownloadCreated));
}
......
......@@ -527,9 +527,8 @@ base::FilePath DownloadManagerImpl::GetDefaultDownloadDirectory() {
#else
if (delegate_) {
base::FilePath website_save_directory; // Unused
bool skip_dir_check = false; // Unused
delegate_->GetSaveDir(GetBrowserContext(), &website_save_directory,
&default_download_directory, &skip_dir_check);
&default_download_directory);
}
#endif
if (default_download_directory.empty()) {
......
......@@ -91,8 +91,8 @@ class MockDownloadManagerDelegate : public DownloadManagerDelegate {
MOCK_METHOD2(ShouldOpenDownload,
bool(download::DownloadItem*,
const DownloadOpenDelayedCallback&));
MOCK_METHOD4(GetSaveDir, void(BrowserContext*,
base::FilePath*, base::FilePath*, bool*));
MOCK_METHOD3(GetSaveDir,
void(BrowserContext*, base::FilePath*, base::FilePath*));
MOCK_METHOD5(ChooseSavePath, void(
WebContents*, const base::FilePath&, const base::FilePath::StringType&,
bool, const SavePackagePathPickedCallback&));
......@@ -599,7 +599,7 @@ TEST_F(DownloadManagerTest, StartDownload) {
#if !defined(USE_X11)
// Doing nothing will set the default download directory to null.
EXPECT_CALL(GetMockDownloadManagerDelegate(), GetSaveDir(_, _, _, _));
EXPECT_CALL(GetMockDownloadManagerDelegate(), GetSaveDir(_, _, _));
#endif
EXPECT_CALL(GetMockDownloadManagerDelegate(),
ApplicationClientIdForFileScanning())
......@@ -635,7 +635,7 @@ TEST_F(DownloadManagerTest, StartDownloadWithoutHistoryDB) {
#if !defined(USE_X11)
// Doing nothing will set the default download directory to null.
EXPECT_CALL(GetMockDownloadManagerDelegate(), GetSaveDir(_, _, _, _));
EXPECT_CALL(GetMockDownloadManagerDelegate(), GetSaveDir(_, _, _));
#endif
EXPECT_CALL(GetMockDownloadManagerDelegate(),
ApplicationClientIdForFileScanning())
......
......@@ -1240,12 +1240,10 @@ void SavePackage::GetSaveInfo() {
// need before calling to it.
base::FilePath website_save_dir;
base::FilePath download_save_dir;
bool skip_dir_check = false;
auto* delegate = download_manager_->GetDelegate();
if (delegate) {
delegate->GetSaveDir(
web_contents()->GetBrowserContext(), &website_save_dir,
&download_save_dir, &skip_dir_check);
delegate->GetSaveDir(web_contents()->GetBrowserContext(), &website_save_dir,
&download_save_dir);
}
std::string mime_type = web_contents()->GetContentsMimeType();
bool can_save_as_complete = CanSaveAsComplete(mime_type);
......@@ -1253,7 +1251,7 @@ void SavePackage::GetSaveInfo() {
download::GetDownloadTaskRunner().get(), FROM_HERE,
base::Bind(&SavePackage::CreateDirectoryOnFileThread, title_, page_url_,
can_save_as_complete, mime_type, website_save_dir,
download_save_dir, skip_dir_check),
download_save_dir),
base::Bind(&SavePackage::ContinueGetSaveInfo, this,
can_save_as_complete));
}
......@@ -1265,8 +1263,7 @@ base::FilePath SavePackage::CreateDirectoryOnFileThread(
bool can_save_as_complete,
const std::string& mime_type,
const base::FilePath& website_save_dir,
const base::FilePath& download_save_dir,
bool skip_dir_check) {
const base::FilePath& download_save_dir) {
DCHECK(download::GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
base::FilePath suggested_filename = filename_generation::GenerateFilename(
......@@ -1274,8 +1271,7 @@ base::FilePath SavePackage::CreateDirectoryOnFileThread(
base::FilePath save_dir;
// If the default html/websites save folder doesn't exist...
// We skip the directory check for gdata directories on ChromeOS.
if (!skip_dir_check && !base::DirectoryExists(website_save_dir)) {
if (!base::DirectoryExists(website_save_dir)) {
// If the default download dir doesn't exist, create it.
if (!base::DirectoryExists(download_save_dir)) {
bool res = base::CreateDirectory(download_save_dir);
......
......@@ -305,8 +305,7 @@ class CONTENT_EXPORT SavePackage
bool can_save_as_complete,
const std::string& mime_type,
const base::FilePath& website_save_dir,
const base::FilePath& download_save_dir,
bool skip_dir_check);
const base::FilePath& download_save_dir);
void ContinueGetSaveInfo(bool can_save_as_complete,
const base::FilePath& suggested_path);
void OnPathPicked(
......
......@@ -38,11 +38,9 @@ class TestShellDownloadManagerDelegate : public ShellDownloadManagerDelegate {
void GetSaveDir(BrowserContext* context,
base::FilePath* website_save_dir,
base::FilePath* download_save_dir,
bool* skip_dir_check) override {
base::FilePath* download_save_dir) override {
*website_save_dir = download_dir_;
*download_save_dir = download_dir_;
*skip_dir_check = false;
}
bool ShouldCompleteDownload(download::DownloadItem* download,
......
......@@ -138,8 +138,7 @@ class CONTENT_EXPORT DownloadManagerDelegate {
// Retrieve the directories to save html pages and downloads to.
virtual void GetSaveDir(BrowserContext* browser_context,
base::FilePath* website_save_dir,
base::FilePath* download_save_dir,
bool* skip_dir_check) {}
base::FilePath* download_save_dir) {}
// Asks the user for the path to save a page. The delegate calls the callback
// to give the answer.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment