Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(573)

Side by Side Diff: crypto/scoped_test_nss_db.cc

Issue 401623006: Extract ScopedTestNSSDB from nss_util. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git cl format Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
5 #include "crypto/scoped_test_nss_db.h"
6
7 #include "base/logging.h"
8 #include "base/threading/thread_restrictions.h"
9 #include "crypto/nss_util.h"
10 #include "crypto/nss_util_internal.h"
11
12 namespace crypto {
13
14 #if defined(USE_NSS)
15 ScopedTestNSSDB::ScopedTestNSSDB() {
16 EnsureNSSInit();
17 // NSS is allowed to do IO on the current thread since dispatching
18 // to a dedicated thread would still have the affect of blocking
19 // the current thread, due to NSS's internal locking requirements
20 base::ThreadRestrictions::ScopedAllowIO allow_io;
21
22 if (!temp_dir_.CreateUniqueTempDir())
23 return;
24
25 const char kTestTPMTokenName[] = "Test DB";
Ryan Sleevi 2014/07/22 01:25:32 Fix variable name. It's not a TPM :)
pneubeck (no reviews) 2014/07/22 14:11:05 Done.
26 slot_ = OpenUserDB(temp_dir_.path(), kTestTPMTokenName);
27 }
28
29 ScopedTestNSSDB::~ScopedTestNSSDB() {
30 // Don't close when NSS is < 3.15.1, because it would require an additional
31 // sleep for 1 second after closing the database, due to
32 // http://bugzil.la/875601.
33 if (!NSS_VersionCheck("3.15.1") || !slot_)
34 return;
35
36 // NSS is allowed to do IO on the current thread since dispatching
37 // to a dedicated thread would still have the affect of blocking
38 // the current thread, due to NSS's internal locking requirements
39 base::ThreadRestrictions::ScopedAllowIO allow_io;
40
41 SECStatus status = SECMOD_CloseUserDB(slot_.get());
42 if (status != SECSuccess)
43 PLOG(ERROR) << "SECMOD_CloseUserDB failed: " << PORT_GetError();
44
45 if (!temp_dir_.Delete())
46 LOG(ERROR) << "Could not delete temporary directory.";
47 }
48 #endif
49
50 } // namespace crypto
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698