summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-27 05:11:04 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-27 05:11:04 +0000
commitc4a5d44787011c0e6385d9c7af92b773db79a4f4 (patch)
treeb05b2ab47155a3f2021b03973e82206675e44529 /chromeos
parentfbca94baffe12906f4888b9c45b688da133eadae (diff)
downloadchromium_src-c4a5d44787011c0e6385d9c7af92b773db79a4f4.zip
chromium_src-c4a5d44787011c0e6385d9c7af92b773db79a4f4.tar.gz
chromium_src-c4a5d44787011c0e6385d9c7af92b773db79a4f4.tar.bz2
cryptohome: Merge FakeCryptohomeClient and CryptohomeClinentStubImpl
The new FakeCryptohomeClient is based on CryptohomeClinentStubImpl. The only addition is set_unmout_result(). BUG=298729 TEST=the existing tests should pass R=hashimoto@chromium.org, stevenjb@chromium.org Review URL: https://codereview.chromium.org/24637004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@225664 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/chromeos.gyp13
-rw-r--r--chromeos/dbus/cryptohome_client.cc4
-rw-r--r--chromeos/dbus/cryptohome_client_stub.cc388
-rw-r--r--chromeos/dbus/cryptohome_client_stub.h167
-rw-r--r--chromeos/dbus/fake_cryptohome_client.cc414
-rw-r--r--chromeos/dbus/fake_cryptohome_client.h37
-rw-r--r--chromeos/dbus/fake_gsm_sms_client.h2
-rw-r--r--chromeos/dbus/fake_image_burner_client.h2
-rw-r--r--chromeos/dbus/fake_system_clock_client.h2
9 files changed, 281 insertions, 748 deletions
diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp
index 9683d3e..c0f7e85 100644
--- a/chromeos/chromeos.gyp
+++ b/chromeos/chromeos.gyp
@@ -85,8 +85,6 @@
'dbus/cros_disks_client.h',
'dbus/cryptohome_client.cc',
'dbus/cryptohome_client.h',
- 'dbus/cryptohome_client_stub.cc',
- 'dbus/cryptohome_client_stub.h',
'dbus/dbus_client_implementation_type.h',
'dbus/dbus_method_call_status.cc',
'dbus/dbus_method_call_status.h',
@@ -108,6 +106,8 @@
'dbus/fake_bluetooth_profile_manager_client.h',
'dbus/fake_bluetooth_profile_service_provider.cc',
'dbus/fake_bluetooth_profile_service_provider.h',
+ 'dbus/fake_cryptohome_client.cc',
+ 'dbus/fake_cryptohome_client.h',
'dbus/fake_gsm_sms_client.cc',
'dbus/fake_gsm_sms_client.h',
'dbus/fake_image_burner_client.cc',
@@ -402,6 +402,7 @@
'type': 'static_library',
'dependencies': [
'../build/linux/system.gyp:dbus',
+ '../crypto/crypto.gyp:crypto',
'../dbus/dbus.gyp:dbus',
'chromeos',
'power_manager_proto',
@@ -409,12 +410,6 @@
'sources': [
'dbus/fake_cros_disks_client.cc',
'dbus/fake_cros_disks_client.h',
- 'dbus/fake_cryptohome_client.cc',
- 'dbus/fake_cryptohome_client.h',
- 'dbus/fake_gsm_sms_client.cc',
- 'dbus/fake_gsm_sms_client.h',
- 'dbus/fake_image_burner_client.cc',
- 'dbus/fake_image_burner_client.h',
'dbus/fake_power_manager_client.cc',
'dbus/fake_power_manager_client.h',
'dbus/fake_session_manager_client.cc',
@@ -423,8 +418,6 @@
'dbus/fake_shill_device_client.h',
'dbus/fake_shill_manager_client.cc',
'dbus/fake_shill_manager_client.h',
- 'dbus/fake_system_clock_client.cc',
- 'dbus/fake_system_clock_client.h',
'dbus/fake_update_engine_client.cc',
'dbus/fake_update_engine_client.h',
'dbus/mock_dbus_thread_manager_without_gmock.cc',
diff --git a/chromeos/dbus/cryptohome_client.cc b/chromeos/dbus/cryptohome_client.cc
index c117f58..cd027e3 100644
--- a/chromeos/dbus/cryptohome_client.cc
+++ b/chromeos/dbus/cryptohome_client.cc
@@ -10,7 +10,7 @@
#include "base/message_loop/message_loop.h"
#include "chromeos/cryptohome/async_method_caller.h"
#include "chromeos/dbus/blocking_method_caller.h"
-#include "chromeos/dbus/cryptohome_client_stub.h"
+#include "chromeos/dbus/fake_cryptohome_client.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "dbus/object_path.h"
@@ -857,7 +857,7 @@ CryptohomeClient* CryptohomeClient::Create(DBusClientImplementationType type) {
if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
return new CryptohomeClientImpl();
DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
- return new CryptohomeClientStubImpl();
+ return new FakeCryptohomeClient();
}
// static
diff --git a/chromeos/dbus/cryptohome_client_stub.cc b/chromeos/dbus/cryptohome_client_stub.cc
deleted file mode 100644
index 008dbf0..0000000
--- a/chromeos/dbus/cryptohome_client_stub.cc
+++ /dev/null
@@ -1,388 +0,0 @@
-// Copyright 2013 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 "chromeos/dbus/cryptohome_client_stub.h"
-
-#include "base/bind.h"
-#include "base/location.h"
-#include "base/message_loop/message_loop.h"
-#include "crypto/nss_util.h"
-#include "third_party/cros_system_api/dbus/service_constants.h"
-
-namespace chromeos {
-
-CryptohomeClientStubImpl::CryptohomeClientStubImpl()
- : async_call_id_(1),
- tpm_is_ready_counter_(0),
- locked_(false),
- weak_ptr_factory_(this) {}
-
-CryptohomeClientStubImpl::~CryptohomeClientStubImpl() {}
-
-void CryptohomeClientStubImpl::Init(dbus::Bus* bus) {
-}
-
-void CryptohomeClientStubImpl::SetAsyncCallStatusHandlers(
- const AsyncCallStatusHandler& handler,
- const AsyncCallStatusWithDataHandler& data_handler) {
- async_call_status_handler_ = handler;
- async_call_status_data_handler_ = data_handler;
-}
-
-void CryptohomeClientStubImpl::ResetAsyncCallStatusHandlers() {
- async_call_status_handler_.Reset();
- async_call_status_data_handler_.Reset();
-}
-
-void CryptohomeClientStubImpl::IsMounted(
- const BoolDBusMethodCallback& callback) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
-}
-
-bool CryptohomeClientStubImpl::Unmount(bool* success) {
- *success = true;
- return true;
-}
-
-void CryptohomeClientStubImpl::AsyncCheckKey(
- const std::string& username,
- const std::string& key,
- const AsyncMethodCallback& callback) {
- ReturnAsyncMethodResult(callback, false);
-}
-
-void CryptohomeClientStubImpl::AsyncMigrateKey(
- const std::string& username,
- const std::string& from_key,
- const std::string& to_key,
- const AsyncMethodCallback& callback) {
- ReturnAsyncMethodResult(callback, false);
-}
-
-void CryptohomeClientStubImpl::AsyncRemove(
- const std::string& username,
- const AsyncMethodCallback& callback) {
- ReturnAsyncMethodResult(callback, false);
-}
-
-bool CryptohomeClientStubImpl::GetSystemSalt(std::vector<uint8>* salt) {
- const char kStubSystemSalt[] = "stub_system_salt";
- salt->assign(kStubSystemSalt,
- kStubSystemSalt + arraysize(kStubSystemSalt) - 1);
- return true;
-}
-
-void CryptohomeClientStubImpl::GetSanitizedUsername(
- const std::string& username,
- const StringDBusMethodCallback& callback) {
- // Even for stub implementation we have to return different values so that
- // multi-profiles would work.
- std::string sanitized_username = GetStubSanitizedUsername(username);
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, sanitized_username));
-}
-
-std::string CryptohomeClientStubImpl::BlockingGetSanitizedUsername(
- const std::string& username) {
- return GetStubSanitizedUsername(username);
-}
-
-void CryptohomeClientStubImpl::AsyncMount(const std::string& username,
- const std::string& key,
- int flags,
- const AsyncMethodCallback& callback) {
- ReturnAsyncMethodResult(callback, false);
-}
-
-void CryptohomeClientStubImpl::AsyncAddKey(
- const std::string& username,
- const std::string& key,
- const std::string& new_key,
- const AsyncMethodCallback& callback) {
- ReturnAsyncMethodResult(callback, false);
-}
-
-void CryptohomeClientStubImpl::AsyncMountGuest(
- const AsyncMethodCallback& callback) {
- ReturnAsyncMethodResult(callback, false);
-}
-
-void CryptohomeClientStubImpl::AsyncMountPublic(
- const std::string& public_mount_id,
- int flags,
- const AsyncMethodCallback& callback) {
- ReturnAsyncMethodResult(callback, false);
-}
-
-void CryptohomeClientStubImpl::TpmIsReady(
- const BoolDBusMethodCallback& callback) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
-}
-
-void CryptohomeClientStubImpl::TpmIsEnabled(
- const BoolDBusMethodCallback& callback) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
-}
-
-bool CryptohomeClientStubImpl::CallTpmIsEnabledAndBlock(bool* enabled) {
- *enabled = true;
- return true;
-}
-
-void CryptohomeClientStubImpl::TpmGetPassword(
- const StringDBusMethodCallback& callback) {
- const char kStubTpmPassword[] = "Stub-TPM-password";
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(callback, DBUS_METHOD_CALL_SUCCESS,
- std::string(kStubTpmPassword)));
-}
-
-void CryptohomeClientStubImpl::TpmIsOwned(
- const BoolDBusMethodCallback& callback) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
-}
-
-bool CryptohomeClientStubImpl::CallTpmIsOwnedAndBlock(bool* owned) {
- *owned = true;
- return true;
-}
-
-void CryptohomeClientStubImpl::TpmIsBeingOwned(
- const BoolDBusMethodCallback& callback) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
-}
-
-bool CryptohomeClientStubImpl::CallTpmIsBeingOwnedAndBlock(bool* owning) {
- *owning = true;
- return true;
-}
-
-void CryptohomeClientStubImpl::TpmCanAttemptOwnership(
- const VoidDBusMethodCallback& callback) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS));
-}
-
-void CryptohomeClientStubImpl::TpmClearStoredPassword(
- const VoidDBusMethodCallback& callback) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS));
-}
-
-bool CryptohomeClientStubImpl::CallTpmClearStoredPasswordAndBlock() {
- return true;
-}
-
-void CryptohomeClientStubImpl::Pkcs11IsTpmTokenReady(
- const BoolDBusMethodCallback& callback) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
-}
-
-void CryptohomeClientStubImpl::Pkcs11GetTpmTokenInfo(
- const Pkcs11GetTpmTokenInfoCallback& callback) {
- const char kStubUserPin[] = "012345";
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(callback,
- DBUS_METHOD_CALL_SUCCESS,
- std::string(crypto::kTestTPMTokenName),
- std::string(kStubUserPin)));
-}
-
-bool CryptohomeClientStubImpl::InstallAttributesGet(const std::string& name,
- std::vector<uint8>* value,
- bool* successful) {
- if (install_attrs_.find(name) != install_attrs_.end()) {
- *value = install_attrs_[name];
- *successful = true;
- } else {
- value->clear();
- *successful = false;
- }
- return true;
-}
-
-bool CryptohomeClientStubImpl::InstallAttributesSet(
- const std::string& name,
- const std::vector<uint8>& value,
- bool* successful) {
- install_attrs_[name] = value;
- *successful = true;
- return true;
-}
-
-bool CryptohomeClientStubImpl::InstallAttributesFinalize(bool* successful) {
- locked_ = true;
- *successful = true;
- return true;
-}
-
-void CryptohomeClientStubImpl::InstallAttributesIsReady(
- const BoolDBusMethodCallback& callback) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
-}
-
-bool CryptohomeClientStubImpl::InstallAttributesIsInvalid(bool* is_invalid) {
- *is_invalid = false;
- return true;
-}
-
-bool CryptohomeClientStubImpl::InstallAttributesIsFirstInstall(
- bool* is_first_install) {
- *is_first_install = !locked_;
- return true;
-}
-
-void CryptohomeClientStubImpl::TpmAttestationIsPrepared(
- const BoolDBusMethodCallback& callback) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
-}
-
-void CryptohomeClientStubImpl::TpmAttestationIsEnrolled(
- const BoolDBusMethodCallback& callback) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
-}
-
-void CryptohomeClientStubImpl::AsyncTpmAttestationCreateEnrollRequest(
- const AsyncMethodCallback& callback) {
- ReturnAsyncMethodResult(callback, true);
-}
-
-void CryptohomeClientStubImpl::AsyncTpmAttestationEnroll(
- const std::string& pca_response,
- const AsyncMethodCallback& callback) {
- ReturnAsyncMethodResult(callback, false);
-}
-
-void CryptohomeClientStubImpl::AsyncTpmAttestationCreateCertRequest(
- attestation::AttestationCertificateProfile certificate_profile,
- const std::string& user_email,
- const std::string& request_origin,
- const AsyncMethodCallback& callback) {
- ReturnAsyncMethodResult(callback, true);
-}
-
-void CryptohomeClientStubImpl::AsyncTpmAttestationFinishCertRequest(
- const std::string& pca_response,
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const AsyncMethodCallback& callback) {
- ReturnAsyncMethodResult(callback, true);
-}
-
-void CryptohomeClientStubImpl::TpmAttestationDoesKeyExist(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const BoolDBusMethodCallback& callback) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false));
-}
-
-void CryptohomeClientStubImpl::TpmAttestationGetCertificate(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const DataMethodCallback& callback) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string()));
-}
-
-void CryptohomeClientStubImpl::TpmAttestationGetPublicKey(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const DataMethodCallback& callback) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string()));
-}
-
-void CryptohomeClientStubImpl::TpmAttestationRegisterKey(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const AsyncMethodCallback& callback) {
- ReturnAsyncMethodResult(callback, true);
-}
-
-void CryptohomeClientStubImpl::TpmAttestationSignEnterpriseChallenge(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const std::string& domain,
- const std::string& device_id,
- attestation::AttestationChallengeOptions options,
- const std::string& challenge,
- const AsyncMethodCallback& callback) {
- ReturnAsyncMethodResult(callback, true);
-}
-
-void CryptohomeClientStubImpl::TpmAttestationSignSimpleChallenge(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const std::string& challenge,
- const AsyncMethodCallback& callback) {
- ReturnAsyncMethodResult(callback, true);
-}
-
-void CryptohomeClientStubImpl::TpmAttestationGetKeyPayload(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const DataMethodCallback& callback) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string()));
-}
-
-void CryptohomeClientStubImpl::TpmAttestationSetKeyPayload(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const std::string& payload,
- const BoolDBusMethodCallback& callback) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false));
-}
-
-void CryptohomeClientStubImpl::ReturnAsyncMethodResult(
- const AsyncMethodCallback& callback,
- bool returns_data) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(&CryptohomeClientStubImpl::ReturnAsyncMethodResultInternal,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- returns_data));
-}
-
-void CryptohomeClientStubImpl::ReturnAsyncMethodResultInternal(
- const AsyncMethodCallback& callback,
- bool returns_data) {
- callback.Run(async_call_id_);
- if (!returns_data && !async_call_status_handler_.is_null()) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(async_call_status_handler_,
- async_call_id_,
- true,
- cryptohome::MOUNT_ERROR_NONE));
- } else if (returns_data && !async_call_status_data_handler_.is_null()) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(async_call_status_data_handler_,
- async_call_id_,
- true,
- std::string()));
- }
- ++async_call_id_;
-}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/cryptohome_client_stub.h b/chromeos/dbus/cryptohome_client_stub.h
deleted file mode 100644
index 0e90f88..0000000
--- a/chromeos/dbus/cryptohome_client_stub.h
+++ /dev/null
@@ -1,167 +0,0 @@
-// Copyright 2013 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 CHROMEOS_DBUS_CRYPTOHOME_CLIENT_STUB_H_
-#define CHROMEOS_DBUS_CRYPTOHOME_CLIENT_STUB_H_
-
-#include <map>
-
-#include "base/basictypes.h"
-#include "base/memory/weak_ptr.h"
-#include "chromeos/dbus/cryptohome_client.h"
-
-namespace chromeos {
-
-class CHROMEOS_EXPORT CryptohomeClientStubImpl : public CryptohomeClient {
- public:
- CryptohomeClientStubImpl();
- virtual ~CryptohomeClientStubImpl();
-
- virtual void Init(dbus::Bus* bus) OVERRIDE;
- virtual void SetAsyncCallStatusHandlers(
- const AsyncCallStatusHandler& handler,
- const AsyncCallStatusWithDataHandler& data_handler) OVERRIDE;
- virtual void ResetAsyncCallStatusHandlers() OVERRIDE;
- virtual void IsMounted(const BoolDBusMethodCallback& callback) OVERRIDE;
- virtual bool Unmount(bool* success) OVERRIDE;
- virtual void AsyncCheckKey(const std::string& username,
- const std::string& key,
- const AsyncMethodCallback& callback) OVERRIDE;
- virtual void AsyncMigrateKey(const std::string& username,
- const std::string& from_key,
- const std::string& to_key,
- const AsyncMethodCallback& callback) OVERRIDE;
- virtual void AsyncRemove(const std::string& username,
- const AsyncMethodCallback& callback) OVERRIDE;
- virtual bool GetSystemSalt(std::vector<uint8>* salt) OVERRIDE;
- virtual void GetSanitizedUsername(
- const std::string& username,
- const StringDBusMethodCallback& callback) OVERRIDE;
- virtual std::string BlockingGetSanitizedUsername(
- const std::string& username) OVERRIDE;
- virtual void AsyncMount(const std::string& username,
- const std::string& key,
- int flags,
- const AsyncMethodCallback& callback) OVERRIDE;
- virtual void AsyncAddKey(const std::string& username,
- const std::string& key,
- const std::string& new_key,
- const AsyncMethodCallback& callback) OVERRIDE;
- virtual void AsyncMountGuest(const AsyncMethodCallback& callback) OVERRIDE;
- virtual void AsyncMountPublic(const std::string& public_mount_id,
- int flags,
- const AsyncMethodCallback& callback) OVERRIDE;
- virtual void TpmIsReady(const BoolDBusMethodCallback& callback) OVERRIDE;
- virtual void TpmIsEnabled(const BoolDBusMethodCallback& callback) OVERRIDE;
- virtual bool CallTpmIsEnabledAndBlock(bool* enabled) OVERRIDE;
- virtual void TpmGetPassword(
- const StringDBusMethodCallback& callback) OVERRIDE;
- virtual void TpmIsOwned(const BoolDBusMethodCallback& callback) OVERRIDE;
- virtual bool CallTpmIsOwnedAndBlock(bool* owned) OVERRIDE;
- virtual void TpmIsBeingOwned(const BoolDBusMethodCallback& callback) OVERRIDE;
- virtual bool CallTpmIsBeingOwnedAndBlock(bool* owning) OVERRIDE;
- virtual void TpmCanAttemptOwnership(
- const VoidDBusMethodCallback& callback) OVERRIDE;
- virtual void TpmClearStoredPassword(
- const VoidDBusMethodCallback& callback) OVERRIDE;
- virtual bool CallTpmClearStoredPasswordAndBlock() OVERRIDE;
- virtual void Pkcs11IsTpmTokenReady(
- const BoolDBusMethodCallback& callback) OVERRIDE;
- virtual void Pkcs11GetTpmTokenInfo(
- const Pkcs11GetTpmTokenInfoCallback& callback) OVERRIDE;
- virtual bool InstallAttributesGet(const std::string& name,
- std::vector<uint8>* value,
- bool* successful) OVERRIDE;
- virtual bool InstallAttributesSet(const std::string& name,
- const std::vector<uint8>& value,
- bool* successful) OVERRIDE;
- virtual bool InstallAttributesFinalize(bool* successful) OVERRIDE;
- virtual void InstallAttributesIsReady(
- const BoolDBusMethodCallback& callback) OVERRIDE;
- virtual bool InstallAttributesIsInvalid(bool* is_invalid) OVERRIDE;
- virtual bool InstallAttributesIsFirstInstall(bool* is_first_install) OVERRIDE;
- virtual void TpmAttestationIsPrepared(
- const BoolDBusMethodCallback& callback) OVERRIDE;
- virtual void TpmAttestationIsEnrolled(
- const BoolDBusMethodCallback& callback) OVERRIDE;
- virtual void AsyncTpmAttestationCreateEnrollRequest(
- const AsyncMethodCallback& callback) OVERRIDE;
- virtual void AsyncTpmAttestationEnroll(
- const std::string& pca_response,
- const AsyncMethodCallback& callback) OVERRIDE;
- virtual void AsyncTpmAttestationCreateCertRequest(
- attestation::AttestationCertificateProfile certificate_profile,
- const std::string& user_email,
- const std::string& request_origin,
- const AsyncMethodCallback& callback) OVERRIDE;
- virtual void AsyncTpmAttestationFinishCertRequest(
- const std::string& pca_response,
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const AsyncMethodCallback& callback) OVERRIDE;
- virtual void TpmAttestationDoesKeyExist(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const BoolDBusMethodCallback& callback) OVERRIDE;
- virtual void TpmAttestationGetCertificate(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const DataMethodCallback& callback) OVERRIDE;
- virtual void TpmAttestationGetPublicKey(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const DataMethodCallback& callback) OVERRIDE;
- virtual void TpmAttestationRegisterKey(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const AsyncMethodCallback& callback) OVERRIDE;
- virtual void TpmAttestationSignEnterpriseChallenge(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const std::string& domain,
- const std::string& device_id,
- attestation::AttestationChallengeOptions options,
- const std::string& challenge,
- const AsyncMethodCallback& callback) OVERRIDE;
- virtual void TpmAttestationSignSimpleChallenge(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const std::string& challenge,
- const AsyncMethodCallback& callback) OVERRIDE;
- virtual void TpmAttestationGetKeyPayload(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const DataMethodCallback& callback) OVERRIDE;
- virtual void TpmAttestationSetKeyPayload(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const std::string& payload,
- const BoolDBusMethodCallback& callback) OVERRIDE;
-
- private:
- // Posts tasks which return fake results to the UI thread.
- void ReturnAsyncMethodResult(const AsyncMethodCallback& callback,
- bool returns_data);
-
- // This method is used to implement ReturnAsyncMethodResult.
- void ReturnAsyncMethodResultInternal(const AsyncMethodCallback& callback,
- bool returns_data);
-
- int async_call_id_;
- AsyncCallStatusHandler async_call_status_handler_;
- AsyncCallStatusWithDataHandler async_call_status_data_handler_;
- int tpm_is_ready_counter_;
-
- // A stub store for InstallAttributes, mapping an attribute name to the
- // associated data blob. Used to implement InstallAttributesSet and -Get.
- std::map<std::string, std::vector<uint8> > install_attrs_;
- bool locked_;
- base::WeakPtrFactory<CryptohomeClientStubImpl> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(CryptohomeClientStubImpl);
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_CRYPTOHOME_CLIENT_STUB_H_
diff --git a/chromeos/dbus/fake_cryptohome_client.cc b/chromeos/dbus/fake_cryptohome_client.cc
index 1d224d9..67883c5 100644
--- a/chromeos/dbus/fake_cryptohome_client.cc
+++ b/chromeos/dbus/fake_cryptohome_client.cc
@@ -1,33 +1,45 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 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 "chromeos/dbus/fake_cryptohome_client.h"
#include "base/bind.h"
+#include "base/location.h"
#include "base/message_loop/message_loop.h"
+#include "crypto/nss_util.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
namespace chromeos {
-namespace {
+FakeCryptohomeClient::FakeCryptohomeClient()
+ : async_call_id_(1),
+ tpm_is_ready_counter_(0),
+ unmount_result_(true),
+ locked_(false),
+ weak_ptr_factory_(this) {}
-// A fake system salt. GetSystemSalt copies it to the given buffer.
-const char kStubSystemSalt[] = "stub_system_salt";
+FakeCryptohomeClient::~FakeCryptohomeClient() {}
-} // namespace
-
-FakeCryptohomeClient::FakeCryptohomeClient() : unmount_result_(false) {
+void FakeCryptohomeClient::Init(dbus::Bus* bus) {
}
-FakeCryptohomeClient::~FakeCryptohomeClient() {
+void FakeCryptohomeClient::SetAsyncCallStatusHandlers(
+ const AsyncCallStatusHandler& handler,
+ const AsyncCallStatusWithDataHandler& data_handler) {
+ async_call_status_handler_ = handler;
+ async_call_status_data_handler_ = data_handler;
}
-void FakeCryptohomeClient::Init(dbus::Bus* bus) {
+void FakeCryptohomeClient::ResetAsyncCallStatusHandlers() {
+ async_call_status_handler_.Reset();
+ async_call_status_data_handler_.Reset();
}
-void FakeCryptohomeClient::TpmIsBeingOwned(
+void FakeCryptohomeClient::IsMounted(
const BoolDBusMethodCallback& callback) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
}
bool FakeCryptohomeClient::Unmount(bool* success) {
@@ -35,242 +47,273 @@ bool FakeCryptohomeClient::Unmount(bool* success) {
return true;
}
-void FakeCryptohomeClient::AsyncCheckKey(const std::string& username,
- const std::string& key,
- const AsyncMethodCallback& callback) {
-}
-
-bool FakeCryptohomeClient::InstallAttributesIsInvalid(bool* is_invalid) {
- return false;
-}
-
-void FakeCryptohomeClient::TpmAttestationGetKeyPayload(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const DataMethodCallback& callback) {
+void FakeCryptohomeClient::AsyncCheckKey(
+ const std::string& username,
+ const std::string& key,
+ const AsyncMethodCallback& callback) {
+ ReturnAsyncMethodResult(callback, false);
}
-void FakeCryptohomeClient::AsyncTpmAttestationFinishCertRequest(
- const std::string& pca_response,
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
+void FakeCryptohomeClient::AsyncMigrateKey(
+ const std::string& username,
+ const std::string& from_key,
+ const std::string& to_key,
const AsyncMethodCallback& callback) {
+ ReturnAsyncMethodResult(callback, false);
}
-void FakeCryptohomeClient::TpmIsEnabled(
- const BoolDBusMethodCallback& callback) {
+void FakeCryptohomeClient::AsyncRemove(
+ const std::string& username,
+ const AsyncMethodCallback& callback) {
+ ReturnAsyncMethodResult(callback, false);
}
-void FakeCryptohomeClient::AsyncTpmAttestationEnroll(
- const std::string& pca_response,
- const AsyncMethodCallback& callback) {
+bool FakeCryptohomeClient::GetSystemSalt(std::vector<uint8>* salt) {
+ const char kStubSystemSalt[] = "stub_system_salt";
+ salt->assign(kStubSystemSalt,
+ kStubSystemSalt + arraysize(kStubSystemSalt) - 1);
+ return true;
}
-void FakeCryptohomeClient::AsyncMigrateKey(
+void FakeCryptohomeClient::GetSanitizedUsername(
const std::string& username,
- const std::string& from_key,
- const std::string& to_key,
- const AsyncMethodCallback& callback) {
+ const StringDBusMethodCallback& callback) {
+ // Even for stub implementation we have to return different values so that
+ // multi-profiles would work.
+ std::string sanitized_username = GetStubSanitizedUsername(username);
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, sanitized_username));
}
-void FakeCryptohomeClient::IsMounted(const BoolDBusMethodCallback& callback) {
- base::MessageLoop::current()->PostTask(FROM_HERE,
- base::Bind(callback,
- DBUS_METHOD_CALL_SUCCESS, true));
+std::string FakeCryptohomeClient::BlockingGetSanitizedUsername(
+ const std::string& username) {
+ return GetStubSanitizedUsername(username);
}
-bool FakeCryptohomeClient::InstallAttributesGet(const std::string& name,
- std::vector<uint8>* value,
- bool* successful) {
- return false;
+void FakeCryptohomeClient::AsyncMount(const std::string& username,
+ const std::string& key,
+ int flags,
+ const AsyncMethodCallback& callback) {
+ ReturnAsyncMethodResult(callback, false);
}
-void FakeCryptohomeClient::AsyncMount(const std::string& username,
- const std::string& key, int flags,
- const AsyncMethodCallback& callback) {
- DCHECK(!callback.is_null());
-
- base::MessageLoop::current()->PostTask(FROM_HERE,
- base::Bind(callback, 1 /* async_id */));
- if (!handler_.is_null())
- base::MessageLoop::current()->PostTask(FROM_HERE,
- base::Bind(handler_,
- 1, // async_id
- true, // return_status
- cryptohome::MOUNT_ERROR_NONE));
-}
-
-void FakeCryptohomeClient::AsyncAddKey(const std::string& username,
- const std::string& key,
- const std::string& new_key,
- const AsyncMethodCallback& callback) {
- DCHECK(!callback.is_null());
-
- base::MessageLoop::current()->PostTask(FROM_HERE,
- base::Bind(callback, 1 /* async_id */));
- if (!handler_.is_null())
- base::MessageLoop::current()->PostTask(FROM_HERE,
- base::Bind(handler_,
- 1, // async_id
- true, // return_status
- cryptohome::MOUNT_ERROR_NONE));
+void FakeCryptohomeClient::AsyncAddKey(
+ const std::string& username,
+ const std::string& key,
+ const std::string& new_key,
+ const AsyncMethodCallback& callback) {
+ ReturnAsyncMethodResult(callback, false);
}
void FakeCryptohomeClient::AsyncMountGuest(
const AsyncMethodCallback& callback) {
+ ReturnAsyncMethodResult(callback, false);
}
void FakeCryptohomeClient::AsyncMountPublic(
const std::string& public_mount_id,
int flags,
const AsyncMethodCallback& callback) {
+ ReturnAsyncMethodResult(callback, false);
}
-bool FakeCryptohomeClient::CallTpmIsBeingOwnedAndBlock(bool* owning) {
- return false;
+void FakeCryptohomeClient::TpmIsReady(
+ const BoolDBusMethodCallback& callback) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
}
-void FakeCryptohomeClient::Pkcs11IsTpmTokenReady(
+void FakeCryptohomeClient::TpmIsEnabled(
const BoolDBusMethodCallback& callback) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
}
-void FakeCryptohomeClient::TpmClearStoredPassword(
- const VoidDBusMethodCallback& callback) {
+bool FakeCryptohomeClient::CallTpmIsEnabledAndBlock(bool* enabled) {
+ *enabled = true;
+ return true;
+}
+
+void FakeCryptohomeClient::TpmGetPassword(
+ const StringDBusMethodCallback& callback) {
+ const char kStubTpmPassword[] = "Stub-TPM-password";
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback, DBUS_METHOD_CALL_SUCCESS,
+ std::string(kStubTpmPassword)));
+}
+
+void FakeCryptohomeClient::TpmIsOwned(
+ const BoolDBusMethodCallback& callback) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
+}
+
+bool FakeCryptohomeClient::CallTpmIsOwnedAndBlock(bool* owned) {
+ *owned = true;
+ return true;
+}
+
+void FakeCryptohomeClient::TpmIsBeingOwned(
+ const BoolDBusMethodCallback& callback) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
+}
+
+bool FakeCryptohomeClient::CallTpmIsBeingOwnedAndBlock(bool* owning) {
+ *owning = true;
+ return true;
}
void FakeCryptohomeClient::TpmCanAttemptOwnership(
const VoidDBusMethodCallback& callback) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS));
}
-bool FakeCryptohomeClient::GetSystemSalt(std::vector<uint8>* salt) {
- salt->assign(kStubSystemSalt,
- kStubSystemSalt + arraysize(kStubSystemSalt) - 1);
- return true;
+void FakeCryptohomeClient::TpmClearStoredPassword(
+ const VoidDBusMethodCallback& callback) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS));
}
-void FakeCryptohomeClient::TpmGetPassword(
- const StringDBusMethodCallback& callback) {
+bool FakeCryptohomeClient::CallTpmClearStoredPasswordAndBlock() {
+ return true;
}
-bool FakeCryptohomeClient::InstallAttributesFinalize(bool* successful) {
- return false;
+void FakeCryptohomeClient::Pkcs11IsTpmTokenReady(
+ const BoolDBusMethodCallback& callback) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
}
-void FakeCryptohomeClient::SetAsyncCallStatusHandlers(
- const AsyncCallStatusHandler& handler,
- const AsyncCallStatusWithDataHandler& data_handler) {
- handler_ = handler;
- data_handler_ = data_handler;
+void FakeCryptohomeClient::Pkcs11GetTpmTokenInfo(
+ const Pkcs11GetTpmTokenInfoCallback& callback) {
+ const char kStubUserPin[] = "012345";
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback,
+ DBUS_METHOD_CALL_SUCCESS,
+ std::string(crypto::kTestTPMTokenName),
+ std::string(kStubUserPin)));
}
-bool FakeCryptohomeClient::CallTpmIsEnabledAndBlock(bool* enabled) {
- return false;
+bool FakeCryptohomeClient::InstallAttributesGet(const std::string& name,
+ std::vector<uint8>* value,
+ bool* successful) {
+ if (install_attrs_.find(name) != install_attrs_.end()) {
+ *value = install_attrs_[name];
+ *successful = true;
+ } else {
+ value->clear();
+ *successful = false;
+ }
+ return true;
}
bool FakeCryptohomeClient::InstallAttributesSet(
const std::string& name,
const std::vector<uint8>& value,
bool* successful) {
- return false;
-}
-
-bool FakeCryptohomeClient::InstallAttributesIsFirstInstall(
- bool* is_first_install) {
- return false;
+ install_attrs_[name] = value;
+ *successful = true;
+ return true;
}
-void FakeCryptohomeClient::TpmAttestationGetCertificate(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const DataMethodCallback& callback) {
+bool FakeCryptohomeClient::InstallAttributesFinalize(bool* successful) {
+ locked_ = true;
+ *successful = true;
+ return true;
}
void FakeCryptohomeClient::InstallAttributesIsReady(
const BoolDBusMethodCallback& callback) {
- base::MessageLoop::current()->PostTask(FROM_HERE,
- base::Bind(callback,
- DBUS_METHOD_CALL_SUCCESS, true));
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
}
-void FakeCryptohomeClient::TpmAttestationGetPublicKey(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const DataMethodCallback& callback) {
+bool FakeCryptohomeClient::InstallAttributesIsInvalid(bool* is_invalid) {
+ *is_invalid = false;
+ return true;
}
-void FakeCryptohomeClient::TpmAttestationSignSimpleChallenge(
- attestation::AttestationKeyType key_type,
- const std::string& key_name,
- const std::string& challenge,
- const AsyncMethodCallback& callback) {
+bool FakeCryptohomeClient::InstallAttributesIsFirstInstall(
+ bool* is_first_install) {
+ *is_first_install = !locked_;
+ return true;
}
-void FakeCryptohomeClient::Pkcs11GetTpmTokenInfo(
- const Pkcs11GetTpmTokenInfoCallback& callback) {
+void FakeCryptohomeClient::TpmAttestationIsPrepared(
+ const BoolDBusMethodCallback& callback) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
}
-void FakeCryptohomeClient::TpmIsOwned(const BoolDBusMethodCallback& callback) {
+void FakeCryptohomeClient::TpmAttestationIsEnrolled(
+ const BoolDBusMethodCallback& callback) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
}
-void FakeCryptohomeClient::TpmAttestationIsPrepared(
- const BoolDBusMethodCallback& callback) {
+void FakeCryptohomeClient::AsyncTpmAttestationCreateEnrollRequest(
+ const AsyncMethodCallback& callback) {
+ ReturnAsyncMethodResult(callback, true);
}
-void FakeCryptohomeClient::TpmIsReady(const BoolDBusMethodCallback& callback) {
+void FakeCryptohomeClient::AsyncTpmAttestationEnroll(
+ const std::string& pca_response,
+ const AsyncMethodCallback& callback) {
+ ReturnAsyncMethodResult(callback, false);
}
-void FakeCryptohomeClient::AsyncTpmAttestationCreateEnrollRequest(
+void FakeCryptohomeClient::AsyncTpmAttestationCreateCertRequest(
+ attestation::AttestationCertificateProfile certificate_profile,
+ const std::string& user_email,
+ const std::string& request_origin,
const AsyncMethodCallback& callback) {
+ ReturnAsyncMethodResult(callback, true);
}
-void FakeCryptohomeClient::ResetAsyncCallStatusHandlers() {
- handler_.Reset();
- data_handler_.Reset();
+void FakeCryptohomeClient::AsyncTpmAttestationFinishCertRequest(
+ const std::string& pca_response,
+ attestation::AttestationKeyType key_type,
+ const std::string& key_name,
+ const AsyncMethodCallback& callback) {
+ ReturnAsyncMethodResult(callback, true);
}
void FakeCryptohomeClient::TpmAttestationDoesKeyExist(
attestation::AttestationKeyType key_type,
const std::string& key_name,
const BoolDBusMethodCallback& callback) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false));
}
-bool FakeCryptohomeClient::CallTpmIsOwnedAndBlock(bool* owned) {
- return false;
-}
-
-void FakeCryptohomeClient::AsyncRemove(const std::string& username,
- const AsyncMethodCallback& callback) {
-}
-
-void FakeCryptohomeClient::TpmAttestationSetKeyPayload(
+void FakeCryptohomeClient::TpmAttestationGetCertificate(
attestation::AttestationKeyType key_type,
const std::string& key_name,
- const std::string& payload,
- const BoolDBusMethodCallback& callback) {
+ const DataMethodCallback& callback) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string()));
}
-void FakeCryptohomeClient::GetSanitizedUsername(
- const std::string& username,
- const StringDBusMethodCallback& callback) {
- DCHECK(!callback.is_null());
-
+void FakeCryptohomeClient::TpmAttestationGetPublicKey(
+ attestation::AttestationKeyType key_type,
+ const std::string& key_name,
+ const DataMethodCallback& callback) {
base::MessageLoop::current()->PostTask(
FROM_HERE,
- base::Bind(callback,
- chromeos::DBUS_METHOD_CALL_SUCCESS,
- username));
- if (!data_handler_.is_null())
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(data_handler_,
- 1, // async_id
- true, // return_status
- username));
+ base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string()));
}
-std::string FakeCryptohomeClient::BlockingGetSanitizedUsername(
- const std::string& username) {
- return username;
+void FakeCryptohomeClient::TpmAttestationRegisterKey(
+ attestation::AttestationKeyType key_type,
+ const std::string& key_name,
+ const AsyncMethodCallback& callback) {
+ ReturnAsyncMethodResult(callback, true);
}
void FakeCryptohomeClient::TpmAttestationSignEnterpriseChallenge(
@@ -281,27 +324,66 @@ void FakeCryptohomeClient::TpmAttestationSignEnterpriseChallenge(
attestation::AttestationChallengeOptions options,
const std::string& challenge,
const AsyncMethodCallback& callback) {
+ ReturnAsyncMethodResult(callback, true);
}
-void FakeCryptohomeClient::TpmAttestationIsEnrolled(
- const BoolDBusMethodCallback& callback) {
+void FakeCryptohomeClient::TpmAttestationSignSimpleChallenge(
+ attestation::AttestationKeyType key_type,
+ const std::string& key_name,
+ const std::string& challenge,
+ const AsyncMethodCallback& callback) {
+ ReturnAsyncMethodResult(callback, true);
}
-void FakeCryptohomeClient::TpmAttestationRegisterKey(
+void FakeCryptohomeClient::TpmAttestationGetKeyPayload(
attestation::AttestationKeyType key_type,
const std::string& key_name,
- const AsyncMethodCallback& callback) {
+ const DataMethodCallback& callback) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string()));
}
-bool FakeCryptohomeClient::CallTpmClearStoredPasswordAndBlock() {
- return false;
+void FakeCryptohomeClient::TpmAttestationSetKeyPayload(
+ attestation::AttestationKeyType key_type,
+ const std::string& key_name,
+ const std::string& payload,
+ const BoolDBusMethodCallback& callback) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false));
}
-void FakeCryptohomeClient::AsyncTpmAttestationCreateCertRequest(
- attestation::AttestationCertificateProfile certificate_profile,
- const std::string& user_email,
- const std::string& request_origin,
- const AsyncMethodCallback& callback) {
+void FakeCryptohomeClient::ReturnAsyncMethodResult(
+ const AsyncMethodCallback& callback,
+ bool returns_data) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&FakeCryptohomeClient::ReturnAsyncMethodResultInternal,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback,
+ returns_data));
+}
+
+void FakeCryptohomeClient::ReturnAsyncMethodResultInternal(
+ const AsyncMethodCallback& callback,
+ bool returns_data) {
+ callback.Run(async_call_id_);
+ if (!returns_data && !async_call_status_handler_.is_null()) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(async_call_status_handler_,
+ async_call_id_,
+ true,
+ cryptohome::MOUNT_ERROR_NONE));
+ } else if (returns_data && !async_call_status_data_handler_.is_null()) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(async_call_status_data_handler_,
+ async_call_id_,
+ true,
+ std::string()));
+ }
+ ++async_call_id_;
}
-} // namespace chromeos
+} // namespace chromeos
diff --git a/chromeos/dbus/fake_cryptohome_client.h b/chromeos/dbus/fake_cryptohome_client.h
index 74d9e81..26e2cc8 100644
--- a/chromeos/dbus/fake_cryptohome_client.h
+++ b/chromeos/dbus/fake_cryptohome_client.h
@@ -1,24 +1,23 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 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 CHROMEOS_DBUS_FAKE_CRYPTOHOME_CLIENT_H_
#define CHROMEOS_DBUS_FAKE_CRYPTOHOME_CLIENT_H_
-#include <string>
+#include <map>
+#include "base/basictypes.h"
+#include "base/memory/weak_ptr.h"
#include "chromeos/dbus/cryptohome_client.h"
namespace chromeos {
-// A fake implementation of CryptohomeClient. This only calls callbacks given
-// as parameters.
-class FakeCryptohomeClient : public CryptohomeClient {
+class CHROMEOS_EXPORT FakeCryptohomeClient : public CryptohomeClient {
public:
FakeCryptohomeClient();
virtual ~FakeCryptohomeClient();
- // CryptohomeClient overrides
virtual void Init(dbus::Bus* bus) OVERRIDE;
virtual void SetAsyncCallStatusHandlers(
const AsyncCallStatusHandler& handler,
@@ -83,9 +82,9 @@ class FakeCryptohomeClient : public CryptohomeClient {
virtual bool InstallAttributesIsInvalid(bool* is_invalid) OVERRIDE;
virtual bool InstallAttributesIsFirstInstall(bool* is_first_install) OVERRIDE;
virtual void TpmAttestationIsPrepared(
- const BoolDBusMethodCallback& callback) OVERRIDE;
+ const BoolDBusMethodCallback& callback) OVERRIDE;
virtual void TpmAttestationIsEnrolled(
- const BoolDBusMethodCallback& callback) OVERRIDE;
+ const BoolDBusMethodCallback& callback) OVERRIDE;
virtual void AsyncTpmAttestationCreateEnrollRequest(
const AsyncMethodCallback& callback) OVERRIDE;
virtual void AsyncTpmAttestationEnroll(
@@ -140,18 +139,32 @@ class FakeCryptohomeClient : public CryptohomeClient {
const std::string& payload,
const BoolDBusMethodCallback& callback) OVERRIDE;
- // Sets the unmount result of Unmount() call. Unmount() always sets the result
- // and pretends that the underlying method call succeeds.
+ // Sets the unmount result of Unmount() call.
void set_unmount_result(bool result) {
unmount_result_= result;
}
private:
- AsyncCallStatusHandler handler_;
- AsyncCallStatusWithDataHandler data_handler_;
+ // Posts tasks which return fake results to the UI thread.
+ void ReturnAsyncMethodResult(const AsyncMethodCallback& callback,
+ bool returns_data);
+ // This method is used to implement ReturnAsyncMethodResult.
+ void ReturnAsyncMethodResultInternal(const AsyncMethodCallback& callback,
+ bool returns_data);
+
+ int async_call_id_;
+ AsyncCallStatusHandler async_call_status_handler_;
+ AsyncCallStatusWithDataHandler async_call_status_data_handler_;
+ int tpm_is_ready_counter_;
bool unmount_result_;
+ // A stub store for InstallAttributes, mapping an attribute name to the
+ // associated data blob. Used to implement InstallAttributesSet and -Get.
+ std::map<std::string, std::vector<uint8> > install_attrs_;
+ bool locked_;
+ base::WeakPtrFactory<FakeCryptohomeClient> weak_ptr_factory_;
+
DISALLOW_COPY_AND_ASSIGN(FakeCryptohomeClient);
};
diff --git a/chromeos/dbus/fake_gsm_sms_client.h b/chromeos/dbus/fake_gsm_sms_client.h
index 321c9f6..2e26dd1 100644
--- a/chromeos/dbus/fake_gsm_sms_client.h
+++ b/chromeos/dbus/fake_gsm_sms_client.h
@@ -15,7 +15,7 @@
namespace chromeos {
// A fake implementation of GsmSMSClient used for tests.
-class FakeGsmSMSClient : public GsmSMSClient {
+class CHROMEOS_EXPORT FakeGsmSMSClient : public GsmSMSClient {
public:
FakeGsmSMSClient();
virtual ~FakeGsmSMSClient();
diff --git a/chromeos/dbus/fake_image_burner_client.h b/chromeos/dbus/fake_image_burner_client.h
index b730ad2..bed5228 100644
--- a/chromeos/dbus/fake_image_burner_client.h
+++ b/chromeos/dbus/fake_image_burner_client.h
@@ -12,7 +12,7 @@
namespace chromeos {
// A fake implemetation of ImageBurnerClient. This class does nothing.
-class FakeImageBurnerClient : public ImageBurnerClient {
+class CHROMEOS_EXPORT FakeImageBurnerClient : public ImageBurnerClient {
public:
FakeImageBurnerClient();
virtual ~FakeImageBurnerClient();
diff --git a/chromeos/dbus/fake_system_clock_client.h b/chromeos/dbus/fake_system_clock_client.h
index 31a3ebc..18c8b2d 100644
--- a/chromeos/dbus/fake_system_clock_client.h
+++ b/chromeos/dbus/fake_system_clock_client.h
@@ -10,7 +10,7 @@
namespace chromeos {
// A fake implementation of SystemClockClient. This class does nothing.
-class FakeSystemClockClient : public SystemClockClient {
+class CHROMEOS_EXPORT FakeSystemClockClient : public SystemClockClient {
public:
FakeSystemClockClient();
virtual ~FakeSystemClockClient();