Commit df8926bb authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview: Do not create non default directories for Save as PDF

Bug: 807746
Change-Id: I21b5add06d217835de3f8f1d2b9cf98df7d92416
Reviewed-on: https://chromium-review.googlesource.com/905336
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#535126}
parent aa63fc1d
......@@ -134,9 +134,13 @@ base::FilePath GetUniquePath(const base::FilePath& path) {
return unique_path;
}
void CreateDirectoryIfNeeded(const base::FilePath& path) {
if (!base::DirectoryExists(path))
base::CreateDirectory(path);
base::FilePath SelectSaveDirectory(const base::FilePath& path,
const base::FilePath& default_path) {
if (base::DirectoryExists(path))
return path;
if (!base::DirectoryExists(default_path))
base::CreateDirectory(default_path);
return default_path;
}
} // namespace
......@@ -330,19 +334,21 @@ void PdfPrinterHandler::SelectFile(const base::FilePath& default_filename,
return;
}
// If the directory is empty there is no reason to create it.
// If the directory is empty there is no reason to create it or use the
// default location.
if (path.empty()) {
OnDirectoryCreated(default_filename);
OnDirectorySelected(default_filename, path);
return;
}
// Create the directory to save in if it does not exist.
base::PostTaskWithTraitsAndReply(
// Get default download directory. This will be used as a fallback if the
// save directory does not exist.
base::FilePath default_path = download_prefs->DownloadPath();
base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND},
base::Bind(&CreateDirectoryIfNeeded, path),
base::Bind(&PdfPrinterHandler::OnDirectoryCreated,
weak_ptr_factory_.GetWeakPtr(),
path.Append(default_filename)));
base::BindOnce(&SelectSaveDirectory, path, default_path),
base::BindOnce(&PdfPrinterHandler::OnDirectorySelected,
weak_ptr_factory_.GetWeakPtr(), default_filename));
}
void PdfPrinterHandler::PostPrintToPdfTask() {
......@@ -358,7 +364,10 @@ void PdfPrinterHandler::OnGotUniqueFileName(const base::FilePath& path) {
FileSelected(path, 0, nullptr);
}
void PdfPrinterHandler::OnDirectoryCreated(const base::FilePath& path) {
void PdfPrinterHandler::OnDirectorySelected(const base::FilePath& filename,
const base::FilePath& directory) {
base::FilePath path = directory.Append(filename);
// Prompts the user to select the file.
ui::SelectFileDialog::FileTypeInfo file_type_info;
file_type_info.extensions.resize(1);
......
......@@ -90,7 +90,11 @@ class PdfPrinterHandler : public PrinterHandler,
private:
void PostPrintToPdfTask();
void OnGotUniqueFileName(const base::FilePath& path);
void OnDirectoryCreated(const base::FilePath& path);
// Prompts the user to save the file. The dialog will default to saving
// the file with name |filename| in |directory|.
void OnDirectorySelected(const base::FilePath& filename,
const base::FilePath& directory);
Profile* const profile_;
printing::StickySettings* const sticky_settings_;
......
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