• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/pref_registry/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 
StickySettings()22 StickySettings::StickySettings() {}
23 
~StickySettings()24 StickySettings::~StickySettings() {}
25 
StoreAppState(const std::string & data)26 void StickySettings::StoreAppState(const std::string& data) {
27   printer_app_state_.reset(new std::string(data));
28 }
29 
StoreSavePath(const base::FilePath & path)30 void StickySettings::StoreSavePath(const base::FilePath& path) {
31   save_path_.reset(new base::FilePath(path));
32 }
33 
SaveInPrefs(PrefService * prefs)34 void StickySettings::SaveInPrefs(PrefService* prefs) {
35   DCHECK(prefs);
36   if (prefs) {
37     scoped_ptr<base::DictionaryValue> value(new base::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 
RestoreFromPrefs(PrefService * prefs)47 void StickySettings::RestoreFromPrefs(PrefService* prefs) {
48   DCHECK(prefs);
49   if (prefs) {
50     const base::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 
RegisterProfilePrefs(user_prefs::PrefRegistrySyncable * registry)62 void StickySettings::RegisterProfilePrefs(
63     user_prefs::PrefRegistrySyncable* registry) {
64   registry->RegisterDictionaryPref(
65       prefs::kPrintPreviewStickySettings,
66       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
67 }
68 
printer_app_state()69 std::string* StickySettings::printer_app_state() {
70   return printer_app_state_.get();
71 }
72 
save_path()73 base::FilePath* StickySettings::save_path() {
74   return save_path_.get();
75 }
76 
77 } // namespace printing
78