| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/cert/test_root_certs.h" | 5 #include "net/cert/test_root_certs.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/threading/thread_restrictions.h" |
| 12 #include "net/cert/x509_certificate.h" | 13 #include "net/cert/x509_certificate.h" |
| 13 | 14 |
| 14 namespace net { | 15 namespace net { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 bool g_has_instance = false; | 19 bool g_has_instance = false; |
| 19 | 20 |
| 20 base::LazyInstance<TestRootCerts>::Leaky | 21 base::LazyInstance<TestRootCerts>::Leaky |
| 21 g_test_root_certs = LAZY_INSTANCE_INITIALIZER; | 22 g_test_root_certs = LAZY_INSTANCE_INITIALIZER; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 36 // static | 37 // static |
| 37 TestRootCerts* TestRootCerts::GetInstance() { | 38 TestRootCerts* TestRootCerts::GetInstance() { |
| 38 return g_test_root_certs.Pointer(); | 39 return g_test_root_certs.Pointer(); |
| 39 } | 40 } |
| 40 | 41 |
| 41 bool TestRootCerts::HasInstance() { | 42 bool TestRootCerts::HasInstance() { |
| 42 return g_has_instance; | 43 return g_has_instance; |
| 43 } | 44 } |
| 44 | 45 |
| 45 bool TestRootCerts::AddFromFile(const base::FilePath& file) { | 46 bool TestRootCerts::AddFromFile(const base::FilePath& file) { |
| 47 base::ThreadRestrictions::ScopedAllowIO allow_io_for_loading_test_certs; |
| 46 CertificateList root_certs = LoadCertificates(file); | 48 CertificateList root_certs = LoadCertificates(file); |
| 47 if (root_certs.empty() || root_certs.size() > 1) | 49 if (root_certs.empty() || root_certs.size() > 1) |
| 48 return false; | 50 return false; |
| 49 | 51 |
| 50 return Add(root_certs.front().get()); | 52 return Add(root_certs.front().get()); |
| 51 } | 53 } |
| 52 | 54 |
| 53 TestRootCerts::TestRootCerts() { | 55 TestRootCerts::TestRootCerts() { |
| 54 Init(); | 56 Init(); |
| 55 g_has_instance = true; | 57 g_has_instance = true; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 67 | 69 |
| 68 void ScopedTestRoot::Reset(X509Certificate* cert) { | 70 void ScopedTestRoot::Reset(X509Certificate* cert) { |
| 69 if (cert_.get()) | 71 if (cert_.get()) |
| 70 TestRootCerts::GetInstance()->Clear(); | 72 TestRootCerts::GetInstance()->Clear(); |
| 71 if (cert) | 73 if (cert) |
| 72 TestRootCerts::GetInstance()->Add(cert); | 74 TestRootCerts::GetInstance()->Add(cert); |
| 73 cert_ = cert; | 75 cert_ = cert; |
| 74 } | 76 } |
| 75 | 77 |
| 76 } // namespace net | 78 } // namespace net |
| OLD | NEW |