Commit 00e7301b authored by Balazs Engedy's avatar Balazs Engedy Committed by Commit Bot

Initial AuthenticatorRequestDialogModel state machine.

Bug: 847985
Change-Id: Ibc8ac6cda1aaf9bfb519ba44a4ef748cc3891e1f
Reviewed-on: https://chromium-review.googlesource.com/1101681Reviewed-by: default avatarKim Paulhamus <kpaulhamus@chromium.org>
Commit-Queue: Balazs Engedy <engedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568001}
parent f53a075d
......@@ -198,10 +198,13 @@ void AuthenticatorRequestDialogView::OnModelDestroyed() {
NOTREACHED();
}
void AuthenticatorRequestDialogView::OnRequestComplete() {
if (!GetWidget())
return;
GetWidget()->Close();
void AuthenticatorRequestDialogView::OnStepTransition() {
if (model_->current_step() ==
AuthenticatorRequestDialogModel::Step::kCompleted) {
if (!GetWidget())
return;
GetWidget()->Close();
}
}
void AuthenticatorRequestDialogView::ReplaceCurrentSheetWith(
......
......@@ -62,7 +62,7 @@ class AuthenticatorRequestDialogView
// AuthenticatorRequestDialogModel::Observer:
void OnModelDestroyed() override;
void OnRequestComplete() override;
void OnStepTransition() override;
private:
friend class test::AuthenticatorRequestDialogViewTestApi;
......
......@@ -10,6 +10,41 @@ AuthenticatorRequestDialogModel::~AuthenticatorRequestDialogModel() {
observer.OnModelDestroyed();
}
void AuthenticatorRequestDialogModel::StartGuidedFlowForTransport(
int transport) {
DCHECK_EQ(current_step(), Step::kTransportSelection);
}
void AuthenticatorRequestDialogModel::TryIfBleAdapterIsPowered() {
DCHECK_EQ(current_step(), Step::kBlePowerOnManual);
}
void AuthenticatorRequestDialogModel::PowerOnBleAdapter() {
DCHECK_EQ(current_step(), Step::kBlePowerOnAutomatic);
}
void AuthenticatorRequestDialogModel::StartBleDiscovery() {
DCHECK_EQ(current_step(), Step::kBlePairingBegin);
}
void AuthenticatorRequestDialogModel::InitiatePairingDevice(
const std::string& device_address) {
DCHECK_EQ(current_step(), Step::kBleDeviceSelection);
}
void AuthenticatorRequestDialogModel::FinishPairingWithPin(
const base::string16& pin) {
DCHECK_EQ(current_step(), Step::kBlePinEntry);
}
void AuthenticatorRequestDialogModel::TryUsbDevice() {
DCHECK_EQ(current_step(), Step::kUsbInsert);
}
void AuthenticatorRequestDialogModel::Cancel() {}
void AuthenticatorRequestDialogModel::Back() {}
void AuthenticatorRequestDialogModel::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
......@@ -19,6 +54,11 @@ void AuthenticatorRequestDialogModel::RemoveObserver(Observer* observer) {
}
void AuthenticatorRequestDialogModel::OnRequestComplete() {
current_step_ = Step::kCompleted;
NotifyStepTransition();
}
void AuthenticatorRequestDialogModel::NotifyStepTransition() {
for (auto& observer : observers_)
observer.OnRequestComplete();
observer.OnStepTransition();
}
......@@ -7,13 +7,40 @@
#include "base/observer_list.h"
// Encapsulates the model behind the Web Authentication request dialog.
// Encapsulates the model behind the Web Authentication request dialog's UX
// flow. This is essentially a state machine going through the states defined in
// the `Step` enumeration.
//
// Ultimately, this will become an observer of the AuthenticatorRequest, and
// contain the logic to figure out which steps the user needs to take, in which
// order, to complete the authentication flow.
class AuthenticatorRequestDialogModel {
public:
// Defines the potential steps of the Web Authentication API request UX flow.
enum class Step {
kInitial,
kTransportSelection,
kErrorTimedOut,
kCompleted,
// Universal Serial Bus (USB).
kUsbInsert,
kUsbActivate,
kUsbVerifying,
// Bluetooth Low Energy (BLE).
kBlePowerOnAutomatic,
kBlePowerOnManual,
kBlePairingBegin,
kBleEnterPairingMode,
kBleDeviceSelection,
kBlePinEntry,
kBleActivate,
kBleVerifying,
};
// Implemented by the dialog to observe this model and show the UI panels
// appropriate for the current step.
class Observer {
......@@ -21,13 +48,66 @@ class AuthenticatorRequestDialogModel {
// Called just before the model is destructed.
virtual void OnModelDestroyed() = 0;
// Called when the authentication request completes (successfully or not).
virtual void OnRequestComplete() {}
// Called when the UX flow has navigated to a different step, so the UI
// should update.
virtual void OnStepTransition() {}
};
AuthenticatorRequestDialogModel();
~AuthenticatorRequestDialogModel();
void set_current_step(Step step) { current_step_ = step; }
Step current_step() const { return current_step_; }
// Requests that the step-by-step wizard flow commence, guiding the user
// through using the Secutity Key with the given |transport|.
//
// Valid action when at step: kTransportSelection.
// TODO(engedy): Use AuthenticatorTransport type when ready.
void StartGuidedFlowForTransport(int transport);
// Tries if the BLE adapter is now powered -- the user claims they turned it
// on.
//
// Valid action when at step: kBlePowerOnManual.
void TryIfBleAdapterIsPowered();
// Turns on the BLE adapter automatically.
//
// Valid action when at step: kBlePowerOnAutomatic.
void PowerOnBleAdapter();
// Lets the pairing procedure start after the user learned about the need.
//
// Valid action when at step: kBlePairingBegin.
void StartBleDiscovery();
// Initiates pairing of the device that the user has chosen.
//
// Valid action when at step: kBleDeviceSelection.
void InitiatePairingDevice(const std::string& device_address);
// Finishes pairing of the previously chosen device with the |pin| code
// entered.
//
// Valid action when at step: kBlePinEntry.
void FinishPairingWithPin(const base::string16& pin);
// Tries if a USB device is present -- the user claims they plugged it in.
//
// Valid action when at step: kUsbInsert.
void TryUsbDevice();
// Cancels the flow as a result of the user clicking `Cancel` on the UI.
//
// Valid action at all steps.
void Cancel();
// Backtracks in the flow as a result of the user clicking `Back` on the UI.
//
// Valid action at all steps.
void Back();
// The |observer| must either outlive the object, or unregister itself on its
// destruction.
void AddObserver(Observer* observer);
......@@ -37,6 +117,12 @@ class AuthenticatorRequestDialogModel {
void OnRequestComplete();
private:
// Notifies observers when a step transition has occurred.
void NotifyStepTransition();
// The current step of the request UX flow that is currently shown.
Step current_step_ = Step::kInitial;
base::ObserverList<Observer> observers_;
DISALLOW_COPY_AND_ASSIGN(AuthenticatorRequestDialogModel);
......
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