Index: crypto/nss_util.cc |
diff --git a/crypto/nss_util.cc b/crypto/nss_util.cc |
index 7a080135c0c8950c15fbfd09f0c0e1e63aa553dd..a0298f78f6c4357298ac0355542446e51e7b9b70 100644 |
--- a/crypto/nss_util.cc |
+++ b/crypto/nss_util.cc |
@@ -31,7 +31,6 @@ |
#include "base/environment.h" |
#include "base/file_util.h" |
#include "base/files/file_path.h" |
-#include "base/files/scoped_temp_dir.h" |
#include "base/lazy_instance.h" |
#include "base/logging.h" |
#include "base/memory/scoped_ptr.h" |
@@ -470,6 +469,14 @@ class NSSInitSingleton { |
return chromeos_user_map_[username_hash]->GetPrivateSlot(callback); |
} |
+ |
+ void CloseTestChromeOSUser(const std::string& username_hash) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ ChromeOSUserMap::iterator i = chromeos_user_map_.find(username_hash); |
+ DCHECK(i != chromeos_user_map_.end()); |
+ delete i->second; |
+ chromeos_user_map_.erase(i); |
+ } |
#endif // defined(OS_CHROMEOS) |
@@ -979,6 +986,27 @@ bool InitializeTPMToken(int token_slot_id) { |
return g_nss_singleton.Get().InitializeTPMToken(token_slot_id); |
} |
+ScopedTestNSSChromeOSUser::ScopedTestNSSChromeOSUser( |
+ const std::string& username_hash) |
+ : username_hash_(username_hash), constructed_successfully_(false) { |
+ if (!temp_dir_.CreateUniqueTempDir()) |
+ return; |
+ constructed_successfully_ = |
+ InitializeNSSForChromeOSUser(username_hash, |
+ username_hash, |
+ false /* is_primary_user */, |
+ temp_dir_.path()); |
+} |
+ |
+ScopedTestNSSChromeOSUser::~ScopedTestNSSChromeOSUser() { |
+ if (constructed_successfully_) |
+ g_nss_singleton.Get().CloseTestChromeOSUser(username_hash_); |
+} |
+ |
+void ScopedTestNSSChromeOSUser::FinishInit() { |
+ InitializePrivateSoftwareSlotForChromeOSUser(username_hash_); |
+} |
+ |
bool InitializeNSSForChromeOSUser( |
const std::string& email, |
const std::string& username_hash, |