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

Unified Diff: net/base/cert_database.cc

Issue 10916094: Move the NSS functions out of CertDatabase into a new NSSCertDatabase class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: net/base/cert_database.cc
diff --git a/net/base/cert_database.cc b/net/base/cert_database.cc
index 7930750757de371ef6df10bfbffbeb98da1cf4cb..8d7475c70eb9d45e27e955632ddd150bccbd908b 100644
--- a/net/base/cert_database.cc
+++ b/net/base/cert_database.cc
@@ -7,59 +7,81 @@
#include "base/memory/singleton.h"
#include "base/observer_list_threadsafe.h"
+#if defined(USE_NSS)
+#include "net/base/nss_cert_database.h"
+#endif
+
namespace net {
-CertDatabase::ImportCertFailure::ImportCertFailure(
- X509Certificate* cert, int err)
- : certificate(cert), net_error(err) {
-}
+#if defined(USE_NSS)
+// Helper that observes events from the NSSCertDatabase and forwards them to
+// the given CertDatabase.
+class CertDatabase::Notifier : public NSSCertDatabase::Observer {
wtc 2012/09/10 22:11:01 Ideally the USE_NSS code in this file should be mo
+ public:
+ explicit Notifier(CertDatabase* cert_db) : cert_db_(cert_db) {
+ NSSCertDatabase::GetInstance()->AddObserver(this);
+ }
-CertDatabase::ImportCertFailure::~ImportCertFailure() {
-}
+ virtual ~Notifier() {
+ NSSCertDatabase::GetInstance()->RemoveObserver(this);
+ }
-// CertDatabaseNotifier notifies registered observers when new user certificates
-// are added to the database.
-class CertDatabaseNotifier {
- public:
- CertDatabaseNotifier()
- : observer_list_(new ObserverListThreadSafe<CertDatabase::Observer>) {
+ // NSSCertDatabase::Observer implementation:
+ virtual void OnCertAdded(const X509Certificate* cert) OVERRIDE {
+ cert_db_->NotifyObserversOfCertAdded(cert);
}
- static CertDatabaseNotifier* GetInstance() {
- return Singleton<CertDatabaseNotifier>::get();
+ virtual void OnCertRemoved(const X509Certificate* cert) OVERRIDE {
+ cert_db_->NotifyObserversOfCertRemoved(cert);
}
- friend struct DefaultSingletonTraits<CertDatabaseNotifier>;
- friend class CertDatabase;
+ virtual void OnCertTrustChanged(const X509Certificate* cert) OVERRIDE {
+ cert_db_->NotifyObserversOfCertTrustChanged(cert);
+ }
private:
- const scoped_refptr<ObserverListThreadSafe<CertDatabase::Observer> >
- observer_list_;
+ CertDatabase* cert_db_;
+
+ DISALLOW_COPY_AND_ASSIGN(Notifier);
};
+#endif
+
+// static
+CertDatabase* CertDatabase::GetInstance() {
+ return Singleton<CertDatabase>::get();
+}
+
+CertDatabase::CertDatabase()
+ : observer_list_(new ObserverListThreadSafe<Observer>) {
+#if defined(USE_NSS)
+ // Observe NSSCertDatabase events and forward them to observers of
+ // CertDatabase. This also makes sure that NSS has been initialized.
+ notifier_.reset(new Notifier(this));
+#endif
+}
+
+CertDatabase::~CertDatabase() {}
void CertDatabase::AddObserver(Observer* observer) {
- CertDatabaseNotifier::GetInstance()->observer_list_->AddObserver(observer);
+ observer_list_->AddObserver(observer);
}
void CertDatabase::RemoveObserver(Observer* observer) {
- CertDatabaseNotifier::GetInstance()->observer_list_->RemoveObserver(observer);
+ observer_list_->RemoveObserver(observer);
}
-void CertDatabase::NotifyObserversOfUserCertAdded(const X509Certificate* cert) {
- CertDatabaseNotifier::GetInstance()->observer_list_->Notify(
- &CertDatabase::Observer::OnUserCertAdded, make_scoped_refptr(cert));
+void CertDatabase::NotifyObserversOfCertAdded(const X509Certificate* cert) {
+ observer_list_->Notify(&Observer::OnCertAdded, make_scoped_refptr(cert));
}
-void CertDatabase::NotifyObserversOfUserCertRemoved(
- const X509Certificate* cert) {
- CertDatabaseNotifier::GetInstance()->observer_list_->Notify(
- &CertDatabase::Observer::OnUserCertRemoved, make_scoped_refptr(cert));
+void CertDatabase::NotifyObserversOfCertRemoved(const X509Certificate* cert) {
+ observer_list_->Notify(&Observer::OnCertRemoved, make_scoped_refptr(cert));
}
void CertDatabase::NotifyObserversOfCertTrustChanged(
const X509Certificate* cert) {
- CertDatabaseNotifier::GetInstance()->observer_list_->Notify(
- &CertDatabase::Observer::OnCertTrustChanged, make_scoped_refptr(cert));
+ observer_list_->Notify(
+ &Observer::OnCertTrustChanged, make_scoped_refptr(cert));
}
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698