diff options
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/nss_util.cc | 23 | ||||
-rw-r--r-- | crypto/nss_util.h | 13 |
2 files changed, 22 insertions, 14 deletions
diff --git a/crypto/nss_util.cc b/crypto/nss_util.cc index c60b7ea..4a48db1 100644 --- a/crypto/nss_util.cc +++ b/crypto/nss_util.cc @@ -30,6 +30,7 @@ #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/native_library.h" +#include "base/scoped_temp_dir.h" #include "base/stringprintf.h" #include "base/threading/thread_restrictions.h" #include "build/build_config.h" @@ -220,6 +221,11 @@ class NSPRInitSingleton { base::LazyInstance<NSPRInitSingleton>::Leaky g_nspr_singleton = LAZY_INSTANCE_INITIALIZER; +// This is a LazyInstance so that it will be deleted automatically when the +// unittest exits. NSSInitSingleton is a LeakySingleton, so it would not be +// deleted if it were a regular member. +base::LazyInstance<ScopedTempDir> g_test_nss_db_dir = LAZY_INSTANCE_INITIALIZER; + class NSSInitSingleton { public: #if defined(OS_CHROMEOS) @@ -343,8 +349,12 @@ class NSSInitSingleton { #endif // defined(OS_CHROMEOS) - bool OpenTestNSSDB(const FilePath& path, const char* description) { - test_slot_ = OpenUserDB(path, description); + bool OpenTestNSSDB() { + if (test_slot_) + return true; + if (!g_test_nss_db_dir.Get().CreateUniqueTempDir()) + return false; + test_slot_ = OpenUserDB(g_test_nss_db_dir.Get().path(), "Test DB"); return !!test_slot_; } @@ -355,6 +365,7 @@ class NSSInitSingleton { PLOG(ERROR) << "SECMOD_CloseUserDB failed: " << PORT_GetError(); PK11_FreeSlot(test_slot_); test_slot_ = NULL; + ignore_result(g_test_nss_db_dir.Get().Delete()); } } @@ -698,12 +709,8 @@ bool CheckNSSVersion(const char* version) { } #if defined(USE_NSS) -bool OpenTestNSSDB(const FilePath& path, const char* description) { - return g_nss_singleton.Get().OpenTestNSSDB(path, description); -} - -void CloseTestNSSDB() { - g_nss_singleton.Get().CloseTestNSSDB(); +bool OpenTestNSSDB() { + return g_nss_singleton.Get().OpenTestNSSDB(); } base::Lock* GetNSSWriteLock() { diff --git a/crypto/nss_util.h b/crypto/nss_util.h index 746691d..9cfdf0b 100644 --- a/crypto/nss_util.h +++ b/crypto/nss_util.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -154,11 +154,12 @@ CRYPTO_EXPORT base::Time PRTimeToBaseTime(int64 prtime); CRYPTO_EXPORT int64 BaseTimeToPRTime(base::Time time); #if defined(USE_NSS) -// Exposed for unittests only. |path| should be an existing directory under -// which the DB files will be placed. |description| is a user-visible name for -// the DB, as a utf8 string, which will be truncated at 32 bytes. -CRYPTO_EXPORT bool OpenTestNSSDB(const FilePath& path, const char* description); -CRYPTO_EXPORT void CloseTestNSSDB(); +// Exposed for unittests only. +// TODO(mattm): when https://bugzilla.mozilla.org/show_bug.cgi?id=588269 is +// fixed, switch back to using a separate userdb for each test. (Maybe refactor +// to provide a ScopedTestNSSDB instead of open/close methods.) +CRYPTO_EXPORT bool OpenTestNSSDB(); +// NOTE: due to NSS bug 588269, mentioned above, there is no CloseTestNSSDB. // NSS has a bug which can cause a deadlock or stall in some cases when writing // to the certDB and keyDB. It also has a bug which causes concurrent key pair |