Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / public / browser / cert_store.h
blob73c35a24e8ec828379882d11a136addbe68495b3
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_PUBLIC_BROWSER_CERT_STORE_H_
6 #define CONTENT_PUBLIC_BROWSER_CERT_STORE_H_
8 #include "base/memory/ref_counted.h"
9 #include "content/common/content_export.h"
11 namespace net {
12 class X509Certificate;
15 namespace content {
17 // The purpose of the cert store is to provide an easy way to store/retrieve
18 // X509Certificate objects. When stored, an X509Certificate object is
19 // associated with a RenderProcessHost. If all the RenderProcessHosts
20 // associated with the cert have exited, the cert is removed from the store.
21 // This class is used by the SSLManager to keep track of the certs associated
22 // to loaded resources.
23 // It can be accessed from the UI and IO threads (it is thread-safe).
24 // Note that the cert ids will overflow if we register more than 2^32 - 1 certs
25 // in 1 browsing session (which is highly unlikely to happen).
26 class CertStore {
27 public:
28 // Returns the singleton instance of the CertStore.
29 CONTENT_EXPORT static CertStore* GetInstance();
31 // Stores the specified cert and returns the id associated with it. The cert
32 // is associated to the specified RenderProcessHost.
33 // When all the RenderProcessHosts associated with a cert have exited, the
34 // cert is removed from the store.
35 // Note: ids starts at 1.
36 virtual int StoreCert(net::X509Certificate* cert,
37 int render_process_host_id) = 0;
39 // Tries to retrieve the previously stored cert associated with the specified
40 // |cert_id|. Returns whether the cert could be found, and, if |cert| is
41 // non-nullptr, copies it in.
42 virtual bool RetrieveCert(int cert_id,
43 scoped_refptr<net::X509Certificate>* cert) = 0;
45 protected:
46 virtual ~CertStore() {}
49 } // namespace content
51 #endif // CONTENT_PUBLIC_BROWSER_CERT_STORE_H_