summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus
diff options
context:
space:
mode:
authorhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-22 07:38:05 +0000
committerhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-22 07:38:05 +0000
commitcff139a2b359e7cb5e4ee1cb5e336153f800792b (patch)
treea2a0cbdc3c401b77c79d1728798d9113a0d7c2aa /chromeos/dbus
parent5a27a550c9f6ea31618177a334136d7b361fa1eb (diff)
downloadchromium_src-cff139a2b359e7cb5e4ee1cb5e336153f800792b.zip
chromium_src-cff139a2b359e7cb5e4ee1cb5e336153f800792b.tar.gz
chromium_src-cff139a2b359e7cb5e4ee1cb5e336153f800792b.tar.bz2
chromeos: Wait for service to be available when getting system salt
Add CryptohomeClient::WaitForServiceToBeAvailable(). Use WaitForServiceToBeAvailable() from SystemSaltGetter. BUG=141009 R=satorux@chromium.org Review URL: https://codereview.chromium.org/34303002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@230067 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/dbus')
-rw-r--r--chromeos/dbus/cryptohome_client.cc6
-rw-r--r--chromeos/dbus/cryptohome_client.h7
-rw-r--r--chromeos/dbus/fake_cryptohome_client.cc23
-rw-r--r--chromeos/dbus/fake_cryptohome_client.h10
-rw-r--r--chromeos/dbus/mock_cryptohome_client.h2
5 files changed, 47 insertions, 1 deletions
diff --git a/chromeos/dbus/cryptohome_client.cc b/chromeos/dbus/cryptohome_client.cc
index 79a6561..ca2d48a 100644
--- a/chromeos/dbus/cryptohome_client.cc
+++ b/chromeos/dbus/cryptohome_client.cc
@@ -45,6 +45,12 @@ class CryptohomeClientImpl : public CryptohomeClient {
}
// CryptohomeClient override.
+ virtual void WaitForServiceToBeAvailable(
+ const WaitForServiceToBeAvailableCallback& callback) OVERRIDE {
+ proxy_->WaitForServiceToBeAvailable(callback);
+ }
+
+ // CryptohomeClient override.
virtual void IsMounted(const BoolDBusMethodCallback& callback) OVERRIDE {
dbus::MethodCall method_call(cryptohome::kCryptohomeInterface,
cryptohome::kCryptohomeIsMounted);
diff --git a/chromeos/dbus/cryptohome_client.h b/chromeos/dbus/cryptohome_client.h
index cc4b9d7..036cf64 100644
--- a/chromeos/dbus/cryptohome_client.h
+++ b/chromeos/dbus/cryptohome_client.h
@@ -35,6 +35,9 @@ class CHROMEOS_EXPORT CryptohomeClient : public DBusClient {
AsyncCallStatusWithDataHandler;
// A callback to handle responses of AsyncXXX methods.
typedef base::Callback<void(int async_id)> AsyncMethodCallback;
+ // A callback for WaitForServiceToBeAvailable().
+ typedef base::Callback<void(bool service_is_ready)>
+ WaitForServiceToBeAvailableCallback;
// A callback to handle responses of Pkcs11GetTpmTokenInfo method. The result
// of the D-Bus call is in |call_status|. On success, |label| holds the
// PKCS #11 token label. This is not useful in practice to identify a token
@@ -73,6 +76,10 @@ class CHROMEOS_EXPORT CryptohomeClient : public DBusClient {
// Resets AsyncCallStatus signal handlers.
virtual void ResetAsyncCallStatusHandlers() = 0;
+ // Runs the callback as soon as the service becomes available.
+ virtual void WaitForServiceToBeAvailable(
+ const WaitForServiceToBeAvailableCallback& callback) = 0;
+
// Calls IsMounted method and returns true when the call succeeds.
virtual void IsMounted(const BoolDBusMethodCallback& callback) = 0;
diff --git a/chromeos/dbus/fake_cryptohome_client.cc b/chromeos/dbus/fake_cryptohome_client.cc
index 7b40854..d23be71 100644
--- a/chromeos/dbus/fake_cryptohome_client.cc
+++ b/chromeos/dbus/fake_cryptohome_client.cc
@@ -13,7 +13,8 @@
namespace chromeos {
FakeCryptohomeClient::FakeCryptohomeClient()
- : async_call_id_(1),
+ : service_is_available_(true),
+ async_call_id_(1),
tpm_is_ready_counter_(0),
unmount_result_(true),
locked_(false),
@@ -36,6 +37,16 @@ void FakeCryptohomeClient::ResetAsyncCallStatusHandlers() {
async_call_status_data_handler_.Reset();
}
+void FakeCryptohomeClient::WaitForServiceToBeAvailable(
+ const WaitForServiceToBeAvailableCallback& callback) {
+ if (service_is_available_) {
+ base::MessageLoop::current()->PostTask(FROM_HERE,
+ base::Bind(callback, true));
+ } else {
+ pending_wait_for_service_to_be_available_callbacks_.push_back(callback);
+ }
+}
+
void FakeCryptohomeClient::IsMounted(
const BoolDBusMethodCallback& callback) {
base::MessageLoop::current()->PostTask(
@@ -368,6 +379,16 @@ void FakeCryptohomeClient::TpmAttestationSetKeyPayload(
FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false));
}
+void FakeCryptohomeClient::SetServiceIsAvailable(bool is_available) {
+ service_is_available_ = is_available;
+ if (is_available) {
+ std::vector<WaitForServiceToBeAvailableCallback> callbacks;
+ callbacks.swap(pending_wait_for_service_to_be_available_callbacks_);
+ for (size_t i = 0; i < callbacks.size(); ++i)
+ callbacks[i].Run(is_available);
+ }
+}
+
// static
std::vector<uint8> FakeCryptohomeClient::GetStubSystemSalt() {
const char kStubSystemSalt[] = "stub_system_salt";
diff --git a/chromeos/dbus/fake_cryptohome_client.h b/chromeos/dbus/fake_cryptohome_client.h
index 4f045ec..3c960e8 100644
--- a/chromeos/dbus/fake_cryptohome_client.h
+++ b/chromeos/dbus/fake_cryptohome_client.h
@@ -23,6 +23,8 @@ class CHROMEOS_EXPORT FakeCryptohomeClient : public CryptohomeClient {
const AsyncCallStatusHandler& handler,
const AsyncCallStatusWithDataHandler& data_handler) OVERRIDE;
virtual void ResetAsyncCallStatusHandlers() OVERRIDE;
+ virtual void WaitForServiceToBeAvailable(
+ const WaitForServiceToBeAvailableCallback& callback) OVERRIDE;
virtual void IsMounted(const BoolDBusMethodCallback& callback) OVERRIDE;
virtual bool Unmount(bool* success) OVERRIDE;
virtual void AsyncCheckKey(const std::string& username,
@@ -151,6 +153,10 @@ class CHROMEOS_EXPORT FakeCryptohomeClient : public CryptohomeClient {
const std::string& payload,
const BoolDBusMethodCallback& callback) OVERRIDE;
+ // Changes the behavior of WaitForServiceToBeAvailable(). This method runs
+ // pending callbacks if is_available is true.
+ void SetServiceIsAvailable(bool is_available);
+
// Sets the unmount result of Unmount() call.
void set_unmount_result(bool result) {
unmount_result_= result;
@@ -169,12 +175,16 @@ class CHROMEOS_EXPORT FakeCryptohomeClient : public CryptohomeClient {
void ReturnAsyncMethodResultInternal(const AsyncMethodCallback& callback,
bool returns_data);
+ bool service_is_available_;
int async_call_id_;
AsyncCallStatusHandler async_call_status_handler_;
AsyncCallStatusWithDataHandler async_call_status_data_handler_;
int tpm_is_ready_counter_;
bool unmount_result_;
+ std::vector<WaitForServiceToBeAvailableCallback>
+ pending_wait_for_service_to_be_available_callbacks_;
+
// 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_;
diff --git a/chromeos/dbus/mock_cryptohome_client.h b/chromeos/dbus/mock_cryptohome_client.h
index 8cb4c6b..cdb1ad8 100644
--- a/chromeos/dbus/mock_cryptohome_client.h
+++ b/chromeos/dbus/mock_cryptohome_client.h
@@ -22,6 +22,8 @@ class MockCryptohomeClient : public CryptohomeClient {
void(const AsyncCallStatusHandler& handler,
const AsyncCallStatusWithDataHandler& data_handler));
MOCK_METHOD0(ResetAsyncCallStatusHandlers, void());
+ MOCK_METHOD1(WaitForServiceToBeAvailable,
+ void(const WaitForServiceToBeAvailableCallback& callback));
MOCK_METHOD1(IsMounted, void(const BoolDBusMethodCallback& callback));
MOCK_METHOD1(Unmount, bool(bool* success));
MOCK_METHOD3(AsyncCheckKey,