1 // Copyright (c) 2011 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/service/service_process_prefs.h"
7 #include "base/message_loop/message_loop_proxy.h"
8 #include "base/prefs/pref_filter.h"
9 #include "base/values.h"
11 ServiceProcessPrefs::ServiceProcessPrefs(
12 const base::FilePath
& pref_filename
,
13 base::SequencedTaskRunner
* task_runner
)
14 : prefs_(new JsonPrefStore(pref_filename
,
16 scoped_ptr
<PrefFilter
>())) {
19 ServiceProcessPrefs::~ServiceProcessPrefs() {}
21 void ServiceProcessPrefs::ReadPrefs() {
25 void ServiceProcessPrefs::WritePrefs() {
26 prefs_
->CommitPendingWrite();
29 std::string
ServiceProcessPrefs::GetString(
30 const std::string
& key
,
31 const std::string
& default_value
) const {
32 const base::Value
* value
;
34 if (!prefs_
->GetValue(key
, &value
) || !value
->GetAsString(&result
))
40 void ServiceProcessPrefs::SetString(const std::string
& key
,
41 const std::string
& value
) {
42 prefs_
->SetValue(key
, new base::StringValue(value
));
45 bool ServiceProcessPrefs::GetBoolean(const std::string
& key
,
46 bool default_value
) const {
47 const base::Value
* value
;
49 if (!prefs_
->GetValue(key
, &value
) || !value
->GetAsBoolean(&result
))
55 void ServiceProcessPrefs::SetBoolean(const std::string
& key
, bool value
) {
56 prefs_
->SetValue(key
, new base::FundamentalValue(value
));
59 int ServiceProcessPrefs::GetInt(const std::string
& key
,
60 int default_value
) const {
61 const base::Value
* value
;
62 int result
= default_value
;
63 if (!prefs_
->GetValue(key
, &value
) || !value
->GetAsInteger(&result
))
69 void ServiceProcessPrefs::SetInt(const std::string
& key
, int value
) {
70 prefs_
->SetValue(key
, new base::FundamentalValue(value
));
73 const base::DictionaryValue
* ServiceProcessPrefs::GetDictionary(
74 const std::string
& key
) const {
75 const base::Value
* value
;
76 if (!prefs_
->GetValue(key
, &value
) ||
77 !value
->IsType(base::Value::TYPE_DICTIONARY
)) {
81 return static_cast<const base::DictionaryValue
*>(value
);
84 const base::ListValue
* ServiceProcessPrefs::GetList(
85 const std::string
& key
) const {
86 const base::Value
* value
;
87 if (!prefs_
->GetValue(key
, &value
) || !value
->IsType(base::Value::TYPE_LIST
))
90 return static_cast<const base::ListValue
*>(value
);
93 void ServiceProcessPrefs::SetValue(const std::string
& key
, base::Value
* value
) {
94 prefs_
->SetValue(key
, value
);
97 void ServiceProcessPrefs::RemovePref(const std::string
& key
) {
98 prefs_
->RemoveValue(key
);