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

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

Issue 10958052: Removed unnecessary returning by reference. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months 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/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_(new JsonPrefStore(pref_filename, file_message_loop_proxy)) { 12 : prefs_(new JsonPrefStore(pref_filename, file_message_loop_proxy)) {
13 } 13 }
14 14
15 ServiceProcessPrefs::~ServiceProcessPrefs() {} 15 ServiceProcessPrefs::~ServiceProcessPrefs() {}
16 16
17 void ServiceProcessPrefs::ReadPrefs() { 17 void ServiceProcessPrefs::ReadPrefs() {
18 prefs_->ReadPrefs(); 18 prefs_->ReadPrefs();
19 } 19 }
20 20
21 void ServiceProcessPrefs::WritePrefs() { 21 void ServiceProcessPrefs::WritePrefs() {
22 prefs_->CommitPendingWrite(); 22 prefs_->CommitPendingWrite();
23 } 23 }
24 24
25 void ServiceProcessPrefs::GetString(const std::string& key, 25 std::string ServiceProcessPrefs::GetString(const std::string& key,
26 std::string* result) const { 26 const std::string& default) const {
27 const Value* value; 27 const Value* value;
28 if (prefs_->GetValue(key, &value) == PersistentPrefStore::READ_OK) 28 std::string result;
29 value->GetAsString(result); 29 if (prefs_->GetValue(key, &value) != PersistentPrefStore::READ_OK ||
30 !value->GetAsString(&result)) {
31 return default;
32 }
33 return result;
30 } 34 }
31 35
32 void ServiceProcessPrefs::SetString(const std::string& key, 36 void ServiceProcessPrefs::SetString(const std::string& key,
33 const std::string& value) { 37 const std::string& value) {
34 prefs_->SetValue(key, Value::CreateStringValue(value)); 38 prefs_->SetValue(key, Value::CreateStringValue(value));
35 } 39 }
36 40
37 void ServiceProcessPrefs::GetBoolean(const std::string& key, 41 bool ServiceProcessPrefs::GetBoolean(const std::string& key,
38 bool* result) const { 42 bool default) const {
39 const Value* value; 43 const Value* value;
40 if (prefs_->GetValue(key, &value) == PersistentPrefStore::READ_OK) 44 bool result = false;
41 value->GetAsBoolean(result); 45 if (prefs_->GetValue(key, &value) != PersistentPrefStore::READ_OK ||
46 !value->GetAsBoolean(&result)) {
47 return default;
48 }
49 return result;
42 } 50 }
43 51
44 void ServiceProcessPrefs::SetBoolean(const std::string& key, bool value) { 52 void ServiceProcessPrefs::SetBoolean(const std::string& key, bool value) {
45 prefs_->SetValue(key, Value::CreateBooleanValue(value)); 53 prefs_->SetValue(key, Value::CreateBooleanValue(value));
46 } 54 }
47 55
48 void ServiceProcessPrefs::GetDictionary(const std::string& key, 56 const DictionaryValue* ServiceProcessPrefs::GetDictionary(
49 const DictionaryValue** result) const { 57 const std::string& key) const {
58 const Value* value;
59 const DictionaryValue* result = NULL;
60 if (prefs_->GetValue(key, &value) != PersistentPrefStore::READ_OK ||
61 !value->IsType(Value::TYPE_DICTIONARY)) {
62 return NULL;
63 }
64
65 return static_cast<const DictionaryValue*>(value);
66 }
67
68 const base::ListValue* ServiceProcessPrefs::GetList(
69 const std::string& key) const {
50 const Value* value; 70 const Value* value;
51 if (prefs_->GetValue(key, &value) != PersistentPrefStore::READ_OK || 71 if (prefs_->GetValue(key, &value) != PersistentPrefStore::READ_OK ||
52 !value->IsType(Value::TYPE_DICTIONARY)) { 72 !value->IsType(Value::TYPE_LIST)) {
53 return; 73 return NULL;
54 } 74 }
55 75
56 *result = static_cast<const DictionaryValue*>(value); 76 return static_cast<const ListValue*>(value);
57 } 77 }
58 78
59 void ServiceProcessPrefs::RemovePref(const std::string& key) { 79 void ServiceProcessPrefs::RemovePref(const std::string& key) {
60 prefs_->RemoveValue(key); 80 prefs_->RemoveValue(key);
61 } 81 }
82
OLDNEW
« chrome/service/cloud_print/connector_settings.cc ('K') | « chrome/service/service_process_prefs.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698