summaryrefslogtreecommitdiffstats
path: root/crypto/nss_util.cc
diff options
context:
space:
mode:
authormattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-25 04:37:51 +0000
committermattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-25 04:37:51 +0000
commit0274629c9983144bc161bb88a7e9436d28301e6d (patch)
treeb66495bbb20df46562644fe5587254b313036c63 /crypto/nss_util.cc
parent527516c019a53b8417b3e4ba3612083efe4e29ce (diff)
downloadchromium_src-0274629c9983144bc161bb88a7e9436d28301e6d.zip
chromium_src-0274629c9983144bc161bb88a7e9436d28301e6d.tar.gz
chromium_src-0274629c9983144bc161bb88a7e9436d28301e6d.tar.bz2
CertDatabaseNSSTest: Don't delete test DB dir since we don't close the DB (broke in r108543).
Refactor test DB code so that nss_util owns the test DB dir. Keeping the test DB dir until exit prevents later tests that would use the test DB from failing. The dir will still be deleted by the LazyInstance atexit handler. BUG=108748 TEST=see bug Review URL: http://codereview.chromium.org/9255034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119003 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'crypto/nss_util.cc')
-rw-r--r--crypto/nss_util.cc23
1 files changed, 15 insertions, 8 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() {