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

Unified Diff: components/prefs/pref_service.cc

Issue 2276043004: Add PrefMember<base::Time> Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add PrefService::{Get,Set}Time(..., base::Time) Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/prefs/pref_service.h ('k') | components/prefs/pref_service_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/prefs/pref_service.cc
diff --git a/components/prefs/pref_service.cc b/components/prefs/pref_service.cc
index 4891ff59c669af84f3e3cb987932e27142f77e07..ed1e046bb7a408f9c742df1a5e712c74bc672f4e 100644
--- a/components/prefs/pref_service.cc
+++ b/components/prefs/pref_service.cc
@@ -188,6 +188,22 @@ base::FilePath PrefService::GetFilePath(const std::string& path) const {
return result;
}
+base::Time PrefService::GetTime(const std::string& path) const {
+ DCHECK(CalledOnValidThread());
+
+ const base::Value* value = GetPreferenceValue(path);
+ if (!value) {
+ NOTREACHED() << "Trying to read an unregistered pref: " << path;
+ return base::Time();
+ }
+ std::string value_string;
+ int64_t value_int = 0;
+ bool rv = (value->GetAsString(&value_string) &&
+ base::StringToInt64(value_string, &value_int));
+ DCHECK(rv);
+ return base::Time::FromInternalValue(value_int);
+}
+
bool PrefService::HasPrefPath(const std::string& path) const {
const Preference* pref = FindPreference(path);
return pref && !pref->IsDefaultValue();
@@ -409,6 +425,11 @@ void PrefService::SetFilePath(const std::string& path,
SetUserPrefValue(path, base::CreateFilePathValue(value));
}
+void PrefService::SetTime(const std::string& path, base::Time value) {
+ SetUserPrefValue(path, new base::StringValue(
+ base::Int64ToString(value.ToInternalValue())));
+}
+
void PrefService::SetInt64(const std::string& path, int64_t value) {
SetUserPrefValue(path, new base::StringValue(base::Int64ToString(value)));
}
« no previous file with comments | « components/prefs/pref_service.h ('k') | components/prefs/pref_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698