scoped_test_nss_chromeos_user.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #ifndef CRYPTO_SCOPED_TEST_NSS_CHROMEOS_USER_H_
  5. #define CRYPTO_SCOPED_TEST_NSS_CHROMEOS_USER_H_
  6. #include <string>
  7. #include "base/files/scoped_temp_dir.h"
  8. #include "crypto/crypto_export.h"
  9. namespace crypto {
  10. // Opens a persistent NSS software database in a temporary directory for the
  11. // user with |username_hash|. This database will be used for both the user's
  12. // public and private slot.
  13. class CRYPTO_EXPORT ScopedTestNSSChromeOSUser {
  14. public:
  15. // Opens the software database and sets the public slot for the user. The
  16. // private slot will not be initialized until FinishInit() is called.
  17. explicit ScopedTestNSSChromeOSUser(const std::string& username_hash);
  18. ScopedTestNSSChromeOSUser(const ScopedTestNSSChromeOSUser&) = delete;
  19. ScopedTestNSSChromeOSUser& operator=(const ScopedTestNSSChromeOSUser&) =
  20. delete;
  21. ~ScopedTestNSSChromeOSUser();
  22. std::string username_hash() const { return username_hash_; }
  23. bool constructed_successfully() const { return constructed_successfully_; }
  24. // Completes initialization of user. Causes any waiting private slot callbacks
  25. // to run, see GetPrivateSlotForChromeOSUser().
  26. void FinishInit();
  27. private:
  28. const std::string username_hash_;
  29. base::ScopedTempDir temp_dir_;
  30. bool constructed_successfully_;
  31. };
  32. } // namespace crypto
  33. #endif // CRYPTO_SCOPED_TEST_NSS_CHROMEOS_USER_H_