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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_CERT_STORE_IMPL_H_
6 #define CONTENT_BROWSER_CERT_STORE_IMPL_H_
10 #include "base/memory/singleton.h"
11 #include "base/synchronization/lock.h"
12 #include "content/public/browser/cert_store.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "net/cert/x509_certificate.h"
19 class CertStoreImpl
: public CertStore
,
20 public NotificationObserver
{
22 // Returns the singleton instance of the CertStore.
23 static CertStoreImpl
* GetInstance();
25 // CertStore implementation:
26 virtual int StoreCert(net::X509Certificate
* cert
,
27 int render_process_host_id
) OVERRIDE
;
28 virtual bool RetrieveCert(int cert_id
,
29 scoped_refptr
<net::X509Certificate
>* cert
) OVERRIDE
;
31 // NotificationObserver implementation.
32 virtual void Observe(int type
,
33 const NotificationSource
& source
,
34 const NotificationDetails
& details
) OVERRIDE
;
37 virtual ~CertStoreImpl();
40 friend struct DefaultSingletonTraits
<CertStoreImpl
>;
42 void RegisterForNotification();
44 // Remove the specified cert from id_to_cert_ and cert_to_id_.
45 // NOTE: the caller (RemoveCertsForRenderProcesHost) must hold cert_lock_.
46 void RemoveCertInternal(int cert_id
);
48 // Removes all the certs associated with the specified process from the store.
49 void RemoveCertsForRenderProcesHost(int render_process_host_id
);
51 typedef std::multimap
<int, int> IDMap
;
52 typedef std::map
<int, scoped_refptr
<net::X509Certificate
> > CertMap
;
53 typedef std::map
<net::X509Certificate
*, int, net::X509Certificate::LessThan
>
56 // Is only used on the UI Thread.
57 NotificationRegistrar registrar_
;
59 IDMap process_id_to_cert_id_
;
60 IDMap cert_id_to_process_id_
;
63 ReverseCertMap cert_to_id_
;
67 // This lock protects: process_to_ids_, id_to_processes_, id_to_cert_ and
69 base::Lock cert_lock_
;
71 DISALLOW_COPY_AND_ASSIGN(CertStoreImpl
);
74 } // namespace content
76 #endif // CONTENT_BROWSER_CERT_STORE_IMPL_H_