OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/service/service_process_prefs.h" | 5 #include "chrome/service/service_process_prefs.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 | 8 |
9 ServiceProcessPrefs::ServiceProcessPrefs( | 9 ServiceProcessPrefs::ServiceProcessPrefs( |
10 const FilePath& pref_filename, | 10 const FilePath& pref_filename, |
11 base::MessageLoopProxy* file_message_loop_proxy) | 11 base::MessageLoopProxy* file_message_loop_proxy) |
12 : prefs_(pref_filename, file_message_loop_proxy) { | 12 : prefs_(new JsonPrefStore(pref_filename, file_message_loop_proxy)) { |
13 } | 13 } |
14 | 14 |
15 void ServiceProcessPrefs::ReadPrefs() { | 15 void ServiceProcessPrefs::ReadPrefs() { |
16 prefs_.ReadPrefs(); | 16 prefs_->ReadPrefs(); |
17 } | 17 } |
18 | 18 |
19 void ServiceProcessPrefs::WritePrefs() { | 19 void ServiceProcessPrefs::WritePrefs() { |
20 prefs_.WritePrefs(); | 20 prefs_->WritePrefs(); |
21 } | 21 } |
22 | 22 |
23 void ServiceProcessPrefs::GetString(const std::string& key, | 23 void ServiceProcessPrefs::GetString(const std::string& key, |
24 std::string* result) { | 24 std::string* result) { |
25 Value* value; | 25 Value* value; |
26 if (prefs_.GetValue(key, &value) == PersistentPrefStore::READ_OK) | 26 if (prefs_->GetValue(key, &value) == PersistentPrefStore::READ_OK) |
27 value->GetAsString(result); | 27 value->GetAsString(result); |
28 } | 28 } |
29 | 29 |
30 void ServiceProcessPrefs::SetString(const std::string& key, | 30 void ServiceProcessPrefs::SetString(const std::string& key, |
31 const std::string& value) { | 31 const std::string& value) { |
32 prefs_.SetValue(key, Value::CreateStringValue(value)); | 32 prefs_->SetValue(key, Value::CreateStringValue(value)); |
33 } | 33 } |
34 | 34 |
35 void ServiceProcessPrefs::GetBoolean(const std::string& key, bool* result) { | 35 void ServiceProcessPrefs::GetBoolean(const std::string& key, bool* result) { |
36 Value* value; | 36 Value* value; |
37 if (prefs_.GetValue(key, &value) == PersistentPrefStore::READ_OK) | 37 if (prefs_->GetValue(key, &value) == PersistentPrefStore::READ_OK) |
38 value->GetAsBoolean(result); | 38 value->GetAsBoolean(result); |
39 } | 39 } |
40 | 40 |
41 void ServiceProcessPrefs::SetBoolean(const std::string& key, bool value) { | 41 void ServiceProcessPrefs::SetBoolean(const std::string& key, bool value) { |
42 prefs_.SetValue(key, Value::CreateBooleanValue(value)); | 42 prefs_->SetValue(key, Value::CreateBooleanValue(value)); |
43 } | 43 } |
44 | 44 |
45 void ServiceProcessPrefs::GetDictionary(const std::string& key, | 45 void ServiceProcessPrefs::GetDictionary(const std::string& key, |
46 DictionaryValue** result) { | 46 DictionaryValue** result) { |
47 Value* value; | 47 Value* value; |
48 if (prefs_.GetValue(key, &value) != PersistentPrefStore::READ_OK || | 48 if (prefs_->GetValue(key, &value) != PersistentPrefStore::READ_OK || |
49 !value->IsType(Value::TYPE_DICTIONARY)) { | 49 !value->IsType(Value::TYPE_DICTIONARY)) { |
50 return; | 50 return; |
51 } | 51 } |
52 | 52 |
53 *result = static_cast<DictionaryValue*>(value); | 53 *result = static_cast<DictionaryValue*>(value); |
54 } | 54 } |
OLD | NEW |