OLD | NEW |
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" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 const base::Value* value = GetPreferenceValue(path); | 181 const base::Value* value = GetPreferenceValue(path); |
182 if (!value) { | 182 if (!value) { |
183 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 183 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
184 return base::FilePath(result); | 184 return base::FilePath(result); |
185 } | 185 } |
186 bool rv = base::GetValueAsFilePath(*value, &result); | 186 bool rv = base::GetValueAsFilePath(*value, &result); |
187 DCHECK(rv); | 187 DCHECK(rv); |
188 return result; | 188 return result; |
189 } | 189 } |
190 | 190 |
| 191 base::Time PrefService::GetTime(const std::string& path) const { |
| 192 DCHECK(CalledOnValidThread()); |
| 193 |
| 194 const base::Value* value = GetPreferenceValue(path); |
| 195 if (!value) { |
| 196 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
| 197 return base::Time(); |
| 198 } |
| 199 std::string value_string; |
| 200 int64_t value_int = 0; |
| 201 bool rv = (value->GetAsString(&value_string) && |
| 202 base::StringToInt64(value_string, &value_int)); |
| 203 DCHECK(rv); |
| 204 return base::Time::FromInternalValue(value_int); |
| 205 } |
| 206 |
191 bool PrefService::HasPrefPath(const std::string& path) const { | 207 bool PrefService::HasPrefPath(const std::string& path) const { |
192 const Preference* pref = FindPreference(path); | 208 const Preference* pref = FindPreference(path); |
193 return pref && !pref->IsDefaultValue(); | 209 return pref && !pref->IsDefaultValue(); |
194 } | 210 } |
195 | 211 |
196 std::unique_ptr<base::DictionaryValue> PrefService::GetPreferenceValues() | 212 std::unique_ptr<base::DictionaryValue> PrefService::GetPreferenceValues() |
197 const { | 213 const { |
198 DCHECK(CalledOnValidThread()); | 214 DCHECK(CalledOnValidThread()); |
199 std::unique_ptr<base::DictionaryValue> out(new base::DictionaryValue); | 215 std::unique_ptr<base::DictionaryValue> out(new base::DictionaryValue); |
200 for (const auto& it : *pref_registry_) { | 216 for (const auto& it : *pref_registry_) { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 | 418 |
403 void PrefService::SetString(const std::string& path, const std::string& value) { | 419 void PrefService::SetString(const std::string& path, const std::string& value) { |
404 SetUserPrefValue(path, new base::StringValue(value)); | 420 SetUserPrefValue(path, new base::StringValue(value)); |
405 } | 421 } |
406 | 422 |
407 void PrefService::SetFilePath(const std::string& path, | 423 void PrefService::SetFilePath(const std::string& path, |
408 const base::FilePath& value) { | 424 const base::FilePath& value) { |
409 SetUserPrefValue(path, base::CreateFilePathValue(value)); | 425 SetUserPrefValue(path, base::CreateFilePathValue(value)); |
410 } | 426 } |
411 | 427 |
| 428 void PrefService::SetTime(const std::string& path, base::Time value) { |
| 429 SetUserPrefValue(path, new base::StringValue( |
| 430 base::Int64ToString(value.ToInternalValue()))); |
| 431 } |
| 432 |
412 void PrefService::SetInt64(const std::string& path, int64_t value) { | 433 void PrefService::SetInt64(const std::string& path, int64_t value) { |
413 SetUserPrefValue(path, new base::StringValue(base::Int64ToString(value))); | 434 SetUserPrefValue(path, new base::StringValue(base::Int64ToString(value))); |
414 } | 435 } |
415 | 436 |
416 int64_t PrefService::GetInt64(const std::string& path) const { | 437 int64_t PrefService::GetInt64(const std::string& path) const { |
417 DCHECK(CalledOnValidThread()); | 438 DCHECK(CalledOnValidThread()); |
418 | 439 |
419 const base::Value* value = GetPreferenceValue(path); | 440 const base::Value* value = GetPreferenceValue(path); |
420 if (!value) { | 441 if (!value) { |
421 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 442 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 DCHECK(found_value->IsType(default_type)); | 634 DCHECK(found_value->IsType(default_type)); |
614 return found_value; | 635 return found_value; |
615 } else { | 636 } else { |
616 // Every registered preference has at least a default value. | 637 // Every registered preference has at least a default value. |
617 NOTREACHED() << "no valid value found for registered pref " << path; | 638 NOTREACHED() << "no valid value found for registered pref " << path; |
618 } | 639 } |
619 } | 640 } |
620 | 641 |
621 return NULL; | 642 return NULL; |
622 } | 643 } |
OLD | NEW |