Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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 "chromeos/network/certificate_handler.h" | |
| 6 | |
| 7 #include "base/values.h" | |
| 8 #include "chromeos/network/onc/onc_certificate_importer.h" | |
| 9 #include "chromeos/network/onc/onc_utils.h" | |
| 10 | |
| 11 namespace chromeos { | |
| 12 | |
| 13 namespace { | |
| 14 CertificateHandler* g_certificate_handler_instance = NULL; | |
|
Joao da Silva
2013/04/22 10:38:09
I generally singletons with static getters.
The C
stevenjb
2013/04/22 16:53:41
I tend to agree. This is a useful model for classe
pneubeck (no reviews)
2013/04/22 18:15:50
Agree. This class was meant for several certificat
| |
| 15 } | |
| 16 | |
| 17 // static | |
| 18 void CertificateHandler::Initialize() { | |
| 19 CHECK(!g_certificate_handler_instance); | |
| 20 g_certificate_handler_instance = new CertificateHandler; | |
| 21 } | |
| 22 | |
| 23 // static | |
| 24 bool CertificateHandler::IsInitialized() { | |
| 25 return g_certificate_handler_instance; | |
| 26 } | |
| 27 | |
| 28 // static | |
| 29 void CertificateHandler::Shutdown() { | |
| 30 CHECK(g_certificate_handler_instance); | |
| 31 delete g_certificate_handler_instance; | |
| 32 g_certificate_handler_instance = NULL; | |
| 33 } | |
| 34 | |
| 35 // static | |
| 36 CertificateHandler* CertificateHandler::Get() { | |
| 37 CHECK(g_certificate_handler_instance); | |
| 38 return g_certificate_handler_instance; | |
| 39 } | |
| 40 | |
| 41 CertificateHandler::CertificateHandler() { | |
| 42 } | |
| 43 | |
| 44 CertificateHandler::~CertificateHandler() { | |
| 45 } | |
| 46 | |
| 47 bool CertificateHandler::ImportCertificates( | |
| 48 const base::ListValue& certificates, | |
| 49 onc::ONCSource source, | |
| 50 net::CertificateList* onc_trusted_certificates) { | |
| 51 VLOG(2) << "ONC file has " << certificates.GetSize() << " certificates"; | |
| 52 | |
| 53 // Web trust is only granted to certificates imported by the user. | |
| 54 bool allow_trust_imports = source == onc::ONC_SOURCE_USER_IMPORT; | |
| 55 onc::CertificateImporter cert_importer(allow_trust_imports); | |
| 56 if (cert_importer.ParseAndStoreCertificates( | |
| 57 certificates, onc_trusted_certificates) != | |
| 58 onc::CertificateImporter::IMPORT_OK) { | |
| 59 LOG(ERROR) << "Cannot parse some of the certificates in the ONC from " | |
| 60 << onc::GetSourceAsString(source); | |
| 61 return false; | |
| 62 } | |
| 63 return true; | |
| 64 } | |
| 65 | |
| 66 } // namespace chromeos | |
| OLD | NEW |