1 // Copyright 2020 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef ASH_LOGIN_SECURITY_TOKEN_REQUEST_CONTROLLER_H_
6 #define ASH_LOGIN_SECURITY_TOKEN_REQUEST_CONTROLLER_H_
8 #include "ash/login/ui/pin_request_view.h"
9 #include "ash/public/cpp/login_types.h"
10 #include "base/memory/weak_ptr.h"
14 // SecurityTokenRequestController serves as a single point of access to ask the
15 // user for a PIN for a security token request.
16 class ASH_EXPORT SecurityTokenRequestController
17 : public PinRequestView::Delegate {
19 SecurityTokenRequestController();
20 SecurityTokenRequestController(const SecurityTokenRequestController&) =
22 SecurityTokenRequestController& operator=(
23 const SecurityTokenRequestController&) = delete;
24 ~SecurityTokenRequestController() override;
26 bool request_canceled() const { return request_canceled_; }
27 void ResetRequestCanceled();
29 // PinRequestView::Delegate interface.
30 PinRequestView::SubmissionResult OnPinSubmitted(
31 const std::string& pin) override;
32 void OnBack() override;
33 void OnHelp() override;
35 // Shows the PIN dialog configured by |request|. If there already is a
36 // SecurityTokenPinRequest in progress, keeps the dialog open and updates the
38 // Returns true if the dialog was opened or updated successfully, false
39 // otherwise. The request will fail if the PIN UI is currently in use for
40 // something other than a SecurityTokenPinRequest.
41 bool SetPinUiState(SecurityTokenPinRequest request);
43 // Closes the UI and resets callbacks.
47 // Called when the user submits the input. Will not be called if the UI is
48 // closed before that happens.
49 SecurityTokenPinRequest::OnPinEntered on_pin_submitted_;
51 // Called when the PIN request UI gets closed by the user (back button).
52 SecurityTokenPinRequest::OnUiClosed on_canceled_by_user_;
54 // Whether this controller is currently using PinRequestWidget.
55 bool security_token_request_in_progress_ = false;
57 // Whether the user has recently canceled a PIN request.
58 bool request_canceled_ = false;
60 base::WeakPtrFactory<SecurityTokenRequestController> weak_factory_{this};
65 #endif // ASH_LOGIN_SECURITY_TOKEN_REQUEST_CONTROLLER_H_