Updating trunk VERSION from 1014.0 to 1015.0
[chromium-blink-merge.git] / net / base / cert_database.cc
blobb8c9aa3a529a578b5b7f3c518fb418b9f502a794
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.
5 #include "net/base/cert_database.h"
7 #include "base/memory/singleton.h"
8 #include "base/observer_list_threadsafe.h"
9 #include "net/base/x509_certificate.h"
11 namespace net {
13 CertDatabase::ImportCertFailure::ImportCertFailure(
14 X509Certificate* cert, int err)
15 : certificate(cert), net_error(err) {
18 CertDatabase::ImportCertFailure::~ImportCertFailure() {
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>) {
29 static CertDatabaseNotifier* GetInstance() {
30 return Singleton<CertDatabaseNotifier>::get();
33 friend struct DefaultSingletonTraits<CertDatabaseNotifier>;
34 friend class CertDatabase;
36 private:
37 const scoped_refptr<ObserverListThreadSafe<CertDatabase::Observer> >
38 observer_list_;
41 void CertDatabase::AddObserver(Observer* observer) {
42 CertDatabaseNotifier::GetInstance()->observer_list_->AddObserver(observer);
45 void CertDatabase::RemoveObserver(Observer* observer) {
46 CertDatabaseNotifier::GetInstance()->observer_list_->RemoveObserver(observer);
49 void CertDatabase::NotifyObserversOfUserCertAdded(const X509Certificate* cert) {
50 CertDatabaseNotifier::GetInstance()->observer_list_->Notify(
51 &CertDatabase::Observer::OnUserCertAdded, make_scoped_refptr(cert));
54 void CertDatabase::NotifyObserversOfCertTrustChanged(
55 const X509Certificate* cert) {
56 CertDatabaseNotifier::GetInstance()->observer_list_->Notify(
57 &CertDatabase::Observer::OnCertTrustChanged, make_scoped_refptr(cert));
60 } // namespace net