From 0274629c9983144bc161bb88a7e9436d28301e6d Mon Sep 17 00:00:00 2001 From: "mattm@chromium.org" Date: Wed, 25 Jan 2012 04:37:51 +0000 Subject: 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 --- crypto/nss_util.cc | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'crypto/nss_util.cc') 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::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 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() { -- cgit v1.1