diff options
-rw-r--r-- | chrome/browser/chromeos/login/parallel_authenticator.cc | 16 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/parallel_authenticator_unittest.cc | 15 | ||||
-rw-r--r-- | chromeos/cryptohome/async_method_caller.cc | 4 | ||||
-rw-r--r-- | chromeos/cryptohome/async_method_caller.h | 33 | ||||
-rw-r--r-- | chromeos/cryptohome/mock_async_method_caller.h | 2 | ||||
-rw-r--r-- | chromeos/dbus/cryptohome_client.cc | 8 | ||||
-rw-r--r-- | chromeos/dbus/cryptohome_client.h | 8 | ||||
-rw-r--r-- | chromeos/dbus/mock_cryptohome_client.h | 2 |
8 files changed, 54 insertions, 34 deletions
diff --git a/chrome/browser/chromeos/login/parallel_authenticator.cc b/chrome/browser/chromeos/login/parallel_authenticator.cc index 1317b8c..c646aec 100644 --- a/chrome/browser/chromeos/login/parallel_authenticator.cc +++ b/chrome/browser/chromeos/login/parallel_authenticator.cc @@ -66,14 +66,14 @@ void TriggerResolveWithLoginTimeMarker( // Calls cryptohome's mount method. void Mount(AuthAttemptState* attempt, scoped_refptr<ParallelAuthenticator> resolver, - bool create_if_missing) { + int flags) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( "CryptohomeMount-Start", false); cryptohome::AsyncMethodCaller::GetInstance()->AsyncMount( attempt->username, attempt->ascii_hash, - create_if_missing, + flags, base::Bind(&TriggerResolveWithLoginTimeMarker, "CryptohomeMount-End", attempt, @@ -210,13 +210,12 @@ void ParallelAuthenticator::AuthenticateToLogin( // Reset the verified flag. owner_is_verified_ = false; - const bool create_if_missing = false; BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, base::Bind(&Mount, current_state_.get(), scoped_refptr<ParallelAuthenticator>(this), - create_if_missing)); + cryptohome::MOUNT_FLAGS_NONE)); // ClientLogin authentication check should happen immediately here. // We should not try OAuthLogin check until the profile loads. if (!using_oauth_) { @@ -243,13 +242,12 @@ void ParallelAuthenticator::CompleteLogin(Profile* profile, // Reset the verified flag. owner_is_verified_ = false; - const bool create_if_missing = false; BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, base::Bind(&Mount, current_state_.get(), scoped_refptr<ParallelAuthenticator>(this), - create_if_missing)); + cryptohome::MOUNT_FLAGS_NONE)); if (!using_oauth_) { // Test automation needs to disable oauth, but that leads to other @@ -457,7 +455,7 @@ void ParallelAuthenticator::RetryAuth(Profile* profile, void ParallelAuthenticator::Resolve() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); bool request_pending = false; - bool create = false; + int mount_flags = cryptohome::MOUNT_FLAGS_NONE; ParallelAuthenticator::AuthState state = ResolveState(); VLOG(1) << "Resolved state to: " << state; switch (state) { @@ -501,7 +499,7 @@ void ParallelAuthenticator::Resolve() { LoginFailure(LoginFailure::TPM_ERROR))); break; case CREATE_NEW: - create = true; + mount_flags |= cryptohome::CREATE_IF_MISSING; case RECOVER_MOUNT: current_state_->ResetCryptohomeStatus(); BrowserThread::PostTask( @@ -509,7 +507,7 @@ void ParallelAuthenticator::Resolve() { base::Bind(&Mount, current_state_.get(), scoped_refptr<ParallelAuthenticator>(this), - create)); + mount_flags)); break; case NEED_OLD_PW: BrowserThread::PostTask( diff --git a/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc b/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc index 9283cf496..3d00064 100644 --- a/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc +++ b/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc @@ -439,13 +439,14 @@ TEST_F(ParallelAuthenticatorTest, DriveDataResync) { FailOnLoginFailure(); // Set up mock cryptohome library to respond successfully to a cryptohome - // remove attempt and a cryptohome create attempt (specified by the |true| - // argument to AsyncMount). + // remove attempt and a cryptohome create attempt (indicated by the + // |CREATE_IF_MISSING| flag to AsyncMount). mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); EXPECT_CALL(*mock_caller_, AsyncRemove(username_, _)) .Times(1) .RetiresOnSaturation(); - EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, true, _)) + EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, + cryptohome::CREATE_IF_MISSING, _)) .Times(1) .RetiresOnSaturation(); @@ -492,7 +493,8 @@ TEST_F(ParallelAuthenticatorTest, DriveDataRecover) { EXPECT_CALL(*mock_caller_, AsyncMigrateKey(username_, _, hash_ascii_, _)) .Times(1) .RetiresOnSaturation(); - EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, false, _)) + EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, + cryptohome::MOUNT_FLAGS_NONE, _)) .Times(1) .RetiresOnSaturation(); EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt()) @@ -568,9 +570,10 @@ TEST_F(ParallelAuthenticatorTest, DriveCreateForNewUser) { FailOnLoginFailure(); // Set up mock cryptohome library to respond successfully to a cryptohome - // create attempt (specified by the |true| argument to AsyncMount). + // create attempt (indicated by the |CREATE_IF_MISSING| flag to AsyncMount). mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); - EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, true, _)) + EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, + cryptohome::CREATE_IF_MISSING, _)) .Times(1) .RetiresOnSaturation(); diff --git a/chromeos/cryptohome/async_method_caller.cc b/chromeos/cryptohome/async_method_caller.cc index 4deb338..c868868 100644 --- a/chromeos/cryptohome/async_method_caller.cc +++ b/chromeos/cryptohome/async_method_caller.cc @@ -58,10 +58,10 @@ class AsyncMethodCallerImpl : public AsyncMethodCaller { virtual void AsyncMount(const std::string& user_email, const std::string& passhash, - const bool create_if_missing, + int flags, Callback callback) OVERRIDE { DBusThreadManager::Get()->GetCryptohomeClient()-> - AsyncMount(user_email, passhash, create_if_missing, base::Bind( + AsyncMount(user_email, passhash, flags, base::Bind( &AsyncMethodCallerImpl::RegisterAsyncCallback, weak_ptr_factory_.GetWeakPtr(), callback, diff --git a/chromeos/cryptohome/async_method_caller.h b/chromeos/cryptohome/async_method_caller.h index 38e0182f..b4ab3ab 100644 --- a/chromeos/cryptohome/async_method_caller.h +++ b/chromeos/cryptohome/async_method_caller.h @@ -14,11 +14,20 @@ namespace cryptohome { -// This class manages calls to Cryptohome service's 'async' methods. -// Note: This class is placed in ::cryptohome instead of ::chromeos::cryptohome +// Note: This file is placed in ::cryptohome instead of ::chromeos::cryptohome // since there is already a namespace ::cryptohome which holds the error code // enum (MountError) and referencing ::chromeos::cryptohome and ::cryptohome // within the same code is confusing. + +// Flags for the AsyncMount method. +enum MountFlags { + MOUNT_FLAGS_NONE = 0, // Used to explicitly denote that no flags are + // set. + CREATE_IF_MISSING = 1, // Create a cryptohome if it does not exist yet. + ENSURE_EPHEMERAL = 1 << 1, // Ensure that the mount is ephemeral. +}; + +// This class manages calls to Cryptohome service's 'async' methods. class CHROMEOS_EXPORT AsyncMethodCaller { public: // A callback type which is called back on the UI thread when the results of @@ -45,16 +54,22 @@ class CHROMEOS_EXPORT AsyncMethodCaller { // 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|. + // The |flags| are a combination of |MountFlags|: + // * CREATE_IF_MISSING Controls whether or not cryptohomed is asked to create + // a new cryptohome if one does not exist yet for + // |user_email|. + // * ENSURE_EPHEMERAL If |true|, the mounted cryptohome will be backed by + // tmpfs. If |false|, the ephemeral users policy decides + // whether tmpfs or an encrypted directory is used as the + // backend. // |callback| will be called with status info on completion. - // If |create_if_missing| is false, and no cryptohome exists for |user_email|, - // we'll get - // callback.Run(false, kCryptohomeMountErrorUserDoesNotExist). - // Otherwise, we expect the normal range of return codes. + // If the |CREATE_IF_MISSING| flag is not given and no cryptohome exists + // for |user_email|, the expected result is + // callback.Run(false, kCryptohomeMountErrorUserDoesNotExist). Otherwise, + // the normal range of return codes is expected. virtual void AsyncMount(const std::string& user_email, const std::string& passhash, - const bool create_if_missing, + int flags, Callback callback) = 0; // Asks cryptohomed to asynchronously to mount a tmpfs for guest mode. diff --git a/chromeos/cryptohome/mock_async_method_caller.h b/chromeos/cryptohome/mock_async_method_caller.h index 5b301cb..3d2fdeb 100644 --- a/chromeos/cryptohome/mock_async_method_caller.h +++ b/chromeos/cryptohome/mock_async_method_caller.h @@ -30,7 +30,7 @@ class MockAsyncMethodCaller : public AsyncMethodCaller { Callback callback)); MOCK_METHOD4(AsyncMount, void(const std::string& user_email, const std::string& passhash, - const bool create_if_missing, + int flags, Callback callback)); MOCK_METHOD1(AsyncMountGuest, void(Callback callback)); MOCK_METHOD2(AsyncRemove, void(const std::string& user_email, diff --git a/chromeos/dbus/cryptohome_client.cc b/chromeos/dbus/cryptohome_client.cc index 8cb58ba..f5ee8aa 100644 --- a/chromeos/dbus/cryptohome_client.cc +++ b/chromeos/dbus/cryptohome_client.cc @@ -6,6 +6,7 @@ #include "base/bind.h" #include "base/message_loop.h" +#include "chromeos/cryptohome/async_method_caller.h" #include "chromeos/dbus/blocking_method_caller.h" #include "dbus/bus.h" #include "dbus/message.h" @@ -125,16 +126,17 @@ class CryptohomeClientImpl : public CryptohomeClient { // CryptohomeClient override. virtual void AsyncMount(const std::string& username, const std::string& key, - const bool create_if_missing, + int flags, const AsyncMethodCallback& callback) OVERRIDE { INITIALIZE_METHOD_CALL(method_call, cryptohome::kCryptohomeAsyncMount); dbus::MessageWriter writer(&method_call); writer.AppendString(username); writer.AppendString(key); - writer.AppendBool(create_if_missing); + writer.AppendBool(flags & cryptohome::CREATE_IF_MISSING); writer.AppendBool(false); // deprecated_replace_tracked_subdirectories // deprecated_tracked_subdirectories writer.AppendArrayOfStrings(std::vector<std::string>()); + writer.AppendBool(flags & cryptohome::ENSURE_EPHEMERAL); proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, weak_ptr_factory_.GetWeakPtr(), @@ -501,7 +503,7 @@ class CryptohomeClientStubImpl : public CryptohomeClient { // CryptohomeClient override. virtual void AsyncMount(const std::string& username, const std::string& key, - const bool create_if_missing, + int flags, const AsyncMethodCallback& callback) OVERRIDE { ReturnAsyncMethodResult(callback); } diff --git a/chromeos/dbus/cryptohome_client.h b/chromeos/dbus/cryptohome_client.h index 7671783..60b632f 100644 --- a/chromeos/dbus/cryptohome_client.h +++ b/chromeos/dbus/cryptohome_client.h @@ -82,11 +82,13 @@ class CHROMEOS_EXPORT CryptohomeClient { // The original content of |salt| is lost. virtual bool GetSystemSalt(std::vector<uint8>* salt) = 0; - // Calls AsyncMount method. |callback| is called after the method call - // succeeds. + // Calls the AsyncMount method to asynchronously mount the cryptohome for + // |username|, using |key| to unlock it. For supported |flags|, see the + // documentation of AsyncMethodCaller::AsyncMount(). + // |callback| is called after the method call succeeds. virtual void AsyncMount(const std::string& username, const std::string& key, - const bool create_if_missing, + int flags, const AsyncMethodCallback& callback) = 0; // Calls AsyncMountGuest method. |callback| is called after the method call diff --git a/chromeos/dbus/mock_cryptohome_client.h b/chromeos/dbus/mock_cryptohome_client.h index e36f887..5a249e0 100644 --- a/chromeos/dbus/mock_cryptohome_client.h +++ b/chromeos/dbus/mock_cryptohome_client.h @@ -36,7 +36,7 @@ class MockCryptohomeClient : public CryptohomeClient { MOCK_METHOD1(GetSystemSalt, bool(std::vector<uint8>* salt)); MOCK_METHOD4(AsyncMount, void(const std::string& username, const std::string& key, - const bool create_if_missing, + int flags, const AsyncMethodCallback& callback)); MOCK_METHOD1(AsyncMountGuest, void(const AsyncMethodCallback& callback)); |