Simple Cache: transactional index in subdirectory
[chromium-blink-merge.git] / chrome / service / service_process_prefs.cc
blobc628a0b5e86b29c66b5b76879d1021c47b2e8033
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/values.h"
10 ServiceProcessPrefs::ServiceProcessPrefs(
11 const base::FilePath& pref_filename,
12 base::SequencedTaskRunner* task_runner)
13 : prefs_(new JsonPrefStore(pref_filename, task_runner)) {
16 ServiceProcessPrefs::~ServiceProcessPrefs() {}
18 void ServiceProcessPrefs::ReadPrefs() {
19 prefs_->ReadPrefs();
22 void ServiceProcessPrefs::WritePrefs() {
23 prefs_->CommitPendingWrite();
26 std::string ServiceProcessPrefs::GetString(
27 const std::string& key,
28 const std::string& default_value) const {
29 const base::Value* value;
30 std::string result;
31 if (!prefs_->GetValue(key, &value) || !value->GetAsString(&result))
32 return default_value;
34 return result;
37 void ServiceProcessPrefs::SetString(const std::string& key,
38 const std::string& value) {
39 prefs_->SetValue(key, new base::StringValue(value));
42 bool ServiceProcessPrefs::GetBoolean(const std::string& key,
43 bool default_value) const {
44 const base::Value* value;
45 bool result = false;
46 if (!prefs_->GetValue(key, &value) || !value->GetAsBoolean(&result))
47 return default_value;
49 return result;
52 void ServiceProcessPrefs::SetBoolean(const std::string& key, bool value) {
53 prefs_->SetValue(key, new base::FundamentalValue(value));
56 int ServiceProcessPrefs::GetInt(const std::string& key,
57 int default_value) const {
58 const base::Value* value;
59 int result = default_value;
60 if (!prefs_->GetValue(key, &value) || !value->GetAsInteger(&result))
61 return default_value;
63 return result;
66 void ServiceProcessPrefs::SetInt(const std::string& key, int value) {
67 prefs_->SetValue(key, new base::FundamentalValue(value));
70 const base::DictionaryValue* ServiceProcessPrefs::GetDictionary(
71 const std::string& key) const {
72 const base::Value* value;
73 if (!prefs_->GetValue(key, &value) ||
74 !value->IsType(base::Value::TYPE_DICTIONARY)) {
75 return NULL;
78 return static_cast<const base::DictionaryValue*>(value);
81 const base::ListValue* ServiceProcessPrefs::GetList(
82 const std::string& key) const {
83 const base::Value* value;
84 if (!prefs_->GetValue(key, &value) || !value->IsType(base::Value::TYPE_LIST))
85 return NULL;
87 return static_cast<const base::ListValue*>(value);
90 void ServiceProcessPrefs::SetValue(const std::string& key, base::Value* value) {
91 prefs_->SetValue(key, value);
94 void ServiceProcessPrefs::RemovePref(const std::string& key) {
95 prefs_->RemoveValue(key);