Commit 0e727b34 authored by rbpotter's avatar rbpotter Committed by Commit bot

Modified printing to no longer store its own save path.

Instead, uses the save path from Download preferences.

This initializes to the path set by the user in Settings, then
updates with each Download or Save to PDF.

BUG=136331

Review-Url: https://codereview.chromium.org/2139303003
Cr-Commit-Position: refs/heads/master@{#405515}
parent a79d7c93
......@@ -23,17 +23,16 @@
#include "base/macros.h"
#include "base/memory/ref_counted_memory.h"
#include "base/metrics/histogram.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task_runner_util.h"
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/app_mode/app_mode_utils.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/printing/print_dialog_cloud.h"
#include "chrome/browser/printing/print_error_dialog.h"
......@@ -52,7 +51,6 @@
#include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
#include "chrome/browser/ui/webui/print_preview/printer_handler.h"
#include "chrome/browser/ui/webui/print_preview/sticky_settings.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/cloud_print/cloud_print_cdd_conversion.h"
#include "chrome/common/cloud_print/cloud_print_constants.h"
......@@ -1357,20 +1355,13 @@ void PrintPreviewHandler::SelectFile(const base::FilePath& default_filename,
}
}
// Initializing |save_path_| if it is not already initialized.
// Get save location from Download Preferences.
DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext(
preview_web_contents()->GetBrowserContext());
base::FilePath file_path = download_prefs->SaveFilePath();
printing::StickySettings* sticky_settings = GetStickySettings();
if (!sticky_settings->save_path()) {
// Allowing IO operation temporarily. It is ok to do so here because
// the select file dialog performs IO anyway in order to display the
// folders and also it is modal.
base::ThreadRestrictions::ScopedAllowIO allow_io;
base::FilePath file_path;
PathService::Get(chrome::DIR_USER_DOCUMENTS, &file_path);
sticky_settings->StoreSavePath(file_path);
sticky_settings->SaveInPrefs(Profile::FromBrowserContext(
preview_web_contents()->GetBrowserContext())->GetPrefs());
}
sticky_settings->SaveInPrefs(Profile::FromBrowserContext(
preview_web_contents()->GetBrowserContext())->GetPrefs());
// Handle the no prompting case. Like the dialog prompt, this function
// returns and eventually FileSelected() gets called.
if (!prompt_user) {
......@@ -1378,7 +1369,7 @@ void PrintPreviewHandler::SelectFile(const base::FilePath& default_filename,
BrowserThread::GetBlockingPool(),
FROM_HERE,
base::Bind(&GetUniquePath,
sticky_settings->save_path()->Append(default_filename)),
download_prefs->SaveFilePath().Append(default_filename)),
base::Bind(&PrintPreviewHandler::OnGotUniqueFileName,
weak_factory_.GetWeakPtr()));
return;
......@@ -1394,7 +1385,7 @@ void PrintPreviewHandler::SelectFile(const base::FilePath& default_filename,
select_file_dialog_->SelectFile(
ui::SelectFileDialog::SELECT_SAVEAS_FILE,
base::string16(),
sticky_settings->save_path()->Append(default_filename),
download_prefs->SaveFilePath().Append(default_filename),
&file_type_info,
0,
base::FilePath::StringType(),
......@@ -1422,10 +1413,12 @@ void PrintPreviewHandler::ShowSystemDialog() {
void PrintPreviewHandler::FileSelected(const base::FilePath& path,
int /* index */,
void* /* params */) {
// Updating |save_path_| to the newly selected folder.
// Update downloads location and save sticky settings.
DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext(
preview_web_contents()->GetBrowserContext());
download_prefs->SetSaveFilePath(path.DirName());
printing::StickySettings* sticky_settings = GetStickySettings();
sticky_settings->StoreSavePath(path.DirName());
sticky_settings->SaveInPrefs(Profile::FromBrowserContext(
sticky_settings->SaveInPrefs(Profile::FromBrowserContext(
preview_web_contents()->GetBrowserContext())->GetPrefs());
web_ui()->CallJavascriptFunctionUnsafe("fileSelectionCompleted");
print_to_pdf_path_ = path;
......
......@@ -5,7 +5,6 @@
#include "chrome/browser/ui/webui/print_preview/sticky_settings.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
......@@ -16,7 +15,6 @@
namespace printing {
const char kSettingSavePath[] = "savePath";
const char kSettingAppState[] = "appState";
StickySettings::StickySettings() {}
......@@ -27,16 +25,10 @@ void StickySettings::StoreAppState(const std::string& data) {
printer_app_state_.reset(new std::string(data));
}
void StickySettings::StoreSavePath(const base::FilePath& path) {
save_path_.reset(new base::FilePath(path));
}
void StickySettings::SaveInPrefs(PrefService* prefs) {
DCHECK(prefs);
if (prefs) {
std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue);
if (save_path_.get())
value->SetString(printing::kSettingSavePath, save_path_->value());
if (printer_app_state_.get())
value->SetString(printing::kSettingAppState,
*printer_app_state_);
......@@ -50,9 +42,6 @@ void StickySettings::RestoreFromPrefs(PrefService* prefs) {
const base::DictionaryValue* value =
prefs->GetDictionary(prefs::kPrintPreviewStickySettings);
base::FilePath::StringType save_path;
if (value->GetString(printing::kSettingSavePath, &save_path))
save_path_.reset(new base::FilePath(save_path));
std::string buffer;
if (value->GetString(printing::kSettingAppState, &buffer))
printer_app_state_.reset(new std::string(buffer));
......@@ -68,8 +57,4 @@ std::string* StickySettings::printer_app_state() {
return printer_app_state_.get();
}
base::FilePath* StickySettings::save_path() {
return save_path_.get();
}
} // namespace printing
......@@ -14,7 +14,6 @@ class PrefService;
namespace base {
class DictionaryValue;
class FilePath;
}
namespace user_prefs {
......@@ -31,20 +30,16 @@ class StickySettings {
StickySettings();
~StickySettings();
base::FilePath* save_path();
std::string* printer_app_state();
// Stores app state for the last used printer.
void StoreAppState(const std::string& app_state);
// Stores the last path the user used to save to pdf.
void StoreSavePath(const base::FilePath& path);
void SaveInPrefs(PrefService* profile);
void RestoreFromPrefs(PrefService* profile);
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
private:
std::unique_ptr<base::FilePath> save_path_;
std::unique_ptr<std::string> printer_app_state_;
};
......
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