1 // Copyright 2012 The Chromium Authors 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/cert/cert_database.h" 6 7 #include "base/metrics/histogram_functions.h" 8 #include "base/observer_list_threadsafe.h" 9 #include "build/build_config.h" 10 #include "net/log/net_log.h" 11 #include "net/log/net_log_values.h" 12 13 namespace net { 14 15 namespace { 16 RecordNotificationHistogram(CertDatabase::HistogramNotificationType type)17void RecordNotificationHistogram(CertDatabase::HistogramNotificationType type) { 18 base::UmaHistogramEnumeration("Net.Certificate.ChangeNotification", type); 19 } 20 21 } // namespace 22 23 // static GetInstance()24CertDatabase* CertDatabase::GetInstance() { 25 static base::NoDestructor<CertDatabase> cert_database; 26 return cert_database.get(); 27 } 28 AddObserver(Observer * observer)29void CertDatabase::AddObserver(Observer* observer) { 30 observer_list_->AddObserver(observer); 31 } 32 RemoveObserver(Observer * observer)33void CertDatabase::RemoveObserver(Observer* observer) { 34 observer_list_->RemoveObserver(observer); 35 } 36 NotifyObserversTrustStoreChanged()37void CertDatabase::NotifyObserversTrustStoreChanged() { 38 // Log to NetLog as it may help debug issues like https://crbug.com/915463 39 // This isn't guarded with net::NetLog::Get()->IsCapturing()) because an 40 // AddGlobalEntry() call without much computation is really cheap. 41 net::NetLog::Get()->AddGlobalEntry( 42 NetLogEventType::CERTIFICATE_DATABASE_TRUST_STORE_CHANGED); 43 44 RecordNotificationHistogram(HistogramNotificationType::kTrust); 45 46 observer_list_->Notify(FROM_HERE, &Observer::OnTrustStoreChanged); 47 } 48 NotifyObserversClientCertStoreChanged()49void CertDatabase::NotifyObserversClientCertStoreChanged() { 50 // Log to NetLog as it may help debug issues like https://crbug.com/915463 51 // This isn't guarded with net::NetLog::Get()->IsCapturing()) because an 52 // AddGlobalEntry() call without much computation is really cheap. 53 net::NetLog::Get()->AddGlobalEntry( 54 NetLogEventType::CERTIFICATE_DATABASE_CLIENT_CERT_STORE_CHANGED); 55 56 RecordNotificationHistogram(HistogramNotificationType::kClientCert); 57 58 observer_list_->Notify(FROM_HERE, &Observer::OnClientCertStoreChanged); 59 } 60 CertDatabase()61CertDatabase::CertDatabase() 62 : observer_list_( 63 base::MakeRefCounted<base::ObserverListThreadSafe<Observer>>()) {} 64 65 } // namespace net 66