Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: chrome/service/service_process_prefs.cc

Issue 11365112: Change PrefStore::ReadResult to a boolean. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/message_loop_proxy.h" 7 #include "base/message_loop_proxy.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 9
10 ServiceProcessPrefs::ServiceProcessPrefs( 10 ServiceProcessPrefs::ServiceProcessPrefs(
(...skipping 10 matching lines...) Expand all
21 21
22 void ServiceProcessPrefs::WritePrefs() { 22 void ServiceProcessPrefs::WritePrefs() {
23 prefs_->CommitPendingWrite(); 23 prefs_->CommitPendingWrite();
24 } 24 }
25 25
26 std::string ServiceProcessPrefs::GetString( 26 std::string ServiceProcessPrefs::GetString(
27 const std::string& key, 27 const std::string& key,
28 const std::string& default_value) const { 28 const std::string& default_value) const {
29 const Value* value; 29 const Value* value;
30 std::string result; 30 std::string result;
31 if (prefs_->GetValue(key, &value) != PersistentPrefStore::READ_OK || 31 if (!prefs_->GetValue(key, &value) || !value->GetAsString(&result))
32 !value->GetAsString(&result)) {
33 return default_value; 32 return default_value;
34 } 33
35 return result; 34 return result;
36 } 35 }
37 36
38 void ServiceProcessPrefs::SetString(const std::string& key, 37 void ServiceProcessPrefs::SetString(const std::string& key,
39 const std::string& value) { 38 const std::string& value) {
40 prefs_->SetValue(key, Value::CreateStringValue(value)); 39 prefs_->SetValue(key, Value::CreateStringValue(value));
41 } 40 }
42 41
43 bool ServiceProcessPrefs::GetBoolean(const std::string& key, 42 bool ServiceProcessPrefs::GetBoolean(const std::string& key,
44 bool default_value) const { 43 bool default_value) const {
45 const Value* value; 44 const Value* value;
46 bool result = false; 45 bool result = false;
47 if (prefs_->GetValue(key, &value) != PersistentPrefStore::READ_OK || 46 if (!prefs_->GetValue(key, &value) || !value->GetAsBoolean(&result))
48 !value->GetAsBoolean(&result)) {
49 return default_value; 47 return default_value;
50 } 48
51 return result; 49 return result;
52 } 50 }
53 51
54 void ServiceProcessPrefs::SetBoolean(const std::string& key, bool value) { 52 void ServiceProcessPrefs::SetBoolean(const std::string& key, bool value) {
55 prefs_->SetValue(key, Value::CreateBooleanValue(value)); 53 prefs_->SetValue(key, Value::CreateBooleanValue(value));
56 } 54 }
57 55
58 int ServiceProcessPrefs::GetInt(const std::string& key, 56 int ServiceProcessPrefs::GetInt(const std::string& key,
59 int default_value) const { 57 int default_value) const {
60 const Value* value; 58 const Value* value;
61 int result = default_value; 59 int result = default_value;
62 if (prefs_->GetValue(key, &value) != PersistentPrefStore::READ_OK || 60 if (!prefs_->GetValue(key, &value) || !value->GetAsInteger(&result))
63 !value->GetAsInteger(&result)) {
64 return default_value; 61 return default_value;
65 } 62
66 return result; 63 return result;
67 } 64 }
68 65
69 void ServiceProcessPrefs::SetInt(const std::string& key, int value) { 66 void ServiceProcessPrefs::SetInt(const std::string& key, int value) {
70 prefs_->SetValue(key, Value::CreateIntegerValue(value)); 67 prefs_->SetValue(key, Value::CreateIntegerValue(value));
71 } 68 }
72 69
73 const DictionaryValue* ServiceProcessPrefs::GetDictionary( 70 const DictionaryValue* ServiceProcessPrefs::GetDictionary(
74 const std::string& key) const { 71 const std::string& key) const {
75 const Value* value; 72 const Value* value;
76 if (prefs_->GetValue(key, &value) != PersistentPrefStore::READ_OK || 73 if (!prefs_->GetValue(key, &value) ||
77 !value->IsType(Value::TYPE_DICTIONARY)) { 74 !value->IsType(Value::TYPE_DICTIONARY)) {
78 return NULL; 75 return NULL;
79 } 76 }
80 77
81 return static_cast<const DictionaryValue*>(value); 78 return static_cast<const DictionaryValue*>(value);
82 } 79 }
83 80
84 const base::ListValue* ServiceProcessPrefs::GetList( 81 const base::ListValue* ServiceProcessPrefs::GetList(
85 const std::string& key) const { 82 const std::string& key) const {
86 const Value* value; 83 const Value* value;
87 if (prefs_->GetValue(key, &value) != PersistentPrefStore::READ_OK || 84 if (!prefs_->GetValue(key, &value) || !value->IsType(Value::TYPE_LIST))
88 !value->IsType(Value::TYPE_LIST)) { 85 return NULL;
89 return NULL;
90 }
91 86
92 return static_cast<const ListValue*>(value); 87 return static_cast<const ListValue*>(value);
93 } 88 }
94 89
95 void ServiceProcessPrefs::SetValue(const std::string& key, base::Value* value) { 90 void ServiceProcessPrefs::SetValue(const std::string& key, base::Value* value) {
96 prefs_->SetValue(key, value); 91 prefs_->SetValue(key, value);
97 } 92 }
98 93
99 void ServiceProcessPrefs::RemovePref(const std::string& key) { 94 void ServiceProcessPrefs::RemovePref(const std::string& key) {
100 prefs_->RemoveValue(key); 95 prefs_->RemoveValue(key);
101 } 96 }
102 97
OLDNEW
« no previous file with comments | « chrome/browser/sync/credential_cache_service_win.cc ('k') | chrome/test/base/testing_pref_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698