#ifndef CONTENT_BROWSER_CERT_STORE_IMPL_H_
#define CONTENT_BROWSER_CERT_STORE_IMPL_H_
#include <map>
#include "base/memory/singleton.h"
#include "base/synchronization/lock.h"
#include "content/public/browser/cert_store.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "net/base/x509_certificate.h"
class CertStoreImpl : public content::CertStore,
public content::NotificationObserver {
public:
static CertStoreImpl* GetInstance();
virtual int StoreCert(net::X509Certificate* cert,
int render_process_host_id) OVERRIDE;
virtual bool RetrieveCert(int cert_id,
scoped_refptr<net::X509Certificate>* cert) OVERRIDE;
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
protected:
CertStoreImpl();
virtual ~CertStoreImpl();
private:
friend struct DefaultSingletonTraits<CertStoreImpl>;
void RegisterForNotification();
void RemoveCertInternal(int cert_id);
void RemoveCertsForRenderProcesHost(int render_process_host_id);
typedef std::multimap<int, int> IDMap;
typedef std::map<int, scoped_refptr<net::X509Certificate> > CertMap;
typedef std::map<net::X509Certificate*, int, net::X509Certificate::LessThan>
ReverseCertMap;
content::NotificationRegistrar registrar_;
IDMap process_id_to_cert_id_;
IDMap cert_id_to_process_id_;
CertMap id_to_cert_;
ReverseCertMap cert_to_id_;
int next_cert_id_;
base::Lock cert_lock_;
DISALLOW_COPY_AND_ASSIGN(CertStoreImpl);
};
#endif