// See CryptohomeClient::OnPkcs11GetTpmTokenInfo.
class CHROMEOS_EXPORT TPMTokenLoader : public LoginState::Observer {
public:
- class Observer {
- public:
- // Called when the TPM token initialization is done or the case where TPM
- // should stay disabled is detected (e.g. on guest login).
- virtual void OnTPMTokenReady() = 0;
-
- protected:
- virtual ~Observer() {}
+ enum TPMTokenStatus {
+ TPM_TOKEN_STATUS_UNDETERMINED,
+ TPM_TOKEN_STATUS_ENABLED,
+ TPM_TOKEN_STATUS_DISABLED
};
+ typedef base::Callback<void(bool)> TPMReadyCallback;
+ typedef std::vector<TPMReadyCallback> TPMReadyCallbackList;
+
// Sets the global instance. Must be called before any calls to Get().
// The global instance will immediately start observing |LoginState|.
static void Initialize();
void SetCryptoTaskRunner(
const scoped_refptr<base::SequencedTaskRunner>& crypto_task_runner);
- void AddObserver(TPMTokenLoader::Observer* observer);
- void RemoveObserver(TPMTokenLoader::Observer* observer);
-
- // Checks if the TPM token in ready to be used.
- bool IsTPMTokenReady() const;
+ // Checks if the TPM token is enabled. If the state is unknown, |callback|
+ // will be called back once the TPM state is known.
+ TPMTokenStatus IsTPMTokenEnabled(const TPMReadyCallback& callback);
std::string tpm_user_pin() const { return tpm_user_pin_; }
explicit TPMTokenLoader(bool for_test);
virtual ~TPMTokenLoader();
+ bool IsTPMLoadingEnabled() const;
+
// Starts tpm token initialization if the user is logged in and the crypto
// task runner is set.
void MaybeStartTokenInitialization();
bool initialized_for_test_;
- ObserverList<Observer> observers_;
+ TPMReadyCallbackList tpm_ready_callback_list_;
// The states are traversed in this order but some might get omitted or never
// be left.