1 // Copyright 2020 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef ASH_LOGIN_SECURITY_TOKEN_REQUEST_CONTROLLER_H_ 6 #define ASH_LOGIN_SECURITY_TOKEN_REQUEST_CONTROLLER_H_ 7 8 #include "ash/login/ui/pin_request_view.h" 9 #include "ash/public/cpp/login_types.h" 10 #include "base/memory/weak_ptr.h" 11 12 namespace ash { 13 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 { 18 public: 19 SecurityTokenRequestController(); 20 SecurityTokenRequestController(const SecurityTokenRequestController&) = 21 delete; 22 SecurityTokenRequestController& operator=( 23 const SecurityTokenRequestController&) = delete; 24 ~SecurityTokenRequestController() override; 25 request_canceled()26 bool request_canceled() const { return request_canceled_; } 27 void ResetRequestCanceled(); 28 29 // PinRequestView::Delegate interface. 30 PinRequestView::SubmissionResult OnPinSubmitted( 31 const std::string& pin) override; 32 void OnBack() override; 33 void OnHelp(gfx::NativeWindow parent_window) override; 34 35 // Shows the PIN dialog configured by |request|. If there already is a 36 // SecurityTokenPinRequest in progress, keeps the dialog open and updates the 37 // dialog's state. 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); 42 43 // Closes the UI and resets callbacks. 44 void ClosePinUi(); 45 46 private: 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_; 50 51 // Called when the PIN request UI gets closed by the user (back button). 52 SecurityTokenPinRequest::OnUiClosed on_canceled_by_user_; 53 54 // Whether this controller is currently using PinRequestWidget. 55 bool security_token_request_in_progress_ = false; 56 57 // Whether the user has recently canceled a PIN request. 58 bool request_canceled_ = false; 59 60 base::WeakPtrFactory<SecurityTokenRequestController> weak_factory_{this}; 61 }; 62 63 } // namespace ash 64 65 #endif // ASH_LOGIN_SECURITY_TOKEN_REQUEST_CONTROLLER_H_ 66