[SyncFS] Add call-on-idle closure to SyncWorker for testing
[chromium-blink-merge.git] / crypto / scoped_test_nss_db.cc
bloba3ff68b8b16dd2506f75f2f379c3a431b5e92575
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.
5 #include "crypto/scoped_test_nss_db.h"
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"
12 namespace crypto {
14 ScopedTestNSSDB::ScopedTestNSSDB() {
15 EnsureNSSInit();
16 // NSS is allowed to do IO on the current thread since dispatching
17 // to a dedicated thread would still have the affect of blocking
18 // the current thread, due to NSS's internal locking requirements
19 base::ThreadRestrictions::ScopedAllowIO allow_io;
21 if (!temp_dir_.CreateUniqueTempDir())
22 return;
24 const char kTestDescription[] = "Test DB";
25 slot_ = OpenSoftwareNSSDB(temp_dir_.path(), kTestDescription);
28 ScopedTestNSSDB::~ScopedTestNSSDB() {
29 // Don't close when NSS is < 3.15.1, because it would require an additional
30 // sleep for 1 second after closing the database, due to
31 // http://bugzil.la/875601.
32 if (!NSS_VersionCheck("3.15.1") || !slot_)
33 return;
35 // NSS is allowed to do IO on the current thread since dispatching
36 // to a dedicated thread would still have the affect of blocking
37 // the current thread, due to NSS's internal locking requirements
38 base::ThreadRestrictions::ScopedAllowIO allow_io;
40 SECStatus status = SECMOD_CloseUserDB(slot_.get());
41 if (status != SECSuccess)
42 PLOG(ERROR) << "SECMOD_CloseUserDB failed: " << PORT_GetError();
44 if (!temp_dir_.Delete())
45 LOG(ERROR) << "Could not delete temporary directory.";
48 } // namespace crypto