summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-20 17:31:31 +0000
committerhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-20 17:31:31 +0000
commitb83d1c9b7b762a76a94c3e0d8a9f41351681ca97 (patch)
treecfbe02b31948e77b3e134a19383499554df9d39b
parenta73179ae99d66c01dd92d795a474159b806aa87d (diff)
downloadchromium_src-b83d1c9b7b762a76a94c3e0d8a9f41351681ca97.zip
chromium_src-b83d1c9b7b762a76a94c3e0d8a9f41351681ca97.tar.gz
chromium_src-b83d1c9b7b762a76a94c3e0d8a9f41351681ca97.tar.bz2
Replace CryptohomeLibrary::Delegate with base::Callback
BUG=chromium-os:16552 TEST= Following operations succeed: adding a user, removing a user, logging in as a user, logging in as a guest. Review URL: http://codereview.chromium.org/9388004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122766 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/cros/cryptohome_library.cc40
-rw-r--r--chrome/browser/chromeos/cros/cryptohome_library.h22
-rw-r--r--chrome/browser/chromeos/cros/mock_cryptohome_library.h14
-rw-r--r--chrome/browser/chromeos/login/cryptohome_op.cc197
-rw-r--r--chrome/browser/chromeos/login/cryptohome_op.h66
-rw-r--r--chrome/browser/chromeos/login/cryptohome_op_unittest.cc238
-rw-r--r--chrome/browser/chromeos/login/login_utils.cc2
-rw-r--r--chrome/browser/chromeos/login/parallel_authenticator.cc287
-rw-r--r--chrome/browser/chromeos/login/parallel_authenticator.h43
-rw-r--r--chrome/browser/chromeos/login/parallel_authenticator_unittest.cc3
-rw-r--r--chrome/browser/chromeos/login/user_manager.cc96
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/chrome_tests.gypi1
13 files changed, 279 insertions, 732 deletions
diff --git a/chrome/browser/chromeos/cros/cryptohome_library.cc b/chrome/browser/chromeos/cros/cryptohome_library.cc
index 7e35516..56589a7 100644
--- a/chrome/browser/chromeos/cros/cryptohome_library.cc
+++ b/chrome/browser/chromeos/cros/cryptohome_library.cc
@@ -45,7 +45,7 @@ class CryptohomeLibraryImpl : public CryptohomeLibrary {
virtual void AsyncCheckKey(const std::string& user_email,
const std::string& passhash,
- Delegate* callback) OVERRIDE {
+ AsyncMethodCallback callback) OVERRIDE {
DBusThreadManager::Get()->GetCryptohomeClient()->
AsyncCheckKey(user_email, passhash, base::Bind(
&CryptohomeLibraryImpl::RegisterAsyncCallback,
@@ -57,7 +57,7 @@ class CryptohomeLibraryImpl : public CryptohomeLibrary {
virtual void AsyncMigrateKey(const std::string& user_email,
const std::string& old_hash,
const std::string& new_hash,
- Delegate* callback) OVERRIDE {
+ AsyncMethodCallback callback) OVERRIDE {
DBusThreadManager::Get()->GetCryptohomeClient()->
AsyncMigrateKey(user_email, old_hash, new_hash, base::Bind(
&CryptohomeLibraryImpl::RegisterAsyncCallback,
@@ -69,7 +69,7 @@ class CryptohomeLibraryImpl : public CryptohomeLibrary {
virtual void AsyncMount(const std::string& user_email,
const std::string& passhash,
const bool create_if_missing,
- Delegate* callback) OVERRIDE {
+ AsyncMethodCallback callback) OVERRIDE {
DBusThreadManager::Get()->GetCryptohomeClient()->
AsyncMount(user_email, passhash, create_if_missing, base::Bind(
&CryptohomeLibraryImpl::RegisterAsyncCallback,
@@ -78,7 +78,7 @@ class CryptohomeLibraryImpl : public CryptohomeLibrary {
"Couldn't initiate async mount of cryptohome."));
}
- virtual void AsyncMountGuest(Delegate* callback) OVERRIDE {
+ virtual void AsyncMountGuest(AsyncMethodCallback callback) OVERRIDE {
DBusThreadManager::Get()->GetCryptohomeClient()->
AsyncMountGuest(base::Bind(
&CryptohomeLibraryImpl::RegisterAsyncCallback,
@@ -88,7 +88,7 @@ class CryptohomeLibraryImpl : public CryptohomeLibrary {
}
virtual void AsyncRemove(
- const std::string& user_email, Delegate* callback) OVERRIDE {
+ const std::string& user_email, AsyncMethodCallback callback) OVERRIDE {
DBusThreadManager::Get()->GetCryptohomeClient()->
AsyncRemove(user_email, base::Bind(
&CryptohomeLibraryImpl::RegisterAsyncCallback,
@@ -228,7 +228,7 @@ class CryptohomeLibraryImpl : public CryptohomeLibrary {
}
private:
- typedef base::hash_map<int, Delegate*> CallbackMap;
+ typedef base::hash_map<int, AsyncMethodCallback> CallbackMap;
// Hanldes the response for async calls.
// Below is described how async calls work.
@@ -240,18 +240,17 @@ class CryptohomeLibraryImpl : public CryptohomeLibrary {
// 4. "HandleAsyncResponse" handles the result signal and call the registered
// callback associated with the "async ID".
void HandleAsyncResponse(int async_id, bool return_status, int return_code) {
- const CallbackMap::iterator callback = callback_map_.find(async_id);
- if (callback == callback_map_.end()) {
+ const CallbackMap::iterator it = callback_map_.find(async_id);
+ if (it == callback_map_.end()) {
LOG(ERROR) << "Received signal for unknown async_id " << async_id;
return;
}
- if (callback->second)
- callback->second->OnComplete(return_status, return_code);
- callback_map_.erase(callback);
+ it->second.Run(return_status, return_code);
+ callback_map_.erase(it);
}
// Registers a callback which is called when the result for AsyncXXX is ready.
- void RegisterAsyncCallback(Delegate* callback,
+ void RegisterAsyncCallback(AsyncMethodCallback callback,
const char* error,
int async_id) {
if (async_id == 0) {
@@ -287,7 +286,7 @@ class CryptohomeLibraryStubImpl : public CryptohomeLibrary {
virtual void AsyncCheckKey(const std::string& user_email,
const std::string& passhash,
- Delegate* callback) OVERRIDE {
+ AsyncMethodCallback callback) OVERRIDE {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&DoStubCallback, callback));
@@ -296,7 +295,7 @@ class CryptohomeLibraryStubImpl : public CryptohomeLibrary {
virtual void AsyncMigrateKey(const std::string& user_email,
const std::string& old_hash,
const std::string& new_hash,
- Delegate* callback) OVERRIDE {
+ AsyncMethodCallback callback) OVERRIDE {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&DoStubCallback, callback));
@@ -305,19 +304,19 @@ class CryptohomeLibraryStubImpl : public CryptohomeLibrary {
virtual void AsyncMount(const std::string& user_email,
const std::string& passhash,
const bool create_if_missing,
- Delegate* callback) OVERRIDE {
+ AsyncMethodCallback callback) OVERRIDE {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&DoStubCallback, callback));
}
- virtual void AsyncMountGuest(Delegate* callback) OVERRIDE {
+ virtual void AsyncMountGuest(AsyncMethodCallback callback) OVERRIDE {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&DoStubCallback, callback));
}
virtual void AsyncRemove(
- const std::string& user_email, Delegate* callback) OVERRIDE {
+ const std::string& user_email, AsyncMethodCallback callback) OVERRIDE {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&DoStubCallback, callback));
@@ -387,7 +386,7 @@ class CryptohomeLibraryStubImpl : public CryptohomeLibrary {
}
virtual void Pkcs11GetTpmTokenInfo(std::string* label,
- std::string* user_pin) OVERRIDE {
+ std::string* user_pin) OVERRIDE {
*label = "Stub TPM Token";
*user_pin = "012345";
}
@@ -405,9 +404,8 @@ class CryptohomeLibraryStubImpl : public CryptohomeLibrary {
}
private:
- static void DoStubCallback(Delegate* callback) {
- if (callback)
- callback->OnComplete(true, cryptohome::MOUNT_ERROR_NONE);
+ static void DoStubCallback(AsyncMethodCallback callback) {
+ callback.Run(true, cryptohome::MOUNT_ERROR_NONE);
}
std::map<std::string, std::string> install_attrs_;
diff --git a/chrome/browser/chromeos/cros/cryptohome_library.h b/chrome/browser/chromeos/cros/cryptohome_library.h
index 656c330..58214d2 100644
--- a/chrome/browser/chromeos/cros/cryptohome_library.h
+++ b/chrome/browser/chromeos/cros/cryptohome_library.h
@@ -8,18 +8,18 @@
#include <string>
+#include "base/callback.h"
+
namespace chromeos {
// This interface defines the interaction with the ChromeOS cryptohome library
// APIs.
class CryptohomeLibrary {
public:
- 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;
- };
+ // A callback type which is called back on the UI thread when the results of
+ // AsyncXXX methods are ready.
+ typedef base::Callback<void(bool success, int return_code)
+ > AsyncMethodCallback;
CryptohomeLibrary();
virtual ~CryptohomeLibrary();
@@ -30,7 +30,7 @@ class CryptohomeLibrary {
// callback->OnComplete() will be called with status info on completion.
virtual void AsyncCheckKey(const std::string& user_email,
const std::string& passhash,
- Delegate* callback) = 0;
+ AsyncMethodCallback callback) = 0;
// Asks cryptohomed to asynchronously try to find the cryptohome for
// |user_email| and then change from using |old_hash| to lock the
@@ -40,7 +40,7 @@ class CryptohomeLibrary {
virtual void AsyncMigrateKey(const std::string& user_email,
const std::string& old_hash,
const std::string& new_hash,
- Delegate* callback) = 0;
+ AsyncMethodCallback callback) = 0;
// Asks cryptohomed to asynchronously try to find the cryptohome for
// |user_email| and then mount it using |passhash| to unlock the key.
@@ -55,17 +55,17 @@ class CryptohomeLibrary {
virtual void AsyncMount(const std::string& user_email,
const std::string& passhash,
const bool create_if_missing,
- Delegate* callback) = 0;
+ AsyncMethodCallback callback) = 0;
// Asks cryptohomed to asynchronously to mount a tmpfs for guest mode.
// Returns true if the attempt is successfully initiated.
// callback->OnComplete() will be called with status info on completion.
- virtual void AsyncMountGuest(Delegate* callback) = 0;
+ virtual void AsyncMountGuest(AsyncMethodCallback callback) = 0;
// Asks cryptohomed to asynchronously try to find the cryptohome for
// |user_email| and then nuke it.
virtual void AsyncRemove(const std::string& user_email,
- Delegate* callback) = 0;
+ AsyncMethodCallback callback) = 0;
// Asks cryptohomed if a drive is currently mounted.
virtual bool IsMounted() = 0;
diff --git a/chrome/browser/chromeos/cros/mock_cryptohome_library.h b/chrome/browser/chromeos/cros/mock_cryptohome_library.h
index cdf5884..04f3c6d 100644
--- a/chrome/browser/chromeos/cros/mock_cryptohome_library.h
+++ b/chrome/browser/chromeos/cros/mock_cryptohome_library.h
@@ -27,18 +27,18 @@ class MockCryptohomeLibrary : public CryptohomeLibrary {
MOCK_METHOD3(AsyncCheckKey, void(const std::string& user_email,
const std::string& passhash,
- Delegate* callback));
+ AsyncMethodCallback callback));
MOCK_METHOD4(AsyncMigrateKey, void(const std::string& user_email,
const std::string& old_hash,
const std::string& new_hash,
- Delegate* callback));
+ AsyncMethodCallback callback));
MOCK_METHOD4(AsyncMount, void(const std::string& user_email,
const std::string& passhash,
const bool create_if_missing,
- Delegate* callback));
- MOCK_METHOD1(AsyncMountGuest, void(Delegate* callback));
+ AsyncMethodCallback callback));
+ MOCK_METHOD1(AsyncMountGuest, void(AsyncMethodCallback callback));
MOCK_METHOD2(AsyncRemove, void(const std::string& user_email,
- Delegate* callback));
+ AsyncMethodCallback callback));
MOCK_METHOD0(IsMounted, bool(void));
MOCK_METHOD1(HashPassword, std::string(const std::string& password));
MOCK_METHOD0(GetSystemSalt, std::string(void));
@@ -66,8 +66,8 @@ class MockCryptohomeLibrary : public CryptohomeLibrary {
code_ = code;
}
- void DoCallback(Delegate* d) {
- d->OnComplete(outcome_, code_);
+ void DoCallback(AsyncMethodCallback callback) {
+ callback.Run(outcome_, code_);
}
private:
diff --git a/chrome/browser/chromeos/login/cryptohome_op.cc b/chrome/browser/chromeos/login/cryptohome_op.cc
deleted file mode 100644
index 7a8c1b1..0000000
--- a/chrome/browser/chromeos/login/cryptohome_op.cc
+++ /dev/null
@@ -1,197 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/chromeos/login/cryptohome_op.h"
-
-#include <string>
-
-#include "base/bind.h"
-#include "chrome/browser/chromeos/boot_times_loader.h"
-#include "chrome/browser/chromeos/cros/cros_library.h"
-#include "chrome/browser/chromeos/cros/cryptohome_library.h"
-#include "chrome/browser/chromeos/login/auth_attempt_state.h"
-#include "chrome/browser/chromeos/login/auth_attempt_state_resolver.h"
-#include "content/public/browser/browser_thread.h"
-
-using content::BrowserThread;
-
-namespace chromeos {
-
-CryptohomeOp::CryptohomeOp(AuthAttemptState* current_attempt,
- AuthAttemptStateResolver* callback)
- : attempt_(current_attempt),
- resolver_(callback) {
-}
-
-CryptohomeOp::~CryptohomeOp() {}
-
-void CryptohomeOp::OnComplete(bool success, int return_code) {
- chromeos::BootTimesLoader::Get()->AddLoginTimeMarker(
- "CryptohomeMount-End", false);
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&CryptohomeOp::TriggerResolve, this, success, return_code));
-}
-
-void CryptohomeOp::TriggerResolve(bool success, int return_code) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- attempt_->RecordCryptohomeStatus(success, return_code);
- resolver_->Resolve();
-}
-
-class MountAttempt : public CryptohomeOp {
- public:
- MountAttempt(AuthAttemptState* current_attempt,
- AuthAttemptStateResolver* callback,
- bool create_if_missing)
- : CryptohomeOp(current_attempt, callback),
- create_if_missing_(create_if_missing) {
- }
-
- virtual ~MountAttempt() {}
-
- void Initiate() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- chromeos::BootTimesLoader::Get()->AddLoginTimeMarker(
- "CryptohomeMount-Start", false);
- CryptohomeLibrary* lib = CrosLibrary::Get()->GetCryptohomeLibrary();
- lib->AsyncMount(attempt_->username, attempt_->ascii_hash,
- create_if_missing_, this);
- }
-
- private:
- const bool create_if_missing_;
- DISALLOW_COPY_AND_ASSIGN(MountAttempt);
-};
-
-class MountGuestAttempt : public CryptohomeOp {
- public:
- MountGuestAttempt(AuthAttemptState* current_attempt,
- AuthAttemptStateResolver* callback)
- : CryptohomeOp(current_attempt, callback) {
- }
-
- virtual ~MountGuestAttempt() {}
-
- void Initiate() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- CryptohomeLibrary* lib = CrosLibrary::Get()->GetCryptohomeLibrary();
- lib->AsyncMountGuest(this);
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MountGuestAttempt);
-};
-
-class MigrateAttempt : public CryptohomeOp {
- public:
- // TODO(cmasone): get rid of passing_old_hash arg, as it's always true.
- MigrateAttempt(AuthAttemptState* current_attempt,
- AuthAttemptStateResolver* callback,
- bool passing_old_hash,
- const std::string& hash)
- : CryptohomeOp(current_attempt, callback),
- is_old_hash_(passing_old_hash),
- hash_(hash) {
- }
-
- virtual ~MigrateAttempt() {}
-
- void Initiate() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- CryptohomeLibrary* lib = CrosLibrary::Get()->GetCryptohomeLibrary();
- if (is_old_hash_) {
- lib->AsyncMigrateKey(attempt_->username, hash_, attempt_->ascii_hash,
- this);
- } else {
- lib->AsyncMigrateKey(attempt_->username, attempt_->ascii_hash, hash_,
- this);
- }
- }
-
- private:
- const bool is_old_hash_;
- const std::string hash_;
-
- DISALLOW_COPY_AND_ASSIGN(MigrateAttempt);
-};
-
-class RemoveAttempt : public CryptohomeOp {
- public:
- RemoveAttempt(AuthAttemptState* current_attempt,
- AuthAttemptStateResolver* callback)
- : CryptohomeOp(current_attempt, callback) {
- }
-
- virtual ~RemoveAttempt() {}
-
- void Initiate() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- CryptohomeLibrary* lib = CrosLibrary::Get()->GetCryptohomeLibrary();
- lib->AsyncRemove(attempt_->username, this);
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(RemoveAttempt);
-};
-
-class CheckKeyAttempt : public CryptohomeOp {
- public:
- CheckKeyAttempt(AuthAttemptState* current_attempt,
- AuthAttemptStateResolver* callback)
- : CryptohomeOp(current_attempt, callback) {
- }
-
- virtual ~CheckKeyAttempt() {}
-
- void Initiate() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- CryptohomeLibrary* lib = CrosLibrary::Get()->GetCryptohomeLibrary();
- lib->AsyncCheckKey(attempt_->username, attempt_->ascii_hash, this);
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(CheckKeyAttempt);
-};
-
-// static
-CryptohomeOp* CryptohomeOp::CreateMountAttempt(
- AuthAttemptState* current_attempt,
- AuthAttemptStateResolver* callback,
- bool create_if_missing) {
- return new MountAttempt(current_attempt, callback, create_if_missing);
-}
-
-// static
-CryptohomeOp* CryptohomeOp::CreateMountGuestAttempt(
- AuthAttemptState* current_attempt,
- AuthAttemptStateResolver* callback) {
- return new MountGuestAttempt(current_attempt, callback);
-}
-
-// static
-CryptohomeOp* CryptohomeOp::CreateMigrateAttempt(
- AuthAttemptState* current_attempt,
- AuthAttemptStateResolver* callback,
- bool passing_old_hash,
- const std::string& hash) {
- return new MigrateAttempt(current_attempt, callback, passing_old_hash, hash);
-}
-
-// static
-CryptohomeOp* CryptohomeOp::CreateRemoveAttempt(
- AuthAttemptState* current_attempt,
- AuthAttemptStateResolver* callback) {
- return new RemoveAttempt(current_attempt, callback);
-}
-
-// static
-CryptohomeOp* CryptohomeOp::CreateCheckKeyAttempt(
- AuthAttemptState* current_attempt,
- AuthAttemptStateResolver* callback) {
-
- return new CheckKeyAttempt(current_attempt, callback);
-}
-
-} // namespace chromeos
diff --git a/chrome/browser/chromeos/login/cryptohome_op.h b/chrome/browser/chromeos/login/cryptohome_op.h
deleted file mode 100644
index eec093b..0000000
--- a/chrome/browser/chromeos/login/cryptohome_op.h
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_CRYPTOHOME_OP_H_
-#define CHROME_BROWSER_CHROMEOS_LOGIN_CRYPTOHOME_OP_H_
-#pragma once
-
-#include <string>
-
-#include "base/compiler_specific.h"
-#include "base/memory/ref_counted.h"
-#include "chrome/browser/chromeos/cros/cryptohome_library.h"
-
-namespace chromeos {
-class AuthAttemptState;
-class AuthAttemptStateResolver;
-
-class CryptohomeOp
- : public base::RefCountedThreadSafe<CryptohomeOp>,
- public CryptohomeLibrary::Delegate {
- public:
- static CryptohomeOp* CreateMountAttempt(AuthAttemptState* current_attempt,
- AuthAttemptStateResolver* callback,
- bool create_if_missing);
-
- static CryptohomeOp* CreateMountGuestAttempt(
- AuthAttemptState* current_attempt,
- AuthAttemptStateResolver* callback);
-
- static CryptohomeOp* CreateMigrateAttempt(AuthAttemptState* current_attempt,
- AuthAttemptStateResolver* callback,
- bool passing_old_hash,
- const std::string& hash);
-
- static CryptohomeOp* CreateRemoveAttempt(AuthAttemptState* current_attempt,
- AuthAttemptStateResolver* callback);
-
- static CryptohomeOp* CreateCheckKeyAttempt(
- AuthAttemptState* current_attempt,
- AuthAttemptStateResolver* callback);
-
- virtual void Initiate() = 0;
-
- // Implementation of CryptohomeLibrary::Delegate.
- virtual void OnComplete(bool success, int return_code) OVERRIDE;
-
- protected:
- CryptohomeOp(AuthAttemptState* current_attempt,
- AuthAttemptStateResolver* callback);
-
- virtual ~CryptohomeOp();
-
- virtual void TriggerResolve(bool offline_outcome, int offline_code);
-
- AuthAttemptState* const attempt_;
- AuthAttemptStateResolver* const resolver_;
-
- private:
- friend class base::RefCountedThreadSafe<CryptohomeOp>;
- DISALLOW_COPY_AND_ASSIGN(CryptohomeOp);
-};
-
-} // namespace chromeos
-
-#endif // CHROME_BROWSER_CHROMEOS_LOGIN_CRYPTOHOME_OP_H_
diff --git a/chrome/browser/chromeos/login/cryptohome_op_unittest.cc b/chrome/browser/chromeos/login/cryptohome_op_unittest.cc
deleted file mode 100644
index 198cc4f..0000000
--- a/chrome/browser/chromeos/login/cryptohome_op_unittest.cc
+++ /dev/null
@@ -1,238 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/chromeos/login/cryptohome_op.h"
-
-#include <string>
-
-#include "base/memory/ref_counted.h"
-#include "base/message_loop.h"
-#include "chrome/browser/chromeos/cros/cros_library.h"
-#include "chrome/browser/chromeos/cros/mock_cryptohome_library.h"
-#include "chrome/browser/chromeos/cros/mock_library_loader.h"
-#include "chrome/browser/chromeos/login/auth_attempt_state.h"
-#include "chrome/browser/chromeos/login/mock_auth_attempt_state_resolver.h"
-#include "chrome/browser/chromeos/login/test_attempt_state.h"
-#include "content/test/test_browser_thread.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/cros_system_api/dbus/service_constants.h"
-
-using content::BrowserThread;
-
-using ::testing::AnyNumber;
-using ::testing::Invoke;
-using ::testing::Return;
-using ::testing::_;
-
-namespace chromeos {
-
-class CryptohomeOpTest : public ::testing::Test {
- public:
- CryptohomeOpTest()
- : message_loop_(MessageLoop::TYPE_UI),
- ui_thread_(BrowserThread::UI, &message_loop_),
- io_thread_(BrowserThread::IO),
- username_("me@nowhere.org"),
- hash_ascii_("0a010000000000a0"),
- state_(username_, "", hash_ascii_, "", "", false),
- resolver_(new MockAuthAttemptStateResolver),
- mock_library_(new MockCryptohomeLibrary) {
- }
-
- virtual ~CryptohomeOpTest() {}
-
- virtual void SetUp() {
- CrosLibrary::TestApi* test_api = CrosLibrary::Get()->GetTestApi();
-
- MockLibraryLoader* loader = new MockLibraryLoader();
- ON_CALL(*loader, Load(_))
- .WillByDefault(Return(true));
- EXPECT_CALL(*loader, Load(_))
- .Times(AnyNumber());
-
- // Passes ownership of |loader| to CrosLibrary.
- test_api->SetLibraryLoader(loader, true);
- // |mock_library_| is mine, though.
- test_api->SetCryptohomeLibrary(mock_library_.get(), false);
- mock_library_->SetUp(false, 0);
-
- io_thread_.Start();
- }
-
- virtual void TearDown() {
- // Prevent bogus gMock leak check from firing.
- chromeos::CrosLibrary::TestApi* test_api =
- chromeos::CrosLibrary::Get()->GetTestApi();
- test_api->SetLibraryLoader(NULL, false);
- }
-
- void ExpectMigrate(bool passing_old_hash, const std::string& hash) {
- if (passing_old_hash) {
- EXPECT_CALL(*(mock_library_.get()), AsyncMigrateKey(username_,
- hash,
- hash_ascii_,
- _))
- .Times(1)
- .RetiresOnSaturation();
- } else {
- EXPECT_CALL(*(mock_library_.get()), AsyncMigrateKey(username_,
- hash_ascii_,
- hash,
- _))
- .Times(1)
- .RetiresOnSaturation();
- }
- }
-
- void ExpectMount() {
- EXPECT_CALL(*(mock_library_.get()),
- AsyncMount(username_, hash_ascii_, true, _))
- .Times(1)
- .RetiresOnSaturation();
- }
-
- void ExpectMountGuest() {
- EXPECT_CALL(*(mock_library_.get()), AsyncMountGuest(_))
- .Times(1)
- .RetiresOnSaturation();
- }
-
- void ExpectRemove() {
- EXPECT_CALL(*(mock_library_.get()), AsyncRemove(username_, _))
- .Times(1)
- .RetiresOnSaturation();
- }
-
- void ExpectCheckKey() {
- EXPECT_CALL(*(mock_library_.get()),
- AsyncCheckKey(username_, hash_ascii_, _))
- .Times(1)
- .RetiresOnSaturation();
- }
-
- void RunTest(CryptohomeOp* op, bool outcome, int code) {
- mock_library_->SetAsyncBehavior(outcome, code);
-
- EXPECT_CALL(*(resolver_.get()), Resolve())
- .Times(1)
- .RetiresOnSaturation();
-
- op->Initiate();
-
- // Force IO thread to finish tasks so I can verify |state_|.
- io_thread_.Stop();
-
- EXPECT_EQ(outcome, state_.cryptohome_outcome());
- EXPECT_EQ(code, state_.cryptohome_code());
- }
-
- MessageLoop message_loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread io_thread_;
- std::string username_;
- std::string hash_ascii_;
- TestAttemptState state_;
- scoped_ptr<MockAuthAttemptStateResolver> resolver_;
- scoped_refptr<CryptohomeOp> op_;
-
- // Initializes / shuts down a stub CrosLibrary.
- chromeos::ScopedStubCrosEnabler stub_cros_enabler_;
-
- // Provide a mock for testing cryptohome.
- scoped_ptr<MockCryptohomeLibrary> mock_library_;
-};
-
-TEST_F(CryptohomeOpTest, MountSuccess) {
- ExpectMount();
- scoped_refptr<CryptohomeOp> op(
- CryptohomeOp::CreateMountAttempt(&state_, resolver_.get(), true));
- RunTest(op.get(), true, cryptohome::MOUNT_ERROR_NONE);
-}
-
-TEST_F(CryptohomeOpTest, MountFatal) {
- ExpectMount();
- scoped_refptr<CryptohomeOp> op(
- CryptohomeOp::CreateMountAttempt(&state_, resolver_.get(), true));
- RunTest(op.get(), false, cryptohome::MOUNT_ERROR_FATAL);
-}
-
-TEST_F(CryptohomeOpTest, MountKeyFailure) {
- ExpectMount();
- scoped_refptr<CryptohomeOp> op(
- CryptohomeOp::CreateMountAttempt(&state_, resolver_.get(), true));
- RunTest(op.get(), false, cryptohome::MOUNT_ERROR_KEY_FAILURE);
-}
-
-TEST_F(CryptohomeOpTest, MountRecreated) {
- ExpectMount();
- scoped_refptr<CryptohomeOp> op(
- CryptohomeOp::CreateMountAttempt(&state_, resolver_.get(), true));
- RunTest(op.get(), true, cryptohome::MOUNT_ERROR_RECREATED);
-}
-
-TEST_F(CryptohomeOpTest, MountGuestSuccess) {
- ExpectMountGuest();
- scoped_refptr<CryptohomeOp> op(
- CryptohomeOp::CreateMountGuestAttempt(&state_, resolver_.get()));
- RunTest(op.get(), true, cryptohome::MOUNT_ERROR_NONE);
-}
-
-TEST_F(CryptohomeOpTest, MountGuestFatal) {
- ExpectMountGuest();
- scoped_refptr<CryptohomeOp> op(
- CryptohomeOp::CreateMountGuestAttempt(&state_, resolver_.get()));
- RunTest(op.get(), false, cryptohome::MOUNT_ERROR_FATAL);
-}
-
-TEST_F(CryptohomeOpTest, MigrateSuccessPassOld) {
- ExpectMigrate(true, "");
- scoped_refptr<CryptohomeOp> op(
- CryptohomeOp::CreateMigrateAttempt(&state_, resolver_.get(), true, ""));
- RunTest(op.get(), true, cryptohome::MOUNT_ERROR_NONE);
-}
-
-TEST_F(CryptohomeOpTest, MigrateSuccessPassNew) {
- ExpectMigrate(false, "");
- scoped_refptr<CryptohomeOp> op(
- CryptohomeOp::CreateMigrateAttempt(&state_, resolver_.get(), false, ""));
- RunTest(op.get(), true, cryptohome::MOUNT_ERROR_NONE);
-}
-
-TEST_F(CryptohomeOpTest, MigrateKeyFailure) {
- ExpectMigrate(true, "");
- scoped_refptr<CryptohomeOp> op(
- CryptohomeOp::CreateMigrateAttempt(&state_, resolver_.get(), true, ""));
- RunTest(op.get(), false, cryptohome::MOUNT_ERROR_KEY_FAILURE);
-}
-
-TEST_F(CryptohomeOpTest, RemoveSuccess) {
- ExpectRemove();
- scoped_refptr<CryptohomeOp> op(
- CryptohomeOp::CreateRemoveAttempt(&state_, resolver_.get()));
- RunTest(op.get(), true, cryptohome::MOUNT_ERROR_NONE);
-}
-
-TEST_F(CryptohomeOpTest, RemoveFailure) {
- ExpectRemove();
- scoped_refptr<CryptohomeOp> op(
- CryptohomeOp::CreateRemoveAttempt(&state_, resolver_.get()));
- RunTest(op.get(), false, cryptohome::MOUNT_ERROR_KEY_FAILURE);
-}
-
-TEST_F(CryptohomeOpTest, CheckKeySuccess) {
- ExpectCheckKey();
- scoped_refptr<CryptohomeOp> op(
- CryptohomeOp::CreateCheckKeyAttempt(&state_, resolver_.get()));
- RunTest(op.get(), true, cryptohome::MOUNT_ERROR_NONE);
-}
-
-TEST_F(CryptohomeOpTest, CheckKeyFailure) {
- ExpectCheckKey();
- scoped_refptr<CryptohomeOp> op(
- CryptohomeOp::CreateCheckKeyAttempt(&state_, resolver_.get()));
- RunTest(op.get(), false, cryptohome::MOUNT_ERROR_KEY_FAILURE);
-}
-
-} // namespace chromeos
diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc
index ad85f38..a709016 100644
--- a/chrome/browser/chromeos/login/login_utils.cc
+++ b/chrome/browser/chromeos/login/login_utils.cc
@@ -25,6 +25,8 @@
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/chromeos/boot_times_loader.h"
#include "chrome/browser/chromeos/cros/cert_library.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "chrome/browser/chromeos/cros/cryptohome_library.h"
#include "chrome/browser/chromeos/cros/network_library.h"
#include "chrome/browser/chromeos/cros_settings.h"
#include "chrome/browser/chromeos/cros_settings_names.h"
diff --git a/chrome/browser/chromeos/login/parallel_authenticator.cc b/chrome/browser/chromeos/login/parallel_authenticator.cc
index ae27986..76b36f7 100644
--- a/chrome/browser/chromeos/login/parallel_authenticator.cc
+++ b/chrome/browser/chromeos/login/parallel_authenticator.cc
@@ -4,9 +4,6 @@
#include "chrome/browser/chromeos/login/parallel_authenticator.h"
-#include <string>
-#include <vector>
-
#include "base/bind.h"
#include "base/command_line.h"
#include "base/file_path.h"
@@ -14,44 +11,168 @@
#include "base/logging.h"
#include "base/path_service.h"
#include "base/string_util.h"
-#include "base/synchronization/lock.h"
-#include "chrome/browser/chromeos/cros/cert_library.h"
+#include "chrome/browser/chromeos/boot_times_loader.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/cryptohome_library.h"
-#include "chrome/browser/chromeos/login/auth_response_handler.h"
#include "chrome/browser/chromeos/login/authentication_notification_details.h"
#include "chrome/browser/chromeos/login/login_status_consumer.h"
#include "chrome/browser/chromeos/login/ownership_service.h"
#include "chrome/browser/chromeos/login/user_manager.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
-#include "chrome/common/net/gaia/gaia_auth_fetcher.h"
-#include "chrome/common/net/gaia/gaia_constants.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
-#include "net/base/load_flags.h"
-#include "net/base/net_errors.h"
-#include "net/url_request/url_request_status.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
-#include "third_party/libjingle/source/talk/base/urlencode.h"
-using base::Time;
-using base::TimeDelta;
using content::BrowserThread;
-using file_util::GetFileSize;
-using file_util::PathExists;
-using file_util::ReadFile;
using file_util::ReadFileToString;
namespace chromeos {
-// static
-const int ParallelAuthenticator::kClientLoginTimeoutMs = 10000;
+namespace {
+
+// Milliseconds until we timeout our attempt to hit ClientLogin.
+const int kClientLoginTimeoutMs = 10000;
+
+// Records status and calls resolver->Resolve().
+void TriggerResolve(AuthAttemptState* attempt,
+ AuthAttemptStateResolver* resolver,
+ bool success,
+ int return_code) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ attempt->RecordCryptohomeStatus(success, return_code);
+ resolver->Resolve();
+}
+
+// Calls TriggerResolve on the IO thread.
+void TriggerResolveOnIoThread(AuthAttemptState* attempt,
+ AuthAttemptStateResolver* resolver,
+ bool success,
+ int return_code) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&TriggerResolve, attempt, resolver, success, return_code));
+}
+
+// Calls TriggerResolve on the IO thread while adding login time marker.
+void TriggerResolveOnIoThreadWithLoginTimeMarker(
+ const std::string& marker_name,
+ AuthAttemptState* attempt,
+ AuthAttemptStateResolver* resolver,
+ bool success,
+ int return_code) {
+ chromeos::BootTimesLoader::Get()->AddLoginTimeMarker(marker_name, false);
+ TriggerResolveOnIoThread(attempt, resolver, success, return_code);
+}
+
+// Calls cryptohome's mount method.
+void Mount(AuthAttemptState* attempt,
+ AuthAttemptStateResolver* resolver,
+ bool create_if_missing) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ chromeos::BootTimesLoader::Get()->AddLoginTimeMarker(
+ "CryptohomeMount-Start", false);
+ CrosLibrary::Get()->GetCryptohomeLibrary()->AsyncMount(
+ attempt->username,
+ attempt->ascii_hash,
+ create_if_missing,
+ base::Bind(&TriggerResolveOnIoThreadWithLoginTimeMarker,
+ "CryptohomeMount-End",
+ attempt,
+ resolver));
+}
+
+// Calls cryptohome's mount method for guest.
+void MountGuest(AuthAttemptState* attempt,
+ AuthAttemptStateResolver* resolver) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ CrosLibrary::Get()->GetCryptohomeLibrary()->AsyncMountGuest(
+ base::Bind(&TriggerResolveOnIoThreadWithLoginTimeMarker,
+ "CryptohomeMount-End",
+ attempt,
+ resolver));
+}
+
+// Calls cryptohome's key migration method.
+void Migrate(AuthAttemptState* attempt,
+ AuthAttemptStateResolver* resolver,
+ bool passing_old_hash,
+ const std::string& hash) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ chromeos::BootTimesLoader::Get()->AddLoginTimeMarker(
+ "CryptohomeMigrate-Start", false);
+ CryptohomeLibrary* lib = CrosLibrary::Get()->GetCryptohomeLibrary();
+ if (passing_old_hash) {
+ lib->AsyncMigrateKey(
+ attempt->username,
+ hash,
+ attempt->ascii_hash,
+ base::Bind(&TriggerResolveOnIoThreadWithLoginTimeMarker,
+ "CryptohomeMount-End",
+ attempt,
+ resolver));
+ } else {
+ lib->AsyncMigrateKey(
+ attempt->username,
+ attempt->ascii_hash,
+ hash,
+ base::Bind(&TriggerResolveOnIoThreadWithLoginTimeMarker,
+ "CryptohomeMount-End",
+ attempt,
+ resolver));
+ }
+}
+
+// Calls cryptohome's remove method.
+void Remove(AuthAttemptState* attempt,
+ AuthAttemptStateResolver* resolver) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ chromeos::BootTimesLoader::Get()->AddLoginTimeMarker(
+ "CryptohomeRemove-Start", false);
+ CrosLibrary::Get()->GetCryptohomeLibrary()->AsyncRemove(
+ attempt->username,
+ base::Bind(&TriggerResolveOnIoThreadWithLoginTimeMarker,
+ "CryptohomeRemove-End",
+ attempt,
+ resolver));
+}
+
+// Calls cryptohome's key check method.
+void CheckKey(AuthAttemptState* attempt,
+ AuthAttemptStateResolver* resolver) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ CrosLibrary::Get()->GetCryptohomeLibrary()->AsyncCheckKey(
+ attempt->username,
+ attempt->ascii_hash,
+ base::Bind(&TriggerResolveOnIoThread, attempt, resolver));
+}
+
+// Resets |current_state| and runs |callback| on the UI thread.
+void ResetCryptohomeStatusAndRunCallback(AuthAttemptState* current_state,
+ base::Closure callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ current_state->ResetCryptohomeStatus();
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
+}
+
+// Returns whether the login failure was connection issue.
+bool WasConnectionIssue(const LoginFailure& online_outcome) {
+ return ((online_outcome.reason() == LoginFailure::LOGIN_TIMED_OUT) ||
+ (online_outcome.error().state() ==
+ GoogleServiceAuthError::CONNECTION_FAILED) ||
+ (online_outcome.error().state() ==
+ GoogleServiceAuthError::REQUEST_CANCELED));
+}
+
+} // namespace
ParallelAuthenticator::ParallelAuthenticator(LoginStatusConsumer* consumer)
: Authenticator(consumer),
+ migrate_attempted_(false),
+ remove_attempted_(false),
+ mount_guest_attempted_(false),
+ check_key_attempted_(false),
already_reported_success_(false),
using_oauth_(
CommandLine::ForCurrentProcess()->HasSwitch(
@@ -81,14 +202,14 @@ void ParallelAuthenticator::AuthenticateToLogin(
login_token,
login_captcha,
!UserManager::Get()->IsKnownUser(canonicalized)));
- mounter_ = CryptohomeOp::CreateMountAttempt(current_state_.get(),
- this,
- false /* don't create */);
- // Sadly, this MUST be on the UI thread due to sending DBus traffic :-/
+ const bool create_if_missing = false;
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
+ base::Bind(&Mount,
+ current_state_.get(),
+ static_cast<AuthAttemptStateResolver*>(this),
+ create_if_missing));
- base::Bind(&CryptohomeOp::Initiate, mounter_.get()));
// ClientLogin authentication check should happen immediately here.
// We should not try OAuthLogin check until the profile loads.
if (!using_oauth_) {
@@ -111,13 +232,13 @@ void ParallelAuthenticator::CompleteLogin(Profile* profile,
password,
CrosLibrary::Get()->GetCryptohomeLibrary()->HashPassword(password),
!UserManager::Get()->IsKnownUser(canonicalized)));
- mounter_ = CryptohomeOp::CreateMountAttempt(current_state_.get(),
- this,
- false /* don't create */);
- // Sadly, this MUST be on the UI thread due to sending DBus traffic :-/
+ const bool create_if_missing = false;
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(&CryptohomeOp::Initiate, mounter_.get()));
+ base::Bind(&Mount,
+ current_state_.get(),
+ static_cast<AuthAttemptStateResolver*>(this),
+ create_if_missing));
if (!using_oauth_) {
// Test automation needs to disable oauth, but that leads to other
@@ -144,20 +265,20 @@ void ParallelAuthenticator::AuthenticateToUnlock(const std::string& username,
new AuthAttemptState(
Authenticator::Canonicalize(username),
CrosLibrary::Get()->GetCryptohomeLibrary()->HashPassword(password)));
- key_checker_ = CryptohomeOp::CreateCheckKeyAttempt(current_state_.get(),
- this);
- // Sadly, this MUST be on the UI thread due to sending DBus traffic :-/
+ check_key_attempted_ = true;
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(&CryptohomeOp::Initiate, key_checker_.get()));
+ base::Bind(&CheckKey,
+ current_state_.get(),
+ static_cast<AuthAttemptStateResolver*>(this)));
}
void ParallelAuthenticator::LoginOffTheRecord() {
- current_state_.reset(new AuthAttemptState("", "", "", "", "", false));
- guest_mounter_ =
- CryptohomeOp::CreateMountGuestAttempt(current_state_.get(), this);
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- guest_mounter_->Initiate();
+ current_state_.reset(new AuthAttemptState("", "", "", "", "", false));
+ mount_guest_attempted_ = true;
+ MountGuest(current_state_.get(),
+ static_cast<AuthAttemptStateResolver*>(this));
}
void ParallelAuthenticator::OnLoginSuccess(
@@ -225,32 +346,28 @@ void ParallelAuthenticator::RecoverEncryptedData(
const GaiaAuthConsumer::ClientLoginResult& credentials) {
std::string old_hash =
CrosLibrary::Get()->GetCryptohomeLibrary()->HashPassword(old_password);
- key_migrator_ = CryptohomeOp::CreateMigrateAttempt(current_state_.get(),
- this,
- true,
- old_hash);
+ migrate_attempted_ = true;
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- base::Bind(&ParallelAuthenticator::ResyncRecoverHelper, this,
- key_migrator_));
+ base::Bind(&ResetCryptohomeStatusAndRunCallback,
+ current_state_.get(),
+ base::Bind(&Migrate,
+ current_state_.get(),
+ static_cast<AuthAttemptStateResolver*>(this),
+ true,
+ old_hash)));
}
void ParallelAuthenticator::ResyncEncryptedData(
const GaiaAuthConsumer::ClientLoginResult& credentials) {
- data_remover_ =
- CryptohomeOp::CreateRemoveAttempt(current_state_.get(), this);
+ remove_attempted_ = true;
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- base::Bind(&ParallelAuthenticator::ResyncRecoverHelper, this,
- data_remover_));
-}
-
-void ParallelAuthenticator::ResyncRecoverHelper(CryptohomeOp* to_initiate) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- current_state_->ResetCryptohomeStatus();
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&CryptohomeOp::Initiate, to_initiate));
+ base::Bind(&ResetCryptohomeStatusAndRunCallback,
+ current_state_.get(),
+ base::Bind(&Remove,
+ current_state_.get(),
+ static_cast<AuthAttemptStateResolver*>(this))));
}
void ParallelAuthenticator::RetryAuth(Profile* profile,
@@ -308,7 +425,7 @@ void ParallelAuthenticator::Resolve() {
LoginFailure(LoginFailure::DATA_REMOVAL_FAILED)));
break;
case FAILED_TMPFS:
- // In this case, we tried to mount a tmpfs for BWSI and failed.
+ // In this case, we tried to mount a tmpfs for guest and failed.
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&ParallelAuthenticator::OnLoginFailure, this,
@@ -318,12 +435,12 @@ void ParallelAuthenticator::Resolve() {
create = true;
case RECOVER_MOUNT:
current_state_->ResetCryptohomeStatus();
- mounter_ = CryptohomeOp::CreateMountAttempt(current_state_.get(),
- this,
- create);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(&CryptohomeOp::Initiate, mounter_.get()));
+ base::Bind(&Mount,
+ current_state_.get(),
+ static_cast<AuthAttemptStateResolver*>(this),
+ create));
break;
case NEED_OLD_PW:
BrowserThread::PostTask(
@@ -373,14 +490,14 @@ void ParallelAuthenticator::Resolve() {
break;
}
case HAVE_NEW_PW:
- key_migrator_ =
- CryptohomeOp::CreateMigrateAttempt(reauth_state_.get(),
- this,
- true,
- current_state_->ascii_hash);
+ migrate_attempted_ = true;
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(&CryptohomeOp::Initiate, key_migrator_.get()));
+ base::Bind(&Migrate,
+ reauth_state_.get(),
+ static_cast<AuthAttemptStateResolver*>(this),
+ true,
+ current_state_->ascii_hash));
break;
case OFFLINE_LOGIN:
VLOG(2) << "Offline login";
@@ -441,10 +558,10 @@ ParallelAuthenticator::AuthState ParallelAuthenticator::ResolveState() {
state = ResolveCryptohomeFailureState();
DCHECK(current_state_->cryptohome_complete()); // Ensure invariant holds.
- key_migrator_ = NULL;
- data_remover_ = NULL;
- guest_mounter_ = NULL;
- key_checker_ = NULL;
+ migrate_attempted_ = false;
+ remove_attempted_ = false;
+ mount_guest_attempted_ = false;
+ check_key_attempted_ = false;
if (state != POSSIBLE_PW_CHANGE &&
state != NO_MOUNT &&
@@ -488,13 +605,13 @@ ParallelAuthenticator::ResolveReauthState() {
ParallelAuthenticator::AuthState
ParallelAuthenticator::ResolveCryptohomeFailureState() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- if (data_remover_.get())
+ if (remove_attempted_)
return FAILED_REMOVE;
- if (guest_mounter_.get())
+ if (mount_guest_attempted_)
return FAILED_TMPFS;
- if (key_migrator_.get())
+ if (migrate_attempted_)
return NEED_OLD_PW;
- if (key_checker_.get())
+ if (check_key_attempted_)
return LOGIN_FAILED;
// Return intermediate states in the following cases:
@@ -524,27 +641,17 @@ ParallelAuthenticator::ResolveCryptohomeFailureState() {
ParallelAuthenticator::AuthState
ParallelAuthenticator::ResolveCryptohomeSuccessState() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- if (data_remover_.get())
+ if (remove_attempted_)
return CREATE_NEW;
- if (guest_mounter_.get())
+ if (mount_guest_attempted_)
return GUEST_LOGIN;
- if (key_migrator_.get())
+ if (migrate_attempted_)
return RECOVER_MOUNT;
- if (key_checker_.get())
+ if (check_key_attempted_)
return UNLOCK;
return OFFLINE_LOGIN;
}
-namespace {
-bool WasConnectionIssue(const LoginFailure& online_outcome) {
- return ((online_outcome.reason() == LoginFailure::LOGIN_TIMED_OUT) ||
- (online_outcome.error().state() ==
- GoogleServiceAuthError::CONNECTION_FAILED) ||
- (online_outcome.error().state() ==
- GoogleServiceAuthError::REQUEST_CANCELED));
-}
-} // anonymous namespace
-
ParallelAuthenticator::AuthState
ParallelAuthenticator::ResolveOnlineFailureState(
ParallelAuthenticator::AuthState offline_state) {
diff --git a/chrome/browser/chromeos/login/parallel_authenticator.h b/chrome/browser/chromeos/login/parallel_authenticator.h
index fc50c38..0da87d9 100644
--- a/chrome/browser/chromeos/login/parallel_authenticator.h
+++ b/chrome/browser/chromeos/login/parallel_authenticator.h
@@ -7,39 +7,24 @@
#pragma once
#include <string>
-#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
-#include "base/gtest_prod_util.h"
-#include "base/memory/ref_counted.h"
+#include "base/synchronization/lock.h"
#include "base/memory/scoped_ptr.h"
-#include "chrome/browser/chromeos/cros/cros_library.h"
-#include "chrome/browser/chromeos/cros/cryptohome_library.h"
#include "chrome/browser/chromeos/login/authenticator.h"
#include "chrome/browser/chromeos/login/auth_attempt_state.h"
#include "chrome/browser/chromeos/login/auth_attempt_state_resolver.h"
#include "chrome/browser/chromeos/login/test_attempt_state.h"
-#include "chrome/browser/chromeos/login/cryptohome_op.h"
#include "chrome/browser/chromeos/login/online_attempt.h"
#include "chrome/common/net/gaia/gaia_auth_consumer.h"
-class GaiaAuthFetcher;
class LoginFailure;
class Profile;
-namespace base {
-class Lock;
-}
-
-namespace crypto {
-class SymmetricKey;
-}
-
namespace chromeos {
class LoginStatusConsumer;
-class ParallelAuthenticator;
class ResolveChecker;
// Authenticates a Chromium OS user against the Google Accounts ClientLogin API.
@@ -47,15 +32,15 @@ class ResolveChecker;
// Simultaneously attempts authentication both offline and online.
//
// At a high, level, here's what happens:
-// AuthenticateToLogin() creates an OnlineAttempt and a CryptohomeOp that
-// attempt to perform online and offline login simultaneously. When one of
+// AuthenticateToLogin() creates an OnlineAttempt and calls a Cryptohome's
+// method to perform online and offline login simultaneously. When one of
// these completes, it will store results in a AuthAttemptState owned by
// ParallelAuthenticator and then call Resolve(). Resolve() will attempt to
// determine which AuthState we're in, based on the info at hand.
// It then triggers further action based on the calculated AuthState; this
// further action might include calling back the passed-in LoginStatusConsumer
// to signal that login succeeded or failed, waiting for more outstanding
-// operations to complete, or triggering some more CryptohomeOps.
+// operations to complete, or triggering some more Cryptohome method calls.
class ParallelAuthenticator : public Authenticator,
public AuthAttemptStateResolver {
public:
@@ -206,11 +191,6 @@ class ParallelAuthenticator : public Authenticator,
current_online_ = attempt;
}
- // Resets |current_state_| and then posts a task to the UI thread to
- // Initiate() |to_initiate|.
- // Call this method on the IO thread.
- void ResyncRecoverHelper(CryptohomeOp* to_initiate);
-
// If we don't have the system salt yet, loads it from the CryptohomeLibrary.
void LoadSystemSalt();
// If we don't have supplemental_user_key_ yet, loads it from the NSS DB.
@@ -224,23 +204,16 @@ class ParallelAuthenticator : public Authenticator,
// an external authentication provider (i.e. GAIA extension).
void ResolveLoginCompletionStatus();
- // Milliseconds until we timeout our attempt to hit ClientLogin.
- static const int kClientLoginTimeoutMs;
-
- // Handles all net communications with Gaia.
- scoped_ptr<GaiaAuthFetcher> gaia_authenticator_;
-
// Used when we need to try online authentication again, after successful
// mount, but failed online login.
scoped_ptr<AuthAttemptState> reauth_state_;
scoped_ptr<AuthAttemptState> current_state_;
scoped_refptr<OnlineAttempt> current_online_;
- scoped_refptr<CryptohomeOp> mounter_;
- scoped_refptr<CryptohomeOp> key_migrator_;
- scoped_refptr<CryptohomeOp> data_remover_;
- scoped_refptr<CryptohomeOp> guest_mounter_;
- scoped_refptr<CryptohomeOp> key_checker_;
+ bool migrate_attempted_;
+ bool remove_attempted_;
+ bool mount_guest_attempted_;
+ bool check_key_attempted_;
// When the user has changed her password, but gives us the old one, we will
// be able to mount her cryptohome, but online authentication will fail.
diff --git a/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc b/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc
index 2b081b7..1670fad 100644
--- a/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc
+++ b/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc
@@ -5,7 +5,6 @@
#include "chrome/browser/chromeos/login/parallel_authenticator.h"
#include <string>
-#include <vector>
#include "base/bind.h"
#include "base/file_path.h"
@@ -16,9 +15,9 @@
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "base/test/thread_test_helper.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/mock_cryptohome_library.h"
#include "chrome/browser/chromeos/cros/mock_library_loader.h"
-#include "chrome/browser/chromeos/login/mock_auth_response_handler.h"
#include "chrome/browser/chromeos/login/mock_login_status_consumer.h"
#include "chrome/browser/chromeos/login/mock_url_fetchers.h"
#include "chrome/browser/chromeos/login/test_attempt_state.h"
diff --git a/chrome/browser/chromeos/login/user_manager.cc b/chrome/browser/chromeos/login/user_manager.cc
index ab85e77..0015fe1 100644
--- a/chrome/browser/chromeos/login/user_manager.cc
+++ b/chrome/browser/chromeos/login/user_manager.cc
@@ -150,74 +150,47 @@ void AddProfileImageTimeHistogram(ProfileDownloadResult result,
DVLOG(1) << "Profile image download time: " << time_delta.InSecondsF();
}
-// Used to handle the asynchronous response of deleting a cryptohome directory.
-class RemoveAttempt : public CryptohomeLibrary::Delegate {
- public:
- // Creates new remove attempt for the given user. Note, |delegate| can
- // be NULL.
- RemoveAttempt(const std::string& user_email,
- chromeos::RemoveUserDelegate* delegate)
- : user_email_(user_email),
- delegate_(delegate),
- weak_factory_(this) {
- RemoveUser();
+// Callback that is called after user removal is complete.
+void OnRemoveUserComplete(const std::string& user_email,
+ bool success,
+ int return_code) {
+ // Log the error, but there's not much we can do.
+ if (!success) {
+ LOG(ERROR) << "Removal of cryptohome for " << user_email
+ << " failed, return code: " << return_code;
}
+}
- virtual ~RemoveAttempt() {}
-
- void RemoveUser() {
- // Owner is not allowed to be removed from the device.
- // Must not proceed without signature verification.
- CrosSettings* cros_settings = CrosSettings::Get();
- bool trusted_owner_available = cros_settings->GetTrusted(
- kDeviceOwner,
- base::Bind(&RemoveAttempt::RemoveUser, weak_factory_.GetWeakPtr()));
- if (!trusted_owner_available) {
- // Value of owner email is still not verified.
- // Another attempt will be invoked after verification completion.
- return;
- }
- std::string owner;
- cros_settings->GetString(kDeviceOwner, &owner);
- if (user_email_ == owner) {
- // Owner is not allowed to be removed from the device. Probably on
- // the stack, so deffer the deletion.
- MessageLoop::current()->DeleteSoon(FROM_HERE, this);
- return;
- }
-
- if (delegate_)
- delegate_->OnBeforeUserRemoved(user_email_);
-
- chromeos::UserManager::Get()->RemoveUserFromList(user_email_);
- RemoveUserCryptohome();
-
- if (delegate_)
- delegate_->OnUserRemoved(user_email_);
- }
+// This method is used to implement UserManager::RemoveUser.
+void RemoveUserInternal(const std::string& user_email,
+ chromeos::RemoveUserDelegate* delegate) {
+ CrosSettings* cros_settings = CrosSettings::Get();
- void RemoveUserCryptohome() {
- CrosLibrary::Get()->GetCryptohomeLibrary()->AsyncRemove(user_email_, this);
+ // Ensure the value of owner email has been fetched.
+ if (!cros_settings->GetTrusted(
+ kDeviceOwner,
+ base::Bind(&RemoveUserInternal, user_email, delegate))) {
+ // Value of owner email is not fetched yet. RemoveUserInternal will be
+ // called again after fetch completion.
+ return;
}
-
- void OnComplete(bool success, int return_code) {
- // Log the error, but there's not much we can do.
- if (!success) {
- VLOG(1) << "Removal of cryptohome for " << user_email_
- << " failed, return code: " << return_code;
- }
- delete this;
+ std::string owner;
+ cros_settings->GetString(kDeviceOwner, &owner);
+ if (user_email == owner) {
+ // Owner is not allowed to be removed from the device.
+ return;
}
- private:
- std::string user_email_;
- chromeos::RemoveUserDelegate* delegate_;
+ if (delegate)
+ delegate->OnBeforeUserRemoved(user_email);
- // Factory of callbacks.
- base::WeakPtrFactory<RemoveAttempt> weak_factory_;
+ chromeos::UserManager::Get()->RemoveUserFromList(user_email);
+ CrosLibrary::Get()->GetCryptohomeLibrary()->AsyncRemove(
+ user_email, base::Bind(&OnRemoveUserComplete, user_email));
- DISALLOW_COPY_AND_ASSIGN(RemoveAttempt);
-};
+ if (delegate)
+ delegate->OnUserRemoved(user_email);
+}
class RealTPMTokenInfoDelegate : public crypto::TPMTokenInfoDelegate {
public:
@@ -392,8 +365,7 @@ void UserManager::RemoveUser(const std::string& email,
if (logged_in_user_ && logged_in_user_->email() == email)
return;
- // |RemoveAttempt| deletes itself when done.
- new RemoveAttempt(email, delegate);
+ RemoveUserInternal(email, delegate);
}
void UserManager::RemoveUserFromList(const std::string& email) {
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 6f15d77..3593258 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -571,8 +571,6 @@
'browser/chromeos/login/client_login_response_handler.h',
'browser/chromeos/login/cookie_fetcher.cc',
'browser/chromeos/login/cookie_fetcher.h',
- 'browser/chromeos/login/cryptohome_op.cc',
- 'browser/chromeos/login/cryptohome_op.h',
'browser/chromeos/login/default_user_images.cc',
'browser/chromeos/login/default_user_images.h',
'browser/chromeos/login/enrollment/enterprise_enrollment_screen.cc',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index a116a71..2d0f6d3 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1349,7 +1349,6 @@
'browser/chromeos/language_preferences_unittest.cc',
'browser/chromeos/login/authenticator_unittest.cc',
'browser/chromeos/login/cookie_fetcher_unittest.cc',
- 'browser/chromeos/login/cryptohome_op_unittest.cc',
'browser/chromeos/login/mock_auth_attempt_state_resolver.cc',
'browser/chromeos/login/mock_auth_attempt_state_resolver.h',
'browser/chromeos/login/mock_auth_response_handler.cc',