[iOS] ProfileAttributesStorageIOS: Prevent inserting duplicates
...by using lower_bound instead of upper_bound to find the insertion point (and check that it's not equal to the to-be-inserted element). upper_bound returns the first existing element that is *larger* than the new one, so if there's a duplicate, it will return the one just past that. lower_bound, on the other hand, will return the duplicate as intended. (In the common case where there's no duplicate, the two are equivalent.) Bug: none Change-Id: I16c19a1fbf1d14702d2673cf0c5c6e03ed7925d9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6038942 Commit-Queue: Marc Treib <treib@chromium.org> Reviewed-by: Sylvain Defresne <sdefresne@chromium.org> Cr-Commit-Position: refs/heads/main@{#1387503}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
f6b12f777c
commit
2df1392168
ios/chrome/browser/shared/model/profile
@ -40,7 +40,7 @@ ProfileAttributesStorageIOS::~ProfileAttributesStorageIOS() = default;
|
||||
|
||||
void ProfileAttributesStorageIOS::AddProfile(std::string_view name) {
|
||||
// Inserts the profile name in sorted position.
|
||||
auto iterator = base::ranges::upper_bound(sorted_keys_, name);
|
||||
auto iterator = base::ranges::lower_bound(sorted_keys_, name);
|
||||
CHECK(iterator == sorted_keys_.end() || *iterator != name);
|
||||
sorted_keys_.insert(iterator, std::string(name));
|
||||
|
||||
|
@ -36,10 +36,12 @@ class ProfileAttributesStorageIOS {
|
||||
|
||||
~ProfileAttributesStorageIOS();
|
||||
|
||||
// Register profile with `name`.
|
||||
// Register profile with `name`. No profile with that name must be registered
|
||||
// yet.
|
||||
void AddProfile(std::string_view name);
|
||||
|
||||
// Remove informations about profile with `name`.
|
||||
// Remove information about profile with `name`. A profile with that name
|
||||
// must be registered (and won't be anymore once this method returns).
|
||||
void RemoveProfile(std::string_view name);
|
||||
|
||||
// Returns the count of known profiles.
|
||||
|
Reference in New Issue
Block a user