diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-31 04:13:38 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-31 04:13:38 +0000 |
commit | a737276ee3ac1896f2c4bb6694eefb97a22b81b5 (patch) | |
tree | a37e003fb115348c4deb8a8669e309a236d75b54 /chromeos | |
parent | 85bbba551aef9be940a992c43b933fe02035b5bd (diff) | |
download | chromium_src-a737276ee3ac1896f2c4bb6694eefb97a22b81b5.zip chromium_src-a737276ee3ac1896f2c4bb6694eefb97a22b81b5.tar.gz chromium_src-a737276ee3ac1896f2c4bb6694eefb97a22b81b5.tar.bz2 |
Convert chromeos::CryptohomeClient::TpmCanAttemptOwnership to asynchronous
BUG=126674
TEST=git try -b linux_chromeos
Review URL: https://chromiumcodereview.appspot.com/10830033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149136 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r-- | chromeos/dbus/cryptohome_client.cc | 31 | ||||
-rw-r--r-- | chromeos/dbus/cryptohome_client.h | 9 | ||||
-rw-r--r-- | chromeos/dbus/mock_cryptohome_client.h | 3 |
3 files changed, 34 insertions, 9 deletions
diff --git a/chromeos/dbus/cryptohome_client.cc b/chromeos/dbus/cryptohome_client.cc index 55c2854..8da8a8b 100644 --- a/chromeos/dbus/cryptohome_client.cc +++ b/chromeos/dbus/cryptohome_client.cc @@ -195,12 +195,11 @@ class CryptohomeClientImpl : public CryptohomeClient { } // CryptohomeClient override. - virtual bool TpmCanAttemptOwnership() OVERRIDE { + virtual void TpmCanAttemptOwnership( + const VoidMethodCallback& callback) OVERRIDE { INITIALIZE_METHOD_CALL(method_call, cryptohome::kCryptohomeTpmCanAttemptOwnership); - scoped_ptr<dbus::Response> response( - blocking_method_caller_.CallMethodAndBlock(&method_call)); - return response.get() != NULL; + CallVoidMethod(&method_call, callback); } // CryptohomeClient override. @@ -311,6 +310,24 @@ class CryptohomeClientImpl : public CryptohomeClient { callback.Run(async_id); } + // Calls a method without result values. + void CallVoidMethod(dbus::MethodCall* method_call, + const VoidMethodCallback& callback) { + proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, + base::Bind(&CryptohomeClientImpl::OnVoidMethod, + weak_ptr_factory_.GetWeakPtr(), + callback)); + } + + void OnVoidMethod(const VoidMethodCallback& callback, + dbus::Response* response) { + if (!response) { + callback.Run(DBUS_METHOD_CALL_FAILURE); + return; + } + callback.Run(DBUS_METHOD_CALL_SUCCESS); + } + // Calls a method with a bool value reult and block. bool CallBoolMethodAndBlock(dbus::MethodCall* method_call, bool* result) { @@ -529,7 +546,11 @@ class CryptohomeClientStubImpl : public CryptohomeClient { } // CryptohomeClient override. - virtual bool TpmCanAttemptOwnership() OVERRIDE { return true; } + virtual void TpmCanAttemptOwnership( + const VoidMethodCallback& callback) OVERRIDE { + MessageLoop::current()->PostTask( + FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS)); + } // CryptohomeClient override. virtual bool TpmClearStoredPassword() OVERRIDE { return true; } diff --git a/chromeos/dbus/cryptohome_client.h b/chromeos/dbus/cryptohome_client.h index 530f57f..f4a86837 100644 --- a/chromeos/dbus/cryptohome_client.h +++ b/chromeos/dbus/cryptohome_client.h @@ -30,6 +30,9 @@ class CHROMEOS_EXPORT CryptohomeClient { > AsyncCallStatusHandler; // A callback to handle responses of AsyncXXX methods. typedef base::Callback<void(int async_id)> AsyncMethodCallback; + // A callback to handle responses of methods without result values. + typedef base::Callback<void( + DBusMethodCallStatus call_status)> VoidMethodCallback; // A callback to handle responses of methods returning a bool value. typedef base::Callback<void(DBusMethodCallStatus call_status, bool result)> BoolMethodCallback; @@ -121,9 +124,9 @@ class CHROMEOS_EXPORT CryptohomeClient { // This method blocks until the call returns. virtual bool TpmIsBeingOwned(bool* owning) = 0; - // Calls TpmCanAttemptOwnership method and returns true when the call - // succeeds. This method blocks until the call returns. - virtual bool TpmCanAttemptOwnership() = 0; + // Calls TpmCanAttemptOwnership method. + // This method tells the service that it is OK to attempt ownership. + virtual void TpmCanAttemptOwnership(const VoidMethodCallback& callback) = 0; // Calls TpmClearStoredPassword method and returns true when the call // succeeds. This method blocks until the call returns. diff --git a/chromeos/dbus/mock_cryptohome_client.h b/chromeos/dbus/mock_cryptohome_client.h index 29f69d1..e7fb3c3 100644 --- a/chromeos/dbus/mock_cryptohome_client.h +++ b/chromeos/dbus/mock_cryptohome_client.h @@ -46,7 +46,8 @@ class MockCryptohomeClient : public CryptohomeClient { MOCK_METHOD1(TpmGetPassword, void(const StringMethodCallback& callback)); MOCK_METHOD1(TpmIsOwned, bool(bool* owned)); MOCK_METHOD1(TpmIsBeingOwned, bool(bool* owning)); - MOCK_METHOD0(TpmCanAttemptOwnership, bool()); + MOCK_METHOD1(TpmCanAttemptOwnership, + void(const VoidMethodCallback& callback)); MOCK_METHOD0(TpmClearStoredPassword, bool()); MOCK_METHOD1(Pkcs11IsTpmTokenReady, void(const BoolMethodCallback& callback)); MOCK_METHOD1(Pkcs11GetTpmTokenInfo, |