security_token_request_controller.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #ifndef ASH_LOGIN_SECURITY_TOKEN_REQUEST_CONTROLLER_H_
  5. #define ASH_LOGIN_SECURITY_TOKEN_REQUEST_CONTROLLER_H_
  6. #include "ash/login/ui/pin_request_view.h"
  7. #include "ash/public/cpp/login_types.h"
  8. #include "base/memory/weak_ptr.h"
  9. namespace ash {
  10. // SecurityTokenRequestController serves as a single point of access to ask the
  11. // user for a PIN for a security token request.
  12. class ASH_EXPORT SecurityTokenRequestController
  13. : public PinRequestView::Delegate {
  14. public:
  15. SecurityTokenRequestController();
  16. SecurityTokenRequestController(const SecurityTokenRequestController&) =
  17. delete;
  18. SecurityTokenRequestController& operator=(
  19. const SecurityTokenRequestController&) = delete;
  20. ~SecurityTokenRequestController() override;
  21. bool request_canceled() const { return request_canceled_; }
  22. void ResetRequestCanceled();
  23. // PinRequestView::Delegate interface.
  24. PinRequestView::SubmissionResult OnPinSubmitted(
  25. const std::string& pin) override;
  26. void OnBack() override;
  27. void OnHelp() override;
  28. // Shows the PIN dialog configured by |request|. If there already is a
  29. // SecurityTokenPinRequest in progress, keeps the dialog open and updates the
  30. // dialog's state.
  31. // Returns true if the dialog was opened or updated successfully, false
  32. // otherwise. The request will fail if the PIN UI is currently in use for
  33. // something other than a SecurityTokenPinRequest.
  34. bool SetPinUiState(SecurityTokenPinRequest request);
  35. // Closes the UI and resets callbacks.
  36. void ClosePinUi();
  37. private:
  38. // Called when the user submits the input. Will not be called if the UI is
  39. // closed before that happens.
  40. SecurityTokenPinRequest::OnPinEntered on_pin_submitted_;
  41. // Called when the PIN request UI gets closed by the user (back button).
  42. SecurityTokenPinRequest::OnUiClosed on_canceled_by_user_;
  43. // Whether this controller is currently using PinRequestWidget.
  44. bool security_token_request_in_progress_ = false;
  45. // Whether the user has recently canceled a PIN request.
  46. bool request_canceled_ = false;
  47. base::WeakPtrFactory<SecurityTokenRequestController> weak_factory_{this};
  48. };
  49. } // namespace ash
  50. #endif // ASH_LOGIN_SECURITY_TOKEN_REQUEST_CONTROLLER_H_