[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 1 | // 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 | |
| 9 | ServiceProcessPrefs::ServiceProcessPrefs( |
| 10 | const FilePath& pref_filename, |
| 11 | base::MessageLoopProxy* file_message_loop_proxy) |
[email protected] | c3498a1 | 2011-02-02 04:14:42 | [diff] [blame^] | 12 | : prefs_(new JsonPrefStore(pref_filename, file_message_loop_proxy)) { |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 13 | } |
| 14 | |
| 15 | void ServiceProcessPrefs::ReadPrefs() { |
[email protected] | c3498a1 | 2011-02-02 04:14:42 | [diff] [blame^] | 16 | prefs_->ReadPrefs(); |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | void ServiceProcessPrefs::WritePrefs() { |
[email protected] | c3498a1 | 2011-02-02 04:14:42 | [diff] [blame^] | 20 | prefs_->WritePrefs(); |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | void ServiceProcessPrefs::GetString(const std::string& key, |
| 24 | std::string* result) { |
| 25 | Value* value; |
[email protected] | c3498a1 | 2011-02-02 04:14:42 | [diff] [blame^] | 26 | if (prefs_->GetValue(key, &value) == PersistentPrefStore::READ_OK) |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 27 | value->GetAsString(result); |
| 28 | } |
| 29 | |
| 30 | void ServiceProcessPrefs::SetString(const std::string& key, |
| 31 | const std::string& value) { |
[email protected] | c3498a1 | 2011-02-02 04:14:42 | [diff] [blame^] | 32 | prefs_->SetValue(key, Value::CreateStringValue(value)); |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | void ServiceProcessPrefs::GetBoolean(const std::string& key, bool* result) { |
| 36 | Value* value; |
[email protected] | c3498a1 | 2011-02-02 04:14:42 | [diff] [blame^] | 37 | if (prefs_->GetValue(key, &value) == PersistentPrefStore::READ_OK) |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 38 | value->GetAsBoolean(result); |
| 39 | } |
| 40 | |
| 41 | void ServiceProcessPrefs::SetBoolean(const std::string& key, bool value) { |
[email protected] | c3498a1 | 2011-02-02 04:14:42 | [diff] [blame^] | 42 | prefs_->SetValue(key, Value::CreateBooleanValue(value)); |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | void ServiceProcessPrefs::GetDictionary(const std::string& key, |
| 46 | DictionaryValue** result) { |
| 47 | Value* value; |
[email protected] | c3498a1 | 2011-02-02 04:14:42 | [diff] [blame^] | 48 | if (prefs_->GetValue(key, &value) != PersistentPrefStore::READ_OK || |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 49 | !value->IsType(Value::TYPE_DICTIONARY)) { |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | *result = static_cast<DictionaryValue*>(value); |
| 54 | } |