scoped_test_nss_chromeos_user.cc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "crypto/scoped_test_nss_chromeos_user.h"
  5. #include "base/check.h"
  6. #include "crypto/nss_util.h"
  7. #include "crypto/nss_util_internal.h"
  8. namespace crypto {
  9. ScopedTestNSSChromeOSUser::ScopedTestNSSChromeOSUser(
  10. const std::string& username_hash)
  11. : username_hash_(username_hash), constructed_successfully_(false) {
  12. if (!temp_dir_.CreateUniqueTempDir())
  13. return;
  14. // This opens a software DB in the given folder. In production code that is in
  15. // the home folder, but for testing the temp folder is used.
  16. constructed_successfully_ =
  17. InitializeNSSForChromeOSUser(username_hash, temp_dir_.GetPath());
  18. }
  19. ScopedTestNSSChromeOSUser::~ScopedTestNSSChromeOSUser() {
  20. if (constructed_successfully_)
  21. CloseChromeOSUserForTesting(username_hash_);
  22. }
  23. void ScopedTestNSSChromeOSUser::FinishInit() {
  24. DCHECK(constructed_successfully_);
  25. if (!ShouldInitializeTPMForChromeOSUser(username_hash_))
  26. return;
  27. WillInitializeTPMForChromeOSUser(username_hash_);
  28. InitializePrivateSoftwareSlotForChromeOSUser(username_hash_);
  29. }
  30. } // namespace crypto