summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/cros/cryptohome_library.h
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/chromeos/cros/cryptohome_library.h')
-rw-r--r--chrome/browser/chromeos/cros/cryptohome_library.h102
1 files changed, 63 insertions, 39 deletions
diff --git a/chrome/browser/chromeos/cros/cryptohome_library.h b/chrome/browser/chromeos/cros/cryptohome_library.h
index 6e91d30..9a72761 100644
--- a/chrome/browser/chromeos/cros/cryptohome_library.h
+++ b/chrome/browser/chromeos/cros/cryptohome_library.h
@@ -4,10 +4,12 @@
#ifndef CHROME_BROWSER_CHROMEOS_CROS_CRYPTOHOME_LIBRARY_H_
#define CHROME_BROWSER_CHROMEOS_CROS_CRYPTOHOME_LIBRARY_H_
+#pragma once
#include <string>
#include "base/singleton.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
#include "cros/chromeos_cryptohome.h"
namespace chromeos {
@@ -16,68 +18,90 @@ namespace chromeos {
// APIs.
class CryptohomeLibrary {
public:
- virtual ~CryptohomeLibrary() {}
-
- // Asks cryptohomed to try to find the cryptohome for |user_email| and then
- // mount it using |passhash| to unlock the key.
- virtual bool Mount(const std::string& user_email,
- const std::string& passhash,
- int* error_code) = 0;
+ class Delegate {
+ public:
+ // This will be called back on the UI thread. Consult |return_code| for
+ // further information beyond mere success or failure.
+ virtual void OnComplete(bool success, int return_code) = 0;
+ };
- // Asks cryptohomed to mount a tmpfs for BWSI mode.
- virtual bool MountForBwsi(int* error_code) = 0;
+ virtual ~CryptohomeLibrary() {}
// Asks cryptohomed to try to find the cryptohome for |user_email| and then
// use |passhash| to unlock the key.
virtual bool CheckKey(const std::string& user_email,
const std::string& passhash) = 0;
+ // Asks cryptohomed to asynchronously try to find the cryptohome for
+ // |user_email| and then use |passhash| to unlock the key.
+ // Returns true if the attempt is successfully initiated.
+ // d->OnComplete() will be called with status info on completion.
+ virtual bool AsyncCheckKey(const std::string& user_email,
+ const std::string& passhash,
+ Delegate* callback) = 0;
+
// Asks cryptohomed to try to find the cryptohome for |user_email| and then
// change from using |old_hash| to lock the key to using |new_hash|.
virtual bool MigrateKey(const std::string& user_email,
const std::string& old_hash,
const std::string& new_hash) = 0;
- // Asks cryptohomed to try to find the cryptohome for |user_email| and then
- // nuke it.
- virtual bool Remove(const std::string& user_email) = 0;
-
- // Asks cryptohomed if a drive is currently mounted.
- virtual bool IsMounted() = 0;
-
- // Asks cryptohomed for the system salt.
- virtual CryptohomeBlob GetSystemSalt() = 0;
-
-};
+ // Asks cryptohomed to asynchronously try to find the cryptohome for
+ // |user_email| and then change from using |old_hash| to lock the
+ // key to using |new_hash|.
+ // Returns true if the attempt is successfully initiated.
+ // d->OnComplete() will be called with status info on completion.
+ virtual bool AsyncMigrateKey(const std::string& user_email,
+ const std::string& old_hash,
+ const std::string& new_hash,
+ Delegate* callback) = 0;
-// This class handles the interaction with the ChromeOS cryptohome library APIs.
-class CryptohomeLibraryImpl : public CryptohomeLibrary {
- public:
- CryptohomeLibraryImpl() {}
- virtual ~CryptohomeLibraryImpl() {}
-
- // CryptohomeLibrary overrides.
+ // Asks cryptohomed to try to find the cryptohome for |user_email| and then
+ // mount it using |passhash| to unlock the key.
virtual bool Mount(const std::string& user_email,
const std::string& passhash,
- int* error_code);
+ int* error_code) = 0;
- virtual bool MountForBwsi(int* error_code);
+ // Asks cryptohomed to asynchronously try to find the cryptohome for
+ // |user_email| and then mount it using |passhash| to unlock the key.
+ // |create_if_missing| controls whether or not we ask cryptohomed to
+ // create a new home dir if one does not yet exist for |user_email|.
+ // Returns true if the attempt is successfully initiated.
+ // d->OnComplete() will be called with status info on completion.
+ // If |create_if_missing| is false, and no cryptohome exists for |user_email|,
+ // we'll get d->OnComplete(false, kCryptohomeMountErrorUserDoesNotExist).
+ // Otherwise, we expect the normal range of return codes.
+ virtual bool AsyncMount(const std::string& user_email,
+ const std::string& passhash,
+ const bool create_if_missing,
+ Delegate* callback) = 0;
- virtual bool CheckKey(const std::string& user_email,
- const std::string& passhash);
+ // Asks cryptohomed to mount a tmpfs for BWSI mode.
+ virtual bool MountForBwsi(int* error_code) = 0;
- virtual bool MigrateKey(const std::string& user_email,
- const std::string& old_hash,
- const std::string& new_hash);
+ // Asks cryptohomed to asynchronously to mount a tmpfs for BWSI mode.
+ // Returns true if the attempt is successfully initiated.
+ // d->OnComplete() will be called with status info on completion.
+ virtual bool AsyncMountForBwsi(Delegate* callback) = 0;
+
+ // Asks cryptohomed to try to find the cryptohome for |user_email| and then
+ // nuke it.
+ virtual bool Remove(const std::string& user_email) = 0;
- virtual bool Remove(const std::string& user_email);
+ // Asks cryptohomed to asynchronously try to find the cryptohome for
+ // |user_email| and then nuke it.
+ virtual bool AsyncRemove(const std::string& user_email,
+ Delegate* callback) = 0;
- virtual bool IsMounted();
+ // Asks cryptohomed if a drive is currently mounted.
+ virtual bool IsMounted() = 0;
- virtual CryptohomeBlob GetSystemSalt();
+ // Asks cryptohomed for the system salt.
+ virtual CryptohomeBlob GetSystemSalt() = 0;
- private:
- DISALLOW_COPY_AND_ASSIGN(CryptohomeLibraryImpl);
+ // Factory function, creates a new instance and returns ownership.
+ // For normal usage, access the singleton via CrosLibrary::Get().
+ static CryptohomeLibrary* GetImpl(bool stub);
};
} // namespace chromeos