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.
5 #include "chrome/browser/ui/webui/print_preview/sticky_settings.h"
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"
19 const char kSettingSavePath
[] = "savePath";
20 const char kSettingAppState
[] = "appState";
22 StickySettings::StickySettings() {}
24 StickySettings::~StickySettings() {}
26 void StickySettings::StoreAppState(const std::string
& data
) {
27 printer_app_state_
.reset(new std::string(data
));
30 void StickySettings::StoreSavePath(const base::FilePath
& path
) {
31 save_path_
.reset(new base::FilePath(path
));
34 void StickySettings::SaveInPrefs(PrefService
* prefs
) {
37 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue
);
39 value
->SetString(printing::kSettingSavePath
, save_path_
->value());
40 if (printer_app_state_
.get())
41 value
->SetString(printing::kSettingAppState
,
43 prefs
->Set(prefs::kPrintPreviewStickySettings
, *value
);
47 void StickySettings::RestoreFromPrefs(PrefService
* prefs
) {
50 const base::DictionaryValue
* value
=
51 prefs
->GetDictionary(prefs::kPrintPreviewStickySettings
);
53 base::FilePath::StringType save_path
;
54 if (value
->GetString(printing::kSettingSavePath
, &save_path
))
55 save_path_
.reset(new base::FilePath(save_path
));
57 if (value
->GetString(printing::kSettingAppState
, &buffer
))
58 printer_app_state_
.reset(new std::string(buffer
));
62 void StickySettings::RegisterProfilePrefs(
63 user_prefs::PrefRegistrySyncable
* registry
) {
64 registry
->RegisterDictionaryPref(prefs::kPrintPreviewStickySettings
);
67 std::string
* StickySettings::printer_app_state() {
68 return printer_app_state_
.get();
71 base::FilePath
* StickySettings::save_path() {
72 return save_path_
.get();
75 } // namespace printing