Commit b47af5d5 authored by Jun Choi's avatar Jun Choi Committed by Commit Bot

Introduce OnAuthenticatorIdChanged() to WebAuthN UI models

When Bluetooth security keys change state from non-pairing mode to
pairing mode, Bluetooth device ID (and corresponding authenticator id)
is changed for security reasons. Currently this is handled by the UI by
removing the authenticator from the UI list and re-adding a
authenticator with an updated id. This is not ideal, as this may cause UI
to flicker. Introduce OnAuthenticatorIdChanged() to
AuthenticatorListObserver so that authenticator id can be changed
without invoking unnecessary UI changes.

Bug: 877344
Change-Id: I9f3328c4b7121864e4e9adfe4567c4e134e3b5a4
Reviewed-on: https://chromium-review.googlesource.com/c/1319673
Commit-Queue: Jun Choi <hongjunchoi@chromium.org>
Reviewed-by: default avatarKim Paulhamus <kpaulhamus@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606109}
parent 91d36d3b
......@@ -16,10 +16,11 @@
namespace {
const std::map<int, std::string>::const_iterator FindElementByValue(
const std::map<int, std::string>& item_map,
std::map<int, std::string>::iterator FindElementByValue(
std::map<int, std::string>* item_map,
base::StringPiece value) {
return std::find_if(item_map.begin(), item_map.end(),
DCHECK(item_map);
return std::find_if(item_map->begin(), item_map->end(),
[value](const auto& key_value_pair) {
return key_value_pair.second == value;
});
......@@ -115,7 +116,7 @@ void BleDeviceHoverListModel::OnAuthenticatorAdded(
void BleDeviceHoverListModel::OnAuthenticatorRemoved(
const AuthenticatorReference& removed_authenticator) {
const auto& authenticator_id = removed_authenticator.authenticator_id();
auto it = FindElementByValue(authenticator_tags_, authenticator_id);
auto it = FindElementByValue(&authenticator_tags_, authenticator_id);
CHECK(it != authenticator_tags_.end());
const auto item_tag = it->first;
authenticator_tags_.erase(it);
......@@ -128,7 +129,7 @@ void BleDeviceHoverListModel::OnAuthenticatorPairingModeChanged(
if (!observer())
return;
auto it = FindElementByValue(authenticator_tags_,
auto it = FindElementByValue(&authenticator_tags_,
changed_authenticator.authenticator_id());
CHECK(it != authenticator_tags_.end());
const auto changed_item_tag = it->first;
......@@ -140,3 +141,11 @@ void BleDeviceHoverListModel::OnAuthenticatorPairingModeChanged(
ListItemChangeType::kRemoveFromViewComponent);
}
}
void BleDeviceHoverListModel::OnAuthenticatorIdChanged(
const AuthenticatorReference& changed_authenticator,
base::StringPiece previous_id) {
auto it = FindElementByValue(&authenticator_tags_, previous_id);
CHECK(it != authenticator_tags_.end());
it->second = changed_authenticator.authenticator_id();
}
......@@ -56,6 +56,13 @@ class BleDeviceHoverListModel : public HoverListModel,
void OnAuthenticatorPairingModeChanged(
const AuthenticatorReference& changed_authenticator) override;
// Invoked when device address(and the corresponding authenticator id) of the
// connected BLE authenticator changes due to authenticator's pairing mode
// change.
void OnAuthenticatorIdChanged(
const AuthenticatorReference& changed_authenticator,
base::StringPiece previous_id) override;
ObservableAuthenticatorList* const authenticator_list_;
Delegate* const delegate_; // Weak, may be nullptr.
......
......@@ -20,6 +20,9 @@ class AuthenticatorListObserver {
const AuthenticatorReference& added_authenticator) = 0;
virtual void OnAuthenticatorRemoved(
const AuthenticatorReference& removed_authenticator) = 0;
virtual void OnAuthenticatorIdChanged(
const AuthenticatorReference& changed_authenticator,
base::StringPiece previous_id) = 0;
virtual void OnAuthenticatorPairingModeChanged(
const AuthenticatorReference& changed_authenticator) = 0;
};
......
......@@ -40,12 +40,9 @@ void ObservableAuthenticatorList::ChangeAuthenticatorId(
if (!authenticator)
return;
if (observer_)
observer_->OnAuthenticatorRemoved(*authenticator);
authenticator->SetAuthenticatorId(std::move(new_id));
if (observer_)
observer_->OnAuthenticatorAdded(*authenticator);
observer_->OnAuthenticatorIdChanged(*authenticator, previous_id);
}
void ObservableAuthenticatorList::ChangeAuthenticatorPairingMode(
......
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