Home | History | Annotate | Download | only in print_preview
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/ui/webui/print_preview/sticky_settings.h"
      6 
      7 #include "base/command_line.h"
      8 #include "base/files/file_path.h"
      9 #include "base/prefs/pref_service.h"
     10 #include "base/values.h"
     11 #include "chrome/browser/profiles/profile.h"
     12 #include "chrome/common/chrome_switches.h"
     13 #include "chrome/common/pref_names.h"
     14 #include "components/user_prefs/pref_registry_syncable.h"
     15 #include "printing/page_size_margins.h"
     16 
     17 namespace printing {
     18 
     19 const char kSettingSavePath[] = "savePath";
     20 const char kSettingAppState[] = "appState";
     21 
     22 StickySettings::StickySettings() {}
     23 
     24 StickySettings::~StickySettings() {}
     25 
     26 void StickySettings::StoreAppState(const std::string& data) {
     27   printer_app_state_.reset(new std::string(data));
     28 }
     29 
     30 void StickySettings::StoreSavePath(const base::FilePath& path) {
     31   save_path_.reset(new base::FilePath(path));
     32 }
     33 
     34 void StickySettings::SaveInPrefs(PrefService* prefs) {
     35   DCHECK(prefs);
     36   if (prefs) {
     37     scoped_ptr<DictionaryValue> value(new DictionaryValue);
     38     if (save_path_.get())
     39       value->SetString(printing::kSettingSavePath, save_path_->value());
     40     if (printer_app_state_.get())
     41       value->SetString(printing::kSettingAppState,
     42           *printer_app_state_);
     43     prefs->Set(prefs::kPrintPreviewStickySettings, *value);
     44   }
     45 }
     46 
     47 void StickySettings::RestoreFromPrefs(PrefService* prefs) {
     48   DCHECK(prefs);
     49   if (prefs) {
     50     const DictionaryValue* value =
     51         prefs->GetDictionary(prefs::kPrintPreviewStickySettings);
     52 
     53     base::FilePath::StringType save_path;
     54     if (value->GetString(printing::kSettingSavePath, &save_path))
     55       save_path_.reset(new base::FilePath(save_path));
     56     std::string buffer;
     57     if (value->GetString(printing::kSettingAppState, &buffer))
     58       printer_app_state_.reset(new std::string(buffer));
     59   }
     60 }
     61 
     62 void StickySettings::RegisterProfilePrefs(
     63     user_prefs::PrefRegistrySyncable* registry) {
     64   registry->RegisterDictionaryPref(
     65       prefs::kPrintPreviewStickySettings,
     66       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
     67 }
     68 
     69 std::string* StickySettings::printer_app_state() {
     70   return printer_app_state_.get();
     71 }
     72 
     73 base::FilePath* StickySettings::save_path() {
     74   return save_path_.get();
     75 }
     76 
     77 } // namespace printing
     78