Move DidStartLoading, DidStopLoading, DidChangeLoadProgress IPCs to RFHI.
[chromium-blink-merge.git] / chrome / service / service_process_prefs.cc
blobd923185d86a56c384db1e4f455e4542f46355dab
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,
15 task_runner,
16 scoped_ptr<PrefFilter>())) {
19 ServiceProcessPrefs::~ServiceProcessPrefs() {}
21 void ServiceProcessPrefs::ReadPrefs() {
22 prefs_->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;
33 std::string result;
34 if (!prefs_->GetValue(key, &value) || !value->GetAsString(&result))
35 return default_value;
37 return 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;
48 bool result = false;
49 if (!prefs_->GetValue(key, &value) || !value->GetAsBoolean(&result))
50 return default_value;
52 return 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))
64 return default_value;
66 return 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)) {
78 return NULL;
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))
88 return NULL;
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);