Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chromeos / tpm_token_loader.h
index 16e20ef..33fffa2 100644 (file)
@@ -32,16 +32,15 @@ namespace chromeos {
 // 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();
@@ -65,11 +64,9 @@ class CHROMEOS_EXPORT TPMTokenLoader : public LoginState::Observer {
   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_; }
 
@@ -77,6 +74,8 @@ class CHROMEOS_EXPORT TPMTokenLoader : public LoginState::Observer {
   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();
@@ -106,7 +105,7 @@ class CHROMEOS_EXPORT TPMTokenLoader : public LoginState::Observer {
 
   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.