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) { ...@@ -134,9 +134,13 @@ base::FilePath GetUniquePath(const base::FilePath& path) {
return unique_path; return unique_path;
} }
void CreateDirectoryIfNeeded(const base::FilePath& path) { base::FilePath SelectSaveDirectory(const base::FilePath& path,
if (!base::DirectoryExists(path)) const base::FilePath& default_path) {
base::CreateDirectory(path); if (base::DirectoryExists(path))
return path;
if (!base::DirectoryExists(default_path))
base::CreateDirectory(default_path);
return default_path;
} }
} // namespace } // namespace
...@@ -330,19 +334,21 @@ void PdfPrinterHandler::SelectFile(const base::FilePath& default_filename, ...@@ -330,19 +334,21 @@ void PdfPrinterHandler::SelectFile(const base::FilePath& default_filename,
return; 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()) { if (path.empty()) {
OnDirectoryCreated(default_filename); OnDirectorySelected(default_filename, path);
return; return;
} }
// Create the directory to save in if it does not exist. // Get default download directory. This will be used as a fallback if the
base::PostTaskWithTraitsAndReply( // save directory does not exist.
base::FilePath default_path = download_prefs->DownloadPath();
base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND},
base::Bind(&CreateDirectoryIfNeeded, path), base::BindOnce(&SelectSaveDirectory, path, default_path),
base::Bind(&PdfPrinterHandler::OnDirectoryCreated, base::BindOnce(&PdfPrinterHandler::OnDirectorySelected,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(), default_filename));
path.Append(default_filename)));
} }
void PdfPrinterHandler::PostPrintToPdfTask() { void PdfPrinterHandler::PostPrintToPdfTask() {
...@@ -358,7 +364,10 @@ void PdfPrinterHandler::OnGotUniqueFileName(const base::FilePath& path) { ...@@ -358,7 +364,10 @@ void PdfPrinterHandler::OnGotUniqueFileName(const base::FilePath& path) {
FileSelected(path, 0, nullptr); 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. // Prompts the user to select the file.
ui::SelectFileDialog::FileTypeInfo file_type_info; ui::SelectFileDialog::FileTypeInfo file_type_info;
file_type_info.extensions.resize(1); file_type_info.extensions.resize(1);
......
...@@ -90,7 +90,11 @@ class PdfPrinterHandler : public PrinterHandler, ...@@ -90,7 +90,11 @@ class PdfPrinterHandler : public PrinterHandler,
private: private:
void PostPrintToPdfTask(); void PostPrintToPdfTask();
void OnGotUniqueFileName(const base::FilePath& path); 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_; Profile* const profile_;
printing::StickySettings* const sticky_settings_; 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