diff options
author | cmasone@chromium.org <cmasone@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-30 00:58:08 +0000 |
---|---|---|
committer | cmasone@chromium.org <cmasone@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-30 00:58:08 +0000 |
commit | b331674628336f246aeaa85b50f1331d1fe6e9c0 (patch) | |
tree | 8a52ff2f492aa8883b7e2be3e600731b206da4a5 | |
parent | b30241405fd188d9896843a84b52fea3f3c57828 (diff) | |
download | chromium_src-b331674628336f246aeaa85b50f1331d1fe6e9c0.zip chromium_src-b331674628336f246aeaa85b50f1331d1fe6e9c0.tar.gz chromium_src-b331674628336f246aeaa85b50f1331d1fe6e9c0.tar.bz2 |
[Chrome OS] Enable CryptohomeLibrary to optionally create new cryptohomes
Expose support for "create if missing" option to crypthome's async mount call.
BUG=chromium-os:4929
TEST=unit tests
Review URL: http://codereview.chromium.org/3544002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61019 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 27 insertions, 31 deletions
diff --git a/chrome/browser/chromeos/cros/cryptohome_library.cc b/chrome/browser/chromeos/cros/cryptohome_library.cc index 60d1005..cd75a85 100644 --- a/chrome/browser/chromeos/cros/cryptohome_library.cc +++ b/chrome/browser/chromeos/cros/cryptohome_library.cc @@ -63,11 +63,12 @@ class CryptohomeLibraryImpl : public CryptohomeLibrary { bool AsyncMount(const std::string& user_email, const std::string& passhash, + const bool create_if_missing, Delegate* d) { return CacheCallback( chromeos::CryptohomeAsyncMount(user_email.c_str(), passhash.c_str(), - true, + create_if_missing, "", std::vector<std::string>()), d, @@ -193,6 +194,7 @@ class CryptohomeLibraryStubImpl : public CryptohomeLibrary { bool AsyncMount(const std::string& user_email, const std::string& passhash, + const bool create_if_missing, Delegate* callback) { ChromeThread::PostTask( ChromeThread::UI, FROM_HERE, diff --git a/chrome/browser/chromeos/cros/cryptohome_library.h b/chrome/browser/chromeos/cros/cryptohome_library.h index 2eb4fc7..9a72761 100644 --- a/chrome/browser/chromeos/cros/cryptohome_library.h +++ b/chrome/browser/chromeos/cros/cryptohome_library.h @@ -64,10 +64,16 @@ class CryptohomeLibrary { // 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; // Asks cryptohomed to mount a tmpfs for BWSI mode. diff --git a/chrome/browser/chromeos/cros/mock_cryptohome_library.h b/chrome/browser/chromeos/cros/mock_cryptohome_library.h index 808db1b..c579418 100644 --- a/chrome/browser/chromeos/cros/mock_cryptohome_library.h +++ b/chrome/browser/chromeos/cros/mock_cryptohome_library.h @@ -12,6 +12,7 @@ #include "testing/gmock/include/gmock/gmock.h" using ::testing::Invoke; +using ::testing::WithArgs; using ::testing::_; namespace chromeos { @@ -20,15 +21,20 @@ class MockCryptohomeLibrary : public CryptohomeLibrary { public: MockCryptohomeLibrary() { ON_CALL(*this, AsyncCheckKey(_, _, _)) - .WillByDefault(Invoke(this, &MockCryptohomeLibrary::TwoString)); + .WillByDefault( + WithArgs<2>(Invoke(this, &MockCryptohomeLibrary::DoCallback))); ON_CALL(*this, AsyncMigrateKey(_, _, _, _)) - .WillByDefault(Invoke(this, &MockCryptohomeLibrary::ThreeString)); - ON_CALL(*this, AsyncMount(_, _, _)) - .WillByDefault(Invoke(this, &MockCryptohomeLibrary::TwoString)); + .WillByDefault( + WithArgs<3>(Invoke(this, &MockCryptohomeLibrary::DoCallback))); + ON_CALL(*this, AsyncMount(_, _, _, _)) + .WillByDefault( + WithArgs<3>(Invoke(this, &MockCryptohomeLibrary::DoCallback))); ON_CALL(*this, AsyncMountForBwsi(_)) - .WillByDefault(Invoke(this, &MockCryptohomeLibrary::ZeroString)); + .WillByDefault( + WithArgs<0>(Invoke(this, &MockCryptohomeLibrary::DoCallback))); ON_CALL(*this, AsyncRemove(_, _)) - .WillByDefault(Invoke(this, &MockCryptohomeLibrary::OneString)); + .WillByDefault( + WithArgs<1>(Invoke(this, &MockCryptohomeLibrary::DoCallback))); } virtual ~MockCryptohomeLibrary() {} MOCK_METHOD2(CheckKey, bool(const std::string& user_email, @@ -46,8 +52,9 @@ class MockCryptohomeLibrary : public CryptohomeLibrary { MOCK_METHOD3(Mount, bool(const std::string& user_email, const std::string& passhash, int* error_code)); - MOCK_METHOD3(AsyncMount, bool(const std::string& user_email, + MOCK_METHOD4(AsyncMount, bool(const std::string& user_email, const std::string& passhash, + const bool create_if_missing, Delegate* callback)); MOCK_METHOD1(MountForBwsi, bool(int*)); MOCK_METHOD1(AsyncMountForBwsi, bool(Delegate* callback)); @@ -61,27 +68,7 @@ class MockCryptohomeLibrary : public CryptohomeLibrary { code_ = code; } - bool ThreeString(const std::string& user_email, - const std::string& old_hash, - const std::string& new_hash, - Delegate* d) { - d->OnComplete(outcome_, code_); - return true; - } - - bool TwoString(const std::string& user_email, - const std::string& passhash, - Delegate* d) { - d->OnComplete(outcome_, code_); - return true; - } - - bool OneString(const std::string& user_email, Delegate* d) { - d->OnComplete(outcome_, code_); - return true; - } - - bool ZeroString(Delegate* d) { + bool DoCallback(Delegate* d) { d->OnComplete(outcome_, code_); return true; } diff --git a/chrome/browser/chromeos/login/cryptohome_op.cc b/chrome/browser/chromeos/login/cryptohome_op.cc index 73bc6ee..82dcad0 100644 --- a/chrome/browser/chromeos/login/cryptohome_op.cc +++ b/chrome/browser/chromeos/login/cryptohome_op.cc @@ -46,7 +46,7 @@ MountAttempt::~MountAttempt() {} bool MountAttempt::Initiate() { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); CryptohomeLibrary* lib = CrosLibrary::Get()->GetCryptohomeLibrary(); - return lib->AsyncMount(attempt_->username, attempt_->ascii_hash, this); + return lib->AsyncMount(attempt_->username, attempt_->ascii_hash, true, this); } MountGuestAttempt::MountGuestAttempt(AuthAttemptState* current_attempt, diff --git a/chrome/browser/chromeos/login/cryptohome_op_unittest.cc b/chrome/browser/chromeos/login/cryptohome_op_unittest.cc index 36a4bf2..9975822 100644 --- a/chrome/browser/chromeos/login/cryptohome_op_unittest.cc +++ b/chrome/browser/chromeos/login/cryptohome_op_unittest.cc @@ -82,7 +82,8 @@ class CryptohomeOpTest : public ::testing::Test { } void ExpectMount() { - EXPECT_CALL(*(mock_library_.get()), AsyncMount(username_, hash_ascii_, _)) + EXPECT_CALL(*(mock_library_.get()), + AsyncMount(username_, hash_ascii_, true, _)) .Times(1) .RetiresOnSaturation(); } |