Commit c6786b33 authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Fix Value::GetDouble() crash in SessionDurationUpdater

It looks like occasionally the kObservedSessionTime pref is corrupt or
otherwise incorrect, resulting in a crash upon a Value::GetDouble()
call on a value in the dictionary. This should fix the crash by
verifying the value type.

Bug: 942397
Change-Id: I15389c725dc61d96b12912dbc21ed9e69648852d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1529719Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Cr-Commit-Position: refs/heads/master@{#642274}
parent a0442b9b
......@@ -40,9 +40,8 @@ base::TimeDelta SessionDurationUpdater::GetCumulativeElapsedSessionTime()
base::TimeDelta SessionDurationUpdater::GetRecordedObservedSessionTime() const {
const base::DictionaryValue* dict =
pref_service_->GetDictionary(prefs::kObservedSessionTime);
const base::Value* dict_value =
dict->FindKey(observed_session_time_dict_key_);
const double stored_value = dict_value ? dict_value->GetDouble() : 0L;
const double stored_value =
dict->FindDoubleKey(observed_session_time_dict_key_).value_or(0);
return base::TimeDelta::FromSeconds(stored_value);
}
......@@ -85,9 +84,8 @@ void SessionDurationUpdater::OnSessionEnded(base::TimeDelta elapsed) {
const base::DictionaryValue* dict =
pref_service_->GetDictionary(prefs::kObservedSessionTime);
const base::Value* dict_value =
dict->FindKey(observed_session_time_dict_key_);
const double stored_value = dict_value ? dict_value->GetDouble() : 0L;
const double stored_value =
dict->FindDoubleKey(observed_session_time_dict_key_).value_or(0);
base::TimeDelta elapsed_session_time =
base::TimeDelta::FromSeconds(stored_value) + elapsed;
......
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