[go: nahoru, domu]

blob: b5e1c3352afd417de214ba9c861fbd9cba40f474 [file] [log] [blame]
Avi Drissman201a9a832022-09-13 19:39:251// Copyright 2014 The Chromium Authors
pneubeck@chromium.org190933f2014-07-28 09:56:512// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "crypto/scoped_test_nss_chromeos_user.h"
6
Hans Wennborg4d0e1802020-04-24 20:19:437#include "base/check.h"
pneubeck@chromium.org190933f2014-07-28 09:56:518#include "crypto/nss_util.h"
9#include "crypto/nss_util_internal.h"
10
11namespace crypto {
12
13ScopedTestNSSChromeOSUser::ScopedTestNSSChromeOSUser(
14 const std::string& username_hash)
15 : username_hash_(username_hash), constructed_successfully_(false) {
16 if (!temp_dir_.CreateUniqueTempDir())
17 return;
18 // This opens a software DB in the given folder. In production code that is in
19 // the home folder, but for testing the temp folder is used.
pneubeckfa32f2e2014-09-12 09:59:0020 constructed_successfully_ =
vabr16e5f602016-09-15 18:14:0021 InitializeNSSForChromeOSUser(username_hash, temp_dir_.GetPath());
pneubeck@chromium.org190933f2014-07-28 09:56:5122}
23
24ScopedTestNSSChromeOSUser::~ScopedTestNSSChromeOSUser() {
25 if (constructed_successfully_)
26 CloseChromeOSUserForTesting(username_hash_);
27}
28
29void ScopedTestNSSChromeOSUser::FinishInit() {
30 DCHECK(constructed_successfully_);
31 if (!ShouldInitializeTPMForChromeOSUser(username_hash_))
32 return;
33 WillInitializeTPMForChromeOSUser(username_hash_);
34 InitializePrivateSoftwareSlotForChromeOSUser(username_hash_);
35}
36
37} // namespace crypto