#ifndef CHROME_BROWSER_ASH_AUTH_CRYPTOHOME_PIN_ENGINE_H_
#define CHROME_BROWSER_ASH_AUTH_CRYPTOHOME_PIN_ENGINE_H_
#include <memory>
#include <optional>
#include <string>
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/memory/weak_ptr.h"
#include "chromeos/ash/components/cryptohome/common_types.h"
#include "chromeos/ash/components/login/auth/auth_factor_editor.h"
#include "chromeos/ash/components/login/auth/auth_performer.h"
class PrefService;
namespace ash {
class UserContext;
namespace legacy {
class CryptohomePinEngine {
public:
enum class Purpose { kAny, kUnlock, kWebAuthn };
CryptohomePinEngine(PrefService* local_state,
ash::AuthPerformer* auth_performer);
CryptohomePinEngine(const CryptohomePinEngine&) = delete;
CryptohomePinEngine& operator=(const CryptohomePinEngine&) = delete;
virtual ~CryptohomePinEngine();
using IsPinAuthAvailableCallback =
base::OnceCallback<void(bool, std::unique_ptr<UserContext>)>;
bool ShouldSkipSetupBecauseOfPolicy(const AccountId& account_id) const;
std::optional<bool> IsCryptohomePinDisabledByPolicy(
const AccountId& account_id,
CryptohomePinEngine::Purpose purpose) const;
void IsPinAuthAvailable(Purpose purpose,
std::unique_ptr<UserContext> user_context,
IsPinAuthAvailableCallback callback);
void Authenticate(const cryptohome::RawPin& pin,
std::unique_ptr<UserContext> user_context,
AuthOperationCallback callback);
private:
void CheckCryptohomePinFactor(std::unique_ptr<UserContext> user_context,
IsPinAuthAvailableCallback callback);
void OnGetAuthFactorsConfiguration(IsPinAuthAvailableCallback callback,
std::unique_ptr<UserContext> user_context,
std::optional<AuthenticationError> error);
const raw_ref<PrefService> local_state_;
const raw_ptr<ash::AuthPerformer> auth_performer_;
ash::AuthFactorEditor auth_factor_editor_;
base::WeakPtrFactory<CryptohomePinEngine> weak_factory_{this};
};
}
}
#endif