blob: d0e479688f5bc3226a3fdfd773402f93861668a0 [file] [log] [blame]
[email protected]f2d1f612010-12-09 15:10:171// Copyright (c) 2010 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/service/service_process_prefs.h"
6
7#include "base/values.h"
8
9ServiceProcessPrefs::ServiceProcessPrefs(
10 const FilePath& pref_filename,
11 base::MessageLoopProxy* file_message_loop_proxy)
[email protected]c3498a12011-02-02 04:14:4212 : prefs_(new JsonPrefStore(pref_filename, file_message_loop_proxy)) {
[email protected]f2d1f612010-12-09 15:10:1713}
14
15void ServiceProcessPrefs::ReadPrefs() {
[email protected]c3498a12011-02-02 04:14:4216 prefs_->ReadPrefs();
[email protected]f2d1f612010-12-09 15:10:1717}
18
19void ServiceProcessPrefs::WritePrefs() {
[email protected]c3498a12011-02-02 04:14:4220 prefs_->WritePrefs();
[email protected]f2d1f612010-12-09 15:10:1721}
22
23void ServiceProcessPrefs::GetString(const std::string& key,
24 std::string* result) {
25 Value* value;
[email protected]c3498a12011-02-02 04:14:4226 if (prefs_->GetValue(key, &value) == PersistentPrefStore::READ_OK)
[email protected]f2d1f612010-12-09 15:10:1727 value->GetAsString(result);
28}
29
30void ServiceProcessPrefs::SetString(const std::string& key,
31 const std::string& value) {
[email protected]c3498a12011-02-02 04:14:4232 prefs_->SetValue(key, Value::CreateStringValue(value));
[email protected]f2d1f612010-12-09 15:10:1733}
34
35void ServiceProcessPrefs::GetBoolean(const std::string& key, bool* result) {
36 Value* value;
[email protected]c3498a12011-02-02 04:14:4237 if (prefs_->GetValue(key, &value) == PersistentPrefStore::READ_OK)
[email protected]f2d1f612010-12-09 15:10:1738 value->GetAsBoolean(result);
39}
40
41void ServiceProcessPrefs::SetBoolean(const std::string& key, bool value) {
[email protected]c3498a12011-02-02 04:14:4242 prefs_->SetValue(key, Value::CreateBooleanValue(value));
[email protected]f2d1f612010-12-09 15:10:1743}
44
45void ServiceProcessPrefs::GetDictionary(const std::string& key,
46 DictionaryValue** result) {
47 Value* value;
[email protected]c3498a12011-02-02 04:14:4248 if (prefs_->GetValue(key, &value) != PersistentPrefStore::READ_OK ||
[email protected]f2d1f612010-12-09 15:10:1749 !value->IsType(Value::TYPE_DICTIONARY)) {
50 return;
51 }
52
53 *result = static_cast<DictionaryValue*>(value);
54}