Skip to content

Commit

Permalink
Use SetKey instead of SetPath when path is a key (#635)
Browse files Browse the repository at this point in the history
This is to avoid running into the DCHECK that Value::SetPath has to
enforce that the std::initializer_list<StringPiece> path param has a
length >= 2.

The caller currently constructs an initializer list with only one object
-- and SetPath() just calls SetKey() for the last object in the list --
so there shouldn't be any functional change here.

b/268553897

Change-Id: I3df2cfec34ba61eaad2391c8baa1113ca999e14a
  • Loading branch information
hlwarriner committed Jun 15, 2023
1 parent 5da8bd4 commit b28a4b3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions components/prefs/json_pref_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,13 @@ void JsonPrefStore::SetValue(const std::string& key,
base::Value* old_value = nullptr;
prefs_->Get(key, &old_value);
if (!old_value || !value->Equals(old_value)) {
#if defined(STARBOARD)
// Value::DictionaryValue::Set creates a nested dictionary treating a URL
// key as a path, SetKey avoids this.
prefs_->SetKey(key, std::move(*value.get()));
prefs_->SetKey(key, base::Value::FromUniquePtrValue(std::move(value)));
#else
prefs_->Set(key, std::move(value));
#endif
ReportValueChanged(key, flags);
}
}
Expand All @@ -222,7 +226,11 @@ void JsonPrefStore::SetValueSilently(const std::string& key,
base::Value* old_value = nullptr;
prefs_->Get(key, &old_value);
if (!old_value || !value->Equals(old_value)) {
prefs_->SetPath({key}, base::Value::FromUniquePtrValue(std::move(value)));
#if defined(STARBOARD)
prefs_->SetKey(key, base::Value::FromUniquePtrValue(std::move(value)));
#else
prefs_->Set(key, std::move(value));
#endif
ScheduleWrite(flags);
}
}
Expand Down

0 comments on commit b28a4b3

Please sign in to comment.