Commit 84df3b8d authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

UMA: use SetTime/GetTime for persisted values

Following the guidance at https://crbug.com/634507#c45, this swaps out
spots which use ToInternalValue/FromInternalValue for persisting a
base::Time in prefs, in favor of PrefService::SetTime()/GetTime().

I verified these internally use From/ToDeltaSinceWindowsEpoch(), which
is consistent with the internal implementation of base::Time.

Bug: 1010369
Test: None
Change-Id: I6a7ba2e93610702e33482eb830bb34ef61a50f89
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1839634Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703463}
parent 99fe0c17
...@@ -208,9 +208,8 @@ void FileMetricsProvider::RegisterSource(const Params& params) { ...@@ -208,9 +208,8 @@ void FileMetricsProvider::RegisterSource(const Params& params) {
// |prefs_key| may be empty if the caller does not wish to persist the // |prefs_key| may be empty if the caller does not wish to persist the
// state across instances of the program. // state across instances of the program.
if (pref_service_ && !params.prefs_key.empty()) { if (pref_service_ && !params.prefs_key.empty()) {
source->last_seen = base::Time::FromInternalValue( source->last_seen = pref_service_->GetTime(
pref_service_->GetInt64(metrics::prefs::kMetricsLastSeenPrefix + metrics::prefs::kMetricsLastSeenPrefix + source->prefs_key);
source->prefs_key));
} }
switch (params.association) { switch (params.association) {
...@@ -696,9 +695,9 @@ void FileMetricsProvider::RecordSourceAsRead(SourceInfo* source) { ...@@ -696,9 +695,9 @@ void FileMetricsProvider::RecordSourceAsRead(SourceInfo* source) {
// Persistently record the "last seen" timestamp of the source file to // Persistently record the "last seen" timestamp of the source file to
// ensure that the file is never read again unless it is modified again. // ensure that the file is never read again unless it is modified again.
if (pref_service_ && !source->prefs_key.empty()) { if (pref_service_ && !source->prefs_key.empty()) {
pref_service_->SetInt64( pref_service_->SetTime(
metrics::prefs::kMetricsLastSeenPrefix + source->prefs_key, metrics::prefs::kMetricsLastSeenPrefix + source->prefs_key,
source->last_seen.ToInternalValue()); source->last_seen);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment