biometric_authenticator.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright 2019 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 COMPONENTS_DEVICE_REAUTH_BIOMETRIC_AUTHENTICATOR_H_
  5. #define COMPONENTS_DEVICE_REAUTH_BIOMETRIC_AUTHENTICATOR_H_
  6. #include "base/callback_forward.h"
  7. #include "base/memory/ref_counted.h"
  8. namespace device_reauth {
  9. // The filling surface asking for biometric authentication.
  10. //
  11. // These values are persisted to logs. Entries should not be renumbered and
  12. // numeric values should never be reused.
  13. //
  14. // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.device_reauth
  15. enum class BiometricAuthRequester {
  16. // The filling surface shown on the first tap on the field after page load.
  17. // This surface has replaced autofilling on Android.
  18. kTouchToFill = 0,
  19. // The suggestion presented in the keyboard accessory or autofill popup.
  20. kAutofillSuggestion = 1,
  21. // The keyboard accessory sheet displaying suggestions for manual filling.
  22. kFallbackSheet = 2,
  23. // The list displaying all saved passwords. Can be used for filling on
  24. // Android.
  25. kAllPasswordsList = 3,
  26. // The dialog displayed via the Credential Management API.
  27. kAccountChooserDialog = 4,
  28. // The list displaying all compromised passwords. Reauth is triggered before
  29. // starting automated password change.
  30. kPasswordCheckAutoPwdChange = 5,
  31. // The dialog displayed to access existing Incognito tabs if the Incognito
  32. // lock setting in on and Chrome came to foreground.
  33. kIncognitoReauthPage = 6,
  34. // The prompt displayed when user is trying to copy/edit/view/export their
  35. // passwords from settings page on Windows and Mac.
  36. kPasswordsInSettings = 7,
  37. kMaxValue = kPasswordsInSettings,
  38. };
  39. // This interface encapsulates operations related to biometric authentication.
  40. // It's intended to be used prior to sharing the user's credentials with a
  41. // website, either via form filling or the Credential Management API.
  42. class BiometricAuthenticator : public base::RefCounted<BiometricAuthenticator> {
  43. public:
  44. using AuthenticateCallback = base::OnceCallback<void(bool)>;
  45. BiometricAuthenticator();
  46. BiometricAuthenticator(const BiometricAuthenticator&) = delete;
  47. BiometricAuthenticator& operator=(const BiometricAuthenticator&) = delete;
  48. // Returns whether biometrics are available for a given device.
  49. virtual bool CanAuthenticate(BiometricAuthRequester requester) = 0;
  50. // Asks the user to authenticate. Invokes |callback| asynchronously when
  51. // the auth flow returns with the result.
  52. // |requester| is the filling surface that is asking for authentication.
  53. // |use_last_valid_auth| if set to false, ignores the grace 60 seconds
  54. // period between the last valid authentication and the current
  55. // authentication, and re-invokes system authentication.
  56. virtual void Authenticate(BiometricAuthRequester requester,
  57. AuthenticateCallback callback,
  58. bool use_last_valid_auth) = 0;
  59. // Asks the user to authenticate. Invokes |callback| asynchronously when
  60. // the auth flow returns with the result.
  61. // |requester| is the filling surface that is asking for authentication.
  62. // |message| contains text that will be displayed to the end user on
  63. // authentication request
  64. virtual void AuthenticateWithMessage(BiometricAuthRequester requester,
  65. const std::u16string message,
  66. AuthenticateCallback callback) = 0;
  67. // Cancels an in-progress authentication if the filling surface requesting
  68. // the cancelation corresponds to the one for which the ongoing auth was
  69. // triggered.
  70. virtual void Cancel(BiometricAuthRequester requester) = 0;
  71. protected:
  72. virtual ~BiometricAuthenticator() = default;
  73. private:
  74. friend class base::RefCounted<BiometricAuthenticator>;
  75. };
  76. } // namespace device_reauth
  77. #endif // COMPONENTS_DEVICE_REAUTH_BIOMETRIC_AUTHENTICATOR_H_