summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-10 05:25:49 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-10 05:25:49 +0000
commit7e4909e0d4bda996db26ff396f6766d473ba8a36 (patch)
treec2312748a961c8611170b74cf833750d89e80272 /chromeos
parent1b943d0993290c33e61c03f6256ab960892593a9 (diff)
downloadchromium_src-7e4909e0d4bda996db26ff396f6766d473ba8a36.zip
chromium_src-7e4909e0d4bda996db26ff396f6766d473ba8a36.tar.gz
chromium_src-7e4909e0d4bda996db26ff396f6766d473ba8a36.tar.bz2
cryptohome: Remove CryptohomeLibraryStubImpl
This production/non-production switching layer is unnecessary, as CryptohomeClient provides such a layer already. BUG=305441 TEST=none R=hashimoto@chromium.org, pneubeck@chromium.org Review URL: https://codereview.chromium.org/26652002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227880 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/cryptohome/cryptohome_library.cc120
-rw-r--r--chromeos/cryptohome/cryptohome_library.h27
2 files changed, 42 insertions, 105 deletions
diff --git a/chromeos/cryptohome/cryptohome_library.cc b/chromeos/cryptohome/cryptohome_library.cc
index e07dd60..a3d3dd2 100644
--- a/chromeos/cryptohome/cryptohome_library.cc
+++ b/chromeos/cryptohome/cryptohome_library.cc
@@ -4,105 +4,60 @@
#include "chromeos/cryptohome/cryptohome_library.h"
-#include <map>
-
#include "base/bind.h"
#include "base/location.h"
-#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
-#include "base/sys_info.h"
#include "chromeos/dbus/cryptohome_client.h"
-#include "chromeos/dbus/dbus_method_call_status.h"
#include "chromeos/dbus/dbus_thread_manager.h"
namespace chromeos {
-
namespace {
-const char kStubSystemSalt[] = "stub_system_salt";
+CryptohomeLibrary* g_cryptohome_library = NULL;
} // namespace
-// This class handles the interaction with the ChromeOS cryptohome library APIs.
-class CryptohomeLibraryImpl : public CryptohomeLibrary {
- public:
- CryptohomeLibraryImpl() {
- }
-
- virtual ~CryptohomeLibraryImpl() {
- }
-
- virtual void GetSystemSalt(const GetSystemSaltCallback& callback) OVERRIDE {
- // TODO(hashimoto): Stop using GetSystemSaltSynt(). crbug.com/141009
- base::MessageLoopProxy::current()->PostTask(
- FROM_HERE, base::Bind(callback, GetSystemSaltSync()));
- }
-
- virtual std::string GetSystemSaltSync() OVERRIDE {
- LoadSystemSalt(); // no-op if it's already loaded.
- return system_salt_;
- }
-
- virtual std::string GetCachedSystemSalt() OVERRIDE {
- return system_salt_;
- }
-
- private:
- void LoadSystemSalt() {
- if (!system_salt_.empty())
- return;
- std::vector<uint8> salt;
- DBusThreadManager::Get()->GetCryptohomeClient()->GetSystemSalt(&salt);
- if (salt.empty() || salt.size() % 2 != 0U) {
- LOG(WARNING) << "System salt not available";
- return;
- }
- system_salt_ = StringToLowerASCII(base::HexEncode(
- reinterpret_cast<const void*>(salt.data()), salt.size()));
- }
-
- std::string system_salt_;
+CryptohomeLibrary::CryptohomeLibrary() {
+}
- DISALLOW_COPY_AND_ASSIGN(CryptohomeLibraryImpl);
-};
+CryptohomeLibrary::~CryptohomeLibrary() {
+}
-class CryptohomeLibraryStubImpl : public CryptohomeLibrary {
- public:
- CryptohomeLibraryStubImpl() {}
- virtual ~CryptohomeLibraryStubImpl() {}
+void CryptohomeLibrary::GetSystemSalt(
+ const GetSystemSaltCallback& callback) {
+ // TODO(hashimoto): Stop using GetSystemSaltSynt(). crbug.com/141009
+ base::MessageLoopProxy::current()->PostTask(
+ FROM_HERE, base::Bind(callback, GetSystemSaltSync()));
+}
- virtual void GetSystemSalt(const GetSystemSaltCallback& callback) OVERRIDE {
- base::MessageLoopProxy::current()->PostTask(
- FROM_HERE, base::Bind(callback, kStubSystemSalt));
- }
+std::string CryptohomeLibrary::GetSystemSaltSync() {
+ LoadSystemSalt(); // no-op if it's already loaded.
+ return system_salt_;
+}
- virtual std::string GetSystemSaltSync() OVERRIDE {
- return kStubSystemSalt;
- }
+std::string CryptohomeLibrary::GetCachedSystemSalt() {
+ return system_salt_;
+}
- virtual std::string GetCachedSystemSalt() OVERRIDE {
- return kStubSystemSalt;
+void CryptohomeLibrary::LoadSystemSalt() {
+ if (!system_salt_.empty())
+ return;
+ std::vector<uint8> salt;
+ DBusThreadManager::Get()->GetCryptohomeClient()->GetSystemSalt(&salt);
+ if (salt.empty() || salt.size() % 2 != 0U) {
+ LOG(WARNING) << "System salt not available";
+ return;
}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(CryptohomeLibraryStubImpl);
-};
-
-CryptohomeLibrary::CryptohomeLibrary() {}
-CryptohomeLibrary::~CryptohomeLibrary() {}
-
-static CryptohomeLibrary* g_cryptohome_library = NULL;
-static CryptohomeLibrary* g_test_cryptohome_library = NULL;
+ system_salt_ = StringToLowerASCII(base::HexEncode(
+ reinterpret_cast<const void*>(salt.data()), salt.size()));
+}
// static
void CryptohomeLibrary::Initialize() {
CHECK(!g_cryptohome_library);
- if (base::SysInfo::IsRunningOnChromeOS())
- g_cryptohome_library = new CryptohomeLibraryImpl();
- else
- g_cryptohome_library = new CryptohomeLibraryStubImpl();
+ g_cryptohome_library = new CryptohomeLibrary();
}
// static
@@ -119,22 +74,9 @@ void CryptohomeLibrary::Shutdown() {
// static
CryptohomeLibrary* CryptohomeLibrary::Get() {
- CHECK(g_cryptohome_library || g_test_cryptohome_library)
+ CHECK(g_cryptohome_library)
<< "CryptohomeLibrary::Get() called before Initialize()";
- if (g_test_cryptohome_library)
- return g_test_cryptohome_library;
return g_cryptohome_library;
}
-// static
-void CryptohomeLibrary::SetForTest(CryptohomeLibrary* impl) {
- CHECK(!g_test_cryptohome_library || !impl);
- g_test_cryptohome_library = impl;
-}
-
-// static
-CryptohomeLibrary* CryptohomeLibrary::GetTestImpl() {
- return new CryptohomeLibraryStubImpl();
-}
-
} // namespace chromeos
diff --git a/chromeos/cryptohome/cryptohome_library.h b/chromeos/cryptohome/cryptohome_library.h
index 9b33bd5..5ab5657 100644
--- a/chromeos/cryptohome/cryptohome_library.h
+++ b/chromeos/cryptohome/cryptohome_library.h
@@ -13,8 +13,8 @@
namespace chromeos {
-// This interface defines the interaction with the ChromeOS cryptohome library
-// APIs.
+// This class is used to get the system salt from cryptohome and cache it.
+// TODO(satorux): Rename this to SystemSaltGetter. crbug.com/305906
class CHROMEOS_EXPORT CryptohomeLibrary {
public:
typedef base::Callback<void(const std::string& system_salt)>
@@ -26,36 +26,31 @@ class CHROMEOS_EXPORT CryptohomeLibrary {
static void Shutdown();
static CryptohomeLibrary* Get();
- // Sets up Get() to return |impl| for testing (e.g. with a mock
- // implementation). Call SetForTest(NULL) when |impl| is deleted.
- static void SetForTest(CryptohomeLibrary* impl);
-
- // Returns a CryptohomeLibrary instance for testing. Does not set or affect
- // the global instance.
- static CryptohomeLibrary* GetTestImpl();
-
- // Public so that result of GetTestImpl can be destroyed.
- virtual ~CryptohomeLibrary();
-
// 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.
- virtual void GetSystemSalt(const GetSystemSaltCallback& callback) = 0;
+ void GetSystemSalt(const GetSystemSaltCallback& callback);
// Synchronous version of GetSystemSalt().
// Blocks the UI thread until the Cryptohome service returns the result.
// DEPRECATED: DO NOT USE.
- virtual std::string GetSystemSaltSync() = 0;
+ std::string GetSystemSaltSync();
// Returns system hash in hex encoded ascii format, cached by a prior call
// to GetSystemSalt(). Note: this may return an empty string (e.g. if
// GetSystemSalt() is not yet called).
- virtual std::string GetCachedSystemSalt() = 0;
+ std::string GetCachedSystemSalt();
protected:
CryptohomeLibrary();
+ ~CryptohomeLibrary();
private:
+ // Loads the system salt from cryptohome and caches it.
+ void LoadSystemSalt();
+
+ std::string system_salt_;
+
DISALLOW_COPY_AND_ASSIGN(CryptohomeLibrary);
};