summaryrefslogtreecommitdiffstats
path: root/chromeos/cryptohome
diff options
context:
space:
mode:
authorhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-28 06:28:08 +0000
committerhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-28 06:28:08 +0000
commitdcbb97305eea45cef1487b15f76cef60051c5964 (patch)
tree34ac3822d2caf7f4639856533a3f3ea65a5ca293 /chromeos/cryptohome
parent621ade066da2fefb69ef9aa7d29ea513a1f0564b (diff)
downloadchromium_src-dcbb97305eea45cef1487b15f76cef60051c5964.zip
chromium_src-dcbb97305eea45cef1487b15f76cef60051c5964.tar.gz
chromium_src-dcbb97305eea45cef1487b15f76cef60051c5964.tar.bz2
chromeos: Remove SystemSaltGetter::GetSystemSaltSync
Make CryptohomeClient::GetSystemSalt asynchronous BUG=141009 Review URL: https://codereview.chromium.org/43503003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231286 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/cryptohome')
-rw-r--r--chromeos/cryptohome/system_salt_getter.cc46
-rw-r--r--chromeos/cryptohome/system_salt_getter.h19
-rw-r--r--chromeos/cryptohome/system_salt_getter_unittest.cc1
3 files changed, 35 insertions, 31 deletions
diff --git a/chromeos/cryptohome/system_salt_getter.cc b/chromeos/cryptohome/system_salt_getter.cc
index 1fa25a3..2a26db7 100644
--- a/chromeos/cryptohome/system_salt_getter.cc
+++ b/chromeos/cryptohome/system_salt_getter.cc
@@ -27,35 +27,43 @@ SystemSaltGetter::~SystemSaltGetter() {
void SystemSaltGetter::GetSystemSalt(
const GetSystemSaltCallback& callback) {
+ if (!system_salt_.empty()) {
+ base::MessageLoopProxy::current()->PostTask(
+ FROM_HERE, base::Bind(callback, system_salt_));
+ return;
+ }
+
DBusThreadManager::Get()->GetCryptohomeClient()->WaitForServiceToBeAvailable(
- base::Bind(&SystemSaltGetter::GetSystemSaltInternal,
+ base::Bind(&SystemSaltGetter::DidWaitForServiceToBeAvailable,
weak_ptr_factory_.GetWeakPtr(),
callback));
}
-std::string SystemSaltGetter::GetSystemSaltSync() {
- LoadSystemSalt(); // no-op if it's already loaded.
- return system_salt_;
-}
-
-void SystemSaltGetter::GetSystemSaltInternal(
+void SystemSaltGetter::DidWaitForServiceToBeAvailable(
const GetSystemSaltCallback& callback,
bool service_is_available) {
- LOG_IF(ERROR, !service_is_available) << "WaitForServiceToBeAvailable failed.";
- // TODO(hashimoto): Stop using GetSystemSaltSync(). crbug.com/141009
- callback.Run(GetSystemSaltSync());
+ if (!service_is_available) {
+ LOG(ERROR) << "WaitForServiceToBeAvailable failed.";
+ callback.Run(std::string());
+ return;
+ }
+ DBusThreadManager::Get()->GetCryptohomeClient()->GetSystemSalt(
+ base::Bind(&SystemSaltGetter::DidGetSystemSalt,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback));
}
-void SystemSaltGetter::LoadSystemSalt() {
- if (!system_salt_.empty())
- return;
- std::vector<uint8> salt;
- DBusThreadManager::Get()->GetCryptohomeClient()->GetSystemSalt(&salt);
- if (salt.empty() || salt.size() % 2 != 0U) {
+void SystemSaltGetter::DidGetSystemSalt(const GetSystemSaltCallback& callback,
+ DBusMethodCallStatus call_status,
+ const std::vector<uint8>& system_salt) {
+ if (call_status == DBUS_METHOD_CALL_SUCCESS &&
+ !system_salt.empty() &&
+ system_salt.size() % 2 == 0U)
+ system_salt_ = ConvertRawSaltToHexString(system_salt);
+ else
LOG(WARNING) << "System salt not available";
- return;
- }
- system_salt_ = ConvertRawSaltToHexString(salt);
+
+ callback.Run(system_salt_);
}
// static
diff --git a/chromeos/cryptohome/system_salt_getter.h b/chromeos/cryptohome/system_salt_getter.h
index 1e4cf81..ee33133 100644
--- a/chromeos/cryptohome/system_salt_getter.h
+++ b/chromeos/cryptohome/system_salt_getter.h
@@ -12,6 +12,7 @@
#include "base/callback_forward.h"
#include "base/memory/weak_ptr.h"
#include "chromeos/chromeos_export.h"
+#include "chromeos/dbus/dbus_method_call_status.h"
namespace chromeos {
@@ -31,26 +32,20 @@ class CHROMEOS_EXPORT SystemSaltGetter {
static std::string ConvertRawSaltToHexString(const std::vector<uint8>& salt);
// Returns system hash in hex encoded ascii format. Note: this may return
- // an empty string (e.g. if cryptohome is not running). It is up to the
- // calling function to try again after a delay if desired.
+ // an empty string (e.g. errors in D-Bus layer)
void GetSystemSalt(const GetSystemSaltCallback& callback);
- // Synchronous version of GetSystemSalt().
- // Blocks the UI thread until the Cryptohome service returns the result.
- // DEPRECATED: DO NOT USE.
- std::string GetSystemSaltSync();
-
protected:
SystemSaltGetter();
~SystemSaltGetter();
private:
// Used to implement GetSystemSalt().
- void GetSystemSaltInternal(const GetSystemSaltCallback& callback,
- bool service_is_available);
-
- // Loads the system salt from cryptohome and caches it.
- void LoadSystemSalt();
+ void DidWaitForServiceToBeAvailable(const GetSystemSaltCallback& callback,
+ bool service_is_available);
+ void DidGetSystemSalt(const GetSystemSaltCallback& callback,
+ DBusMethodCallStatus call_status,
+ const std::vector<uint8>& system_salt);
std::string system_salt_;
diff --git a/chromeos/cryptohome/system_salt_getter_unittest.cc b/chromeos/cryptohome/system_salt_getter_unittest.cc
index 84403e4..07883a0 100644
--- a/chromeos/cryptohome/system_salt_getter_unittest.cc
+++ b/chromeos/cryptohome/system_salt_getter_unittest.cc
@@ -55,6 +55,7 @@ TEST_F(SystemSaltGetterTest, GetSystemSalt) {
// Service becomes available.
fake_cryptohome_client_->SetServiceIsAvailable(true);
+ base::RunLoop().RunUntilIdle();
const std::string expected_system_salt =
SystemSaltGetter::ConvertRawSaltToHexString(
FakeCryptohomeClient::GetStubSystemSalt());