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

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

Issue 1899083002: Convert //chrome from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 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
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 <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h"
9 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
10 #include "base/values.h" 11 #include "base/values.h"
11 #include "components/prefs/pref_filter.h" 12 #include "components/prefs/pref_filter.h"
12 13
13 ServiceProcessPrefs::ServiceProcessPrefs( 14 ServiceProcessPrefs::ServiceProcessPrefs(const base::FilePath& pref_filename,
14 const base::FilePath& pref_filename, 15 base::SequencedTaskRunner* task_runner)
15 base::SequencedTaskRunner* task_runner)
16 : prefs_(new JsonPrefStore(pref_filename, 16 : prefs_(new JsonPrefStore(pref_filename,
17 task_runner, 17 task_runner,
18 scoped_ptr<PrefFilter>())) { 18 std::unique_ptr<PrefFilter>())) {}
19 }
20 19
21 ServiceProcessPrefs::~ServiceProcessPrefs() {} 20 ServiceProcessPrefs::~ServiceProcessPrefs() {}
22 21
23 void ServiceProcessPrefs::ReadPrefs() { 22 void ServiceProcessPrefs::ReadPrefs() {
24 prefs_->ReadPrefs(); 23 prefs_->ReadPrefs();
25 } 24 }
26 25
27 void ServiceProcessPrefs::WritePrefs() { 26 void ServiceProcessPrefs::WritePrefs() {
28 prefs_->CommitPendingWrite(); 27 prefs_->CommitPendingWrite();
29 } 28 }
30 29
31 std::string ServiceProcessPrefs::GetString( 30 std::string ServiceProcessPrefs::GetString(
32 const std::string& key, 31 const std::string& key,
33 const std::string& default_value) const { 32 const std::string& default_value) const {
34 const base::Value* value; 33 const base::Value* value;
35 std::string result; 34 std::string result;
36 if (!prefs_->GetValue(key, &value) || !value->GetAsString(&result)) 35 if (!prefs_->GetValue(key, &value) || !value->GetAsString(&result))
37 return default_value; 36 return default_value;
38 37
39 return result; 38 return result;
40 } 39 }
41 40
42 void ServiceProcessPrefs::SetString(const std::string& key, 41 void ServiceProcessPrefs::SetString(const std::string& key,
43 const std::string& value) { 42 const std::string& value) {
44 prefs_->SetValue(key, make_scoped_ptr(new base::StringValue(value)), 43 prefs_->SetValue(key, base::WrapUnique(new base::StringValue(value)),
45 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 44 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
46 } 45 }
47 46
48 bool ServiceProcessPrefs::GetBoolean(const std::string& key, 47 bool ServiceProcessPrefs::GetBoolean(const std::string& key,
49 bool default_value) const { 48 bool default_value) const {
50 const base::Value* value; 49 const base::Value* value;
51 bool result = false; 50 bool result = false;
52 if (!prefs_->GetValue(key, &value) || !value->GetAsBoolean(&result)) 51 if (!prefs_->GetValue(key, &value) || !value->GetAsBoolean(&result))
53 return default_value; 52 return default_value;
54 53
55 return result; 54 return result;
56 } 55 }
57 56
58 void ServiceProcessPrefs::SetBoolean(const std::string& key, bool value) { 57 void ServiceProcessPrefs::SetBoolean(const std::string& key, bool value) {
59 prefs_->SetValue(key, make_scoped_ptr(new base::FundamentalValue(value)), 58 prefs_->SetValue(key, base::WrapUnique(new base::FundamentalValue(value)),
60 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 59 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
61 } 60 }
62 61
63 int ServiceProcessPrefs::GetInt(const std::string& key, 62 int ServiceProcessPrefs::GetInt(const std::string& key,
64 int default_value) const { 63 int default_value) const {
65 const base::Value* value; 64 const base::Value* value;
66 int result = default_value; 65 int result = default_value;
67 if (!prefs_->GetValue(key, &value) || !value->GetAsInteger(&result)) 66 if (!prefs_->GetValue(key, &value) || !value->GetAsInteger(&result))
68 return default_value; 67 return default_value;
69 68
70 return result; 69 return result;
71 } 70 }
72 71
73 void ServiceProcessPrefs::SetInt(const std::string& key, int value) { 72 void ServiceProcessPrefs::SetInt(const std::string& key, int value) {
74 prefs_->SetValue(key, make_scoped_ptr(new base::FundamentalValue(value)), 73 prefs_->SetValue(key, base::WrapUnique(new base::FundamentalValue(value)),
75 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 74 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
76 } 75 }
77 76
78 const base::DictionaryValue* ServiceProcessPrefs::GetDictionary( 77 const base::DictionaryValue* ServiceProcessPrefs::GetDictionary(
79 const std::string& key) const { 78 const std::string& key) const {
80 const base::Value* value; 79 const base::Value* value;
81 if (!prefs_->GetValue(key, &value) || 80 if (!prefs_->GetValue(key, &value) ||
82 !value->IsType(base::Value::TYPE_DICTIONARY)) { 81 !value->IsType(base::Value::TYPE_DICTIONARY)) {
83 return NULL; 82 return NULL;
84 } 83 }
85 84
86 return static_cast<const base::DictionaryValue*>(value); 85 return static_cast<const base::DictionaryValue*>(value);
87 } 86 }
88 87
89 const base::ListValue* ServiceProcessPrefs::GetList( 88 const base::ListValue* ServiceProcessPrefs::GetList(
90 const std::string& key) const { 89 const std::string& key) const {
91 const base::Value* value; 90 const base::Value* value;
92 if (!prefs_->GetValue(key, &value) || !value->IsType(base::Value::TYPE_LIST)) 91 if (!prefs_->GetValue(key, &value) || !value->IsType(base::Value::TYPE_LIST))
93 return NULL; 92 return NULL;
94 93
95 return static_cast<const base::ListValue*>(value); 94 return static_cast<const base::ListValue*>(value);
96 } 95 }
97 96
98 void ServiceProcessPrefs::SetValue(const std::string& key, 97 void ServiceProcessPrefs::SetValue(const std::string& key,
99 scoped_ptr<base::Value> value) { 98 std::unique_ptr<base::Value> value) {
100 prefs_->SetValue(key, std::move(value), 99 prefs_->SetValue(key, std::move(value),
101 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 100 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
102 } 101 }
103 102
104 void ServiceProcessPrefs::RemovePref(const std::string& key) { 103 void ServiceProcessPrefs::RemovePref(const std::string& key) {
105 prefs_->RemoveValue(key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 104 prefs_->RemoveValue(key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
106 } 105 }
107 106
OLDNEW
« no previous file with comments | « chrome/service/service_process_prefs.h ('k') | chrome/service/service_process_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698