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/cert_database.h" | 5 #include "net/cert/cert_database.h" |
6 | 6 |
7 #include <cert.h> | 7 #include <cert.h> |
8 #include <pk11pub.h> | 8 #include <pk11pub.h> |
9 #include <secmod.h> | 9 #include <secmod.h> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/observer_list_threadsafe.h" | 12 #include "base/observer_list_threadsafe.h" |
13 #include "crypto/nss_util.h" | 13 #include "crypto/nss_util.h" |
14 #include "crypto/scoped_nss_types.h" | 14 #include "crypto/scoped_nss_types.h" |
15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
16 #include "net/cert/nss_cert_database.h" | |
17 #include "net/cert/x509_certificate.h" | 16 #include "net/cert/x509_certificate.h" |
18 #include "net/cert/x509_util_nss.h" | 17 #include "net/cert/x509_util_nss.h" |
19 | 18 |
20 namespace net { | 19 namespace net { |
21 | 20 |
22 // Helper that observes events from the NSSCertDatabase and forwards them to | 21 // Helper that observes events from any other cert database (currently |
23 // the given CertDatabase. | 22 // NSSCertDatabase) and forwards them to the given CertDatabase. |
24 class CertDatabase::Notifier : public NSSCertDatabase::Observer { | 23 class CertDatabase::Notifier : public CertDatabase::Observer { |
25 public: | 24 public: |
26 explicit Notifier(CertDatabase* cert_db) : cert_db_(cert_db) {} | 25 explicit Notifier(CertDatabase* cert_db) : cert_db_(cert_db) {} |
27 | 26 |
28 virtual ~Notifier() {} | 27 virtual ~Notifier() {} |
29 | 28 |
30 // NSSCertDatabase::Observer implementation: | 29 // CertDatabase::Observer implementation: |
31 virtual void OnCertAdded(const X509Certificate* cert) OVERRIDE { | 30 virtual void OnCertAdded(const X509Certificate* cert) OVERRIDE { |
32 cert_db_->NotifyObserversOfCertAdded(cert); | 31 cert_db_->NotifyObserversOfCertAdded(cert); |
33 } | 32 } |
34 | 33 |
35 virtual void OnCertRemoved(const X509Certificate* cert) OVERRIDE { | 34 virtual void OnCertRemoved(const X509Certificate* cert) OVERRIDE { |
36 cert_db_->NotifyObserversOfCertRemoved(cert); | 35 cert_db_->NotifyObserversOfCertRemoved(cert); |
37 } | 36 } |
38 | 37 |
39 virtual void OnCACertChanged(const X509Certificate* cert) OVERRIDE { | 38 virtual void OnCACertChanged(const X509Certificate* cert) OVERRIDE { |
40 cert_db_->NotifyObserversOfCACertChanged(cert); | 39 cert_db_->NotifyObserversOfCACertChanged(cert); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 96 |
98 if (rv != SECSuccess) { | 97 if (rv != SECSuccess) { |
99 LOG(ERROR) << "Couldn't import user certificate. " << PORT_GetError(); | 98 LOG(ERROR) << "Couldn't import user certificate. " << PORT_GetError(); |
100 return ERR_ADD_USER_CERT_FAILED; | 99 return ERR_ADD_USER_CERT_FAILED; |
101 } | 100 } |
102 | 101 |
103 NotifyObserversOfCertAdded(cert_obj); | 102 NotifyObserversOfCertAdded(cert_obj); |
104 return OK; | 103 return OK; |
105 } | 104 } |
106 | 105 |
107 void CertDatabase::ObserveNSSCertDatabase(NSSCertDatabase* source) { | 106 CertDatabase::Observer* CertDatabase::GetObserver() { |
108 source->AddObserver(this->notifier_.get()); | 107 return notifier_.get(); |
109 } | 108 } |
110 | 109 |
111 } // namespace net | 110 } // namespace net |
OLD | NEW |