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

Side by Side Diff: components/prefs/pref_service.cc

Issue 1907043002: Convert //components/prefs from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IWYU fixes 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "components/prefs/pref_service.h" 5 #include "components/prefs/pref_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/ptr_util.h"
14 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
15 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
16 #include "base/stl_util.h" 17 #include "base/stl_util.h"
17 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
19 #include "base/thread_task_runner_handle.h" 20 #include "base/thread_task_runner_handle.h"
20 #include "base/value_conversions.h" 21 #include "base/value_conversions.h"
21 #include "build/build_config.h" 22 #include "build/build_config.h"
22 #include "components/prefs/default_pref_store.h" 23 #include "components/prefs/default_pref_store.h"
23 #include "components/prefs/pref_notifier_impl.h" 24 #include "components/prefs/pref_notifier_impl.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 bool rv = base::GetValueAsFilePath(*value, &result); 186 bool rv = base::GetValueAsFilePath(*value, &result);
186 DCHECK(rv); 187 DCHECK(rv);
187 return result; 188 return result;
188 } 189 }
189 190
190 bool PrefService::HasPrefPath(const std::string& path) const { 191 bool PrefService::HasPrefPath(const std::string& path) const {
191 const Preference* pref = FindPreference(path); 192 const Preference* pref = FindPreference(path);
192 return pref && !pref->IsDefaultValue(); 193 return pref && !pref->IsDefaultValue();
193 } 194 }
194 195
195 scoped_ptr<base::DictionaryValue> PrefService::GetPreferenceValues() const { 196 std::unique_ptr<base::DictionaryValue> PrefService::GetPreferenceValues()
197 const {
196 DCHECK(CalledOnValidThread()); 198 DCHECK(CalledOnValidThread());
197 scoped_ptr<base::DictionaryValue> out(new base::DictionaryValue); 199 std::unique_ptr<base::DictionaryValue> out(new base::DictionaryValue);
198 for (const auto& it : *pref_registry_) { 200 for (const auto& it : *pref_registry_) {
199 out->Set(it.first, GetPreferenceValue(it.first)->CreateDeepCopy()); 201 out->Set(it.first, GetPreferenceValue(it.first)->CreateDeepCopy());
200 } 202 }
201 return out; 203 return out;
202 } 204 }
203 205
204 scoped_ptr<base::DictionaryValue> PrefService::GetPreferenceValuesOmitDefaults() 206 std::unique_ptr<base::DictionaryValue>
205 const { 207 PrefService::GetPreferenceValuesOmitDefaults() const {
206 DCHECK(CalledOnValidThread()); 208 DCHECK(CalledOnValidThread());
207 scoped_ptr<base::DictionaryValue> out(new base::DictionaryValue); 209 std::unique_ptr<base::DictionaryValue> out(new base::DictionaryValue);
208 for (const auto& it : *pref_registry_) { 210 for (const auto& it : *pref_registry_) {
209 const Preference* pref = FindPreference(it.first); 211 const Preference* pref = FindPreference(it.first);
210 if (pref->IsDefaultValue()) 212 if (pref->IsDefaultValue())
211 continue; 213 continue;
212 out->Set(it.first, pref->GetValue()->CreateDeepCopy()); 214 out->Set(it.first, pref->GetValue()->CreateDeepCopy());
213 } 215 }
214 return out; 216 return out;
215 } 217 }
216 218
217 scoped_ptr<base::DictionaryValue> 219 std::unique_ptr<base::DictionaryValue>
218 PrefService::GetPreferenceValuesWithoutPathExpansion() const { 220 PrefService::GetPreferenceValuesWithoutPathExpansion() const {
219 DCHECK(CalledOnValidThread()); 221 DCHECK(CalledOnValidThread());
220 scoped_ptr<base::DictionaryValue> out(new base::DictionaryValue); 222 std::unique_ptr<base::DictionaryValue> out(new base::DictionaryValue);
221 for (const auto& it : *pref_registry_) { 223 for (const auto& it : *pref_registry_) {
222 const base::Value* value = GetPreferenceValue(it.first); 224 const base::Value* value = GetPreferenceValue(it.first);
223 DCHECK(value); 225 DCHECK(value);
224 out->SetWithoutPathExpansion(it.first, value->CreateDeepCopy()); 226 out->SetWithoutPathExpansion(it.first, value->CreateDeepCopy());
225 } 227 }
226 return out; 228 return out;
227 } 229 }
228 230
229 const PrefService::Preference* PrefService::FindPreference( 231 const PrefService::Preference* PrefService::FindPreference(
230 const std::string& pref_name) const { 232 const std::string& pref_name) const {
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 base::Value* value = NULL; 471 base::Value* value = NULL;
470 if (!user_pref_store_->GetMutableValue(path, &value) || 472 if (!user_pref_store_->GetMutableValue(path, &value) ||
471 !value->IsType(type)) { 473 !value->IsType(type)) {
472 if (type == base::Value::TYPE_DICTIONARY) { 474 if (type == base::Value::TYPE_DICTIONARY) {
473 value = new base::DictionaryValue; 475 value = new base::DictionaryValue;
474 } else if (type == base::Value::TYPE_LIST) { 476 } else if (type == base::Value::TYPE_LIST) {
475 value = new base::ListValue; 477 value = new base::ListValue;
476 } else { 478 } else {
477 NOTREACHED(); 479 NOTREACHED();
478 } 480 }
479 user_pref_store_->SetValueSilently(path, make_scoped_ptr(value), 481 user_pref_store_->SetValueSilently(path, base::WrapUnique(value),
480 GetWriteFlags(pref)); 482 GetWriteFlags(pref));
481 } 483 }
482 return value; 484 return value;
483 } 485 }
484 486
485 void PrefService::ReportUserPrefChanged(const std::string& key) { 487 void PrefService::ReportUserPrefChanged(const std::string& key) {
486 DCHECK(CalledOnValidThread()); 488 DCHECK(CalledOnValidThread());
487 user_pref_store_->ReportValueChanged(key, GetWriteFlags(FindPreference(key))); 489 user_pref_store_->ReportValueChanged(key, GetWriteFlags(FindPreference(key)));
488 } 490 }
489 491
490 void PrefService::SetUserPrefValue(const std::string& path, 492 void PrefService::SetUserPrefValue(const std::string& path,
491 base::Value* new_value) { 493 base::Value* new_value) {
492 scoped_ptr<base::Value> owned_value(new_value); 494 std::unique_ptr<base::Value> owned_value(new_value);
493 DCHECK(CalledOnValidThread()); 495 DCHECK(CalledOnValidThread());
494 496
495 const Preference* pref = FindPreference(path); 497 const Preference* pref = FindPreference(path);
496 if (!pref) { 498 if (!pref) {
497 NOTREACHED() << "Trying to write an unregistered pref: " << path; 499 NOTREACHED() << "Trying to write an unregistered pref: " << path;
498 return; 500 return;
499 } 501 }
500 if (pref->GetType() != new_value->GetType()) { 502 if (pref->GetType() != new_value->GetType()) {
501 NOTREACHED() << "Trying to set pref " << path 503 NOTREACHED() << "Trying to set pref " << path
502 << " of type " << pref->GetType() 504 << " of type " << pref->GetType()
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 DCHECK(found_value->IsType(default_type)); 613 DCHECK(found_value->IsType(default_type));
612 return found_value; 614 return found_value;
613 } else { 615 } else {
614 // Every registered preference has at least a default value. 616 // Every registered preference has at least a default value.
615 NOTREACHED() << "no valid value found for registered pref " << path; 617 NOTREACHED() << "no valid value found for registered pref " << path;
616 } 618 }
617 } 619 }
618 620
619 return NULL; 621 return NULL;
620 } 622 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698