Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6527)

Unified Diff: chrome/browser/ui/webui/print_preview/sticky_settings.cc

Issue 10909124: Improves application state persistance. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Updates unit tests. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/webui/print_preview/sticky_settings.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/print_preview/sticky_settings.cc
diff --git a/chrome/browser/ui/webui/print_preview/sticky_settings.cc b/chrome/browser/ui/webui/print_preview/sticky_settings.cc
index 1feed70bc9de740c77d5c0bd640040b94e6f35a6..6720edc1f7bd6f026bc2a4910ab6fd30d3279323 100644
--- a/chrome/browser/ui/webui/print_preview/sticky_settings.cc
+++ b/chrome/browser/ui/webui/print_preview/sticky_settings.cc
@@ -16,89 +16,14 @@
namespace printing {
const char kSettingSavePath[] = "savePath";
-const char kSettingCloudPrintData[] = "cloudPrintData";
+const char kSettingAppState[] = "appState";
-StickySettings::StickySettings()
- : color_model_(printing::UNKNOWN_COLOR_MODEL),
- margins_type_(printing::DEFAULT_MARGINS),
- headers_footers_(true),
- duplex_mode_(printing::UNKNOWN_DUPLEX_MODE) {}
+StickySettings::StickySettings() {}
StickySettings::~StickySettings() {}
-void StickySettings::GetLastUsedMarginSettings(
- base::DictionaryValue* custom_margins) const {
- custom_margins->SetInteger(printing::kSettingMarginsType,
- margins_type_);
- if (page_size_margins_.get()) {
- custom_margins->SetDouble(printing::kSettingMarginTop,
- page_size_margins_->margin_top);
- custom_margins->SetDouble(printing::kSettingMarginBottom,
- page_size_margins_->margin_bottom);
- custom_margins->SetDouble(printing::kSettingMarginLeft,
- page_size_margins_->margin_left);
- custom_margins->SetDouble(printing::kSettingMarginRight,
- page_size_margins_->margin_right);
- }
-}
-
-void StickySettings::StoreColorModel(
- const base::DictionaryValue& settings) {
- int color_model;
- if (!settings.GetInteger(printing::kSettingColor, &color_model))
- color_model = printing::GRAY;
- color_model_ = static_cast<printing::ColorModels>(color_model);
-}
-
-void StickySettings::StoreMarginSettings(
- const base::DictionaryValue& settings) {
- int margin_type;
- if (!settings.GetInteger(printing::kSettingMarginsType, &margin_type))
- margin_type = printing::DEFAULT_MARGINS;
- margins_type_ = static_cast<printing::MarginType>(margin_type);
- if (margins_type_ == printing::CUSTOM_MARGINS) {
- if (!page_size_margins_.get())
- page_size_margins_.reset(new printing::PageSizeMargins());
- GetCustomMarginsFromJobSettings(
- settings, page_size_margins_.get());
- }
-}
-
-void StickySettings::StoreHeadersFooters(
- const base::DictionaryValue& settings) {
- settings.GetBoolean(
- printing::kSettingHeaderFooterEnabled, &headers_footers_);
-}
-
-void StickySettings::Store(const base::DictionaryValue& settings) {
- // Storing last used color model.
- StoreColorModel(settings);
- // Storing last used duplex mode.
- StoreDuplexMode(settings);
-
- bool is_modifiable = false;
- settings.GetBoolean(printing::kSettingPreviewModifiable, &is_modifiable);
- if (is_modifiable) {
- // Storing last used margin settings.
- StoreMarginSettings(settings);
- // Storing last used header and footer setting.
- StoreHeadersFooters(settings);
- }
-}
-
-void StickySettings::StoreDuplexMode(
- const base::DictionaryValue& settings) {
- int duplex_mode = printing::UNKNOWN_DUPLEX_MODE;
- settings.GetInteger(printing::kSettingDuplexMode, &duplex_mode);
- duplex_mode_ = static_cast<printing::DuplexMode>(duplex_mode);
-}
-
-void StickySettings::StorePrinterName(const std::string& printer_name) {
- printer_name_.reset(new std::string(printer_name));
-}
-
-void StickySettings::StoreCloudPrintData(const std::string& data) {
- printer_cloud_print_data_.reset(new std::string(data));
+void StickySettings::StoreAppState(const std::string& data) {
+ printer_app_state_.reset(new std::string(data));
}
void StickySettings::StoreSavePath(const FilePath& path) {
@@ -106,43 +31,19 @@ void StickySettings::StoreSavePath(const FilePath& path) {
}
void StickySettings::SaveInPrefs(PrefService* prefs) {
- if (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kPrintSettingsReset))
- return;
DCHECK(prefs);
if (prefs) {
scoped_ptr<DictionaryValue> value(new DictionaryValue);
if (save_path_.get())
value->SetString(printing::kSettingSavePath, save_path_->value());
- if (printer_name_.get())
- value->SetString(printing::kSettingPrinterName, *printer_name_);
- if (printer_cloud_print_data_.get())
- value->SetString(printing::kSettingCloudPrintData,
- *printer_cloud_print_data_);
- value->SetInteger(printing::kSettingColor, color_model_);
- value->SetInteger(printing::kSettingMarginsType, margins_type_);
- if (margins_type_ == printing::CUSTOM_MARGINS) {
- if (page_size_margins_.get()) {
- value->SetDouble(printing::kSettingMarginTop,
- page_size_margins_->margin_top);
- value->SetDouble(printing::kSettingMarginBottom,
- page_size_margins_->margin_bottom);
- value->SetDouble(printing::kSettingMarginLeft,
- page_size_margins_->margin_left);
- value->SetDouble(printing::kSettingMarginRight,
- page_size_margins_->margin_right);
- }
- }
- value->SetBoolean(printing::kSettingHeaderFooterEnabled, headers_footers_);
- value->SetInteger(printing::kSettingDuplexMode, duplex_mode_);
+ if (printer_app_state_.get())
+ value->SetString(printing::kSettingAppState,
+ *printer_app_state_);
prefs->Set(prefs::kPrintPreviewStickySettings, *value);
}
}
void StickySettings::RestoreFromPrefs(PrefService* prefs) {
- if (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kPrintSettingsReset))
- return;
DCHECK(prefs);
if (prefs) {
const DictionaryValue* value =
@@ -152,32 +53,8 @@ void StickySettings::RestoreFromPrefs(PrefService* prefs) {
if (value->GetString(printing::kSettingSavePath, &save_path))
save_path_.reset(new FilePath(save_path));
std::string buffer;
- if (value->GetString(printing::kSettingPrinterName, &buffer))
- StorePrinterName(buffer);
- if (value->GetString(printing::kSettingCloudPrintData, &buffer))
- StoreCloudPrintData(buffer);
- int int_buffer;
- if (value->GetInteger(printing::kSettingColor, &int_buffer))
- color_model_ = static_cast<printing::ColorModels>(int_buffer);
- if (value->GetInteger(printing::kSettingMarginsType, &int_buffer))
- margins_type_ = static_cast<printing::MarginType>(int_buffer);
- if (margins_type_ == printing::CUSTOM_MARGINS) {
- if (!page_size_margins_.get())
- page_size_margins_.reset(new PageSizeMargins);
- if (page_size_margins_.get()) {
- value->GetDouble(printing::kSettingMarginTop,
- &page_size_margins_->margin_top);
- value->GetDouble(printing::kSettingMarginBottom,
- &page_size_margins_->margin_bottom);
- value->GetDouble(printing::kSettingMarginLeft,
- &page_size_margins_->margin_left);
- value->GetDouble(printing::kSettingMarginRight,
- &page_size_margins_->margin_right);
- }
- }
- value->GetBoolean(printing::kSettingHeaderFooterEnabled, &headers_footers_);
- if (value->GetInteger(printing::kSettingDuplexMode, &int_buffer))
- duplex_mode_ = static_cast<printing::DuplexMode>(int_buffer);
+ if (value->GetString(printing::kSettingAppState, &buffer))
+ printer_app_state_.reset(new std::string(buffer));
}
}
@@ -186,28 +63,12 @@ void StickySettings::RegisterUserPrefs(PrefService* prefs) {
PrefService::UNSYNCABLE_PREF);
}
-std::string* StickySettings::printer_name() {
- return printer_name_.get();
-}
-
-std::string* StickySettings::printer_cloud_print_data() {
- return printer_cloud_print_data_.get();
-}
-
-printing::ColorModels StickySettings::color_model() const {
- return color_model_;
-}
-
-bool StickySettings::headers_footers() const {
- return headers_footers_;
+std::string* StickySettings::printer_app_state() {
+ return printer_app_state_.get();
}
FilePath* StickySettings::save_path() {
return save_path_.get();
}
-printing::DuplexMode StickySettings::duplex_mode() const {
- return duplex_mode_;
-}
-
} // namespace printing
« no previous file with comments | « chrome/browser/ui/webui/print_preview/sticky_settings.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698