Home | History | Annotate | Download | only in base
      1 // Copyright (c) 2011 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 "net/base/cert_database.h"
      6 
      7 #include "base/memory/singleton.h"
      8 #include "base/observer_list_threadsafe.h"
      9 #include "net/base/x509_certificate.h"
     10 
     11 namespace net {
     12 
     13 CertDatabase::ImportCertFailure::ImportCertFailure(
     14     X509Certificate* cert, int err)
     15     : certificate(cert), net_error(err) {
     16 }
     17 
     18 CertDatabase::ImportCertFailure::~ImportCertFailure() {
     19 }
     20 
     21 // CertDatabaseNotifier notifies registered observers when new user certificates
     22 // are added to the database.
     23 class CertDatabaseNotifier {
     24  public:
     25   CertDatabaseNotifier()
     26       : observer_list_(new ObserverListThreadSafe<CertDatabase::Observer>) {
     27   }
     28 
     29   static CertDatabaseNotifier* GetInstance() {
     30     return Singleton<CertDatabaseNotifier>::get();
     31   }
     32 
     33   friend struct DefaultSingletonTraits<CertDatabaseNotifier>;
     34   friend class CertDatabase;
     35 
     36  private:
     37   const scoped_refptr<ObserverListThreadSafe<CertDatabase::Observer> >
     38       observer_list_;
     39 };
     40 
     41 void CertDatabase::AddObserver(Observer* observer) {
     42   CertDatabaseNotifier::GetInstance()->observer_list_->AddObserver(observer);
     43 }
     44 
     45 void CertDatabase::RemoveObserver(Observer* observer) {
     46   CertDatabaseNotifier::GetInstance()->observer_list_->RemoveObserver(observer);
     47 }
     48 
     49 void CertDatabase::NotifyObserversOfUserCertAdded(const X509Certificate* cert) {
     50   CertDatabaseNotifier::GetInstance()->observer_list_->Notify(
     51       &CertDatabase::Observer::OnUserCertAdded, make_scoped_refptr(cert));
     52 }
     53 
     54 void CertDatabase::NotifyObserversOfCertTrustChanged(
     55     const X509Certificate* cert) {
     56   CertDatabaseNotifier::GetInstance()->observer_list_->Notify(
     57       &CertDatabase::Observer::OnCertTrustChanged, make_scoped_refptr(cert));
     58 }
     59 
     60 }  // namespace net
     61