Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(636)

Side by Side Diff: content/browser/cert_store.h

Issue 9691003: Add Content API around CertStore. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix clang Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/website_settings_model_unittest.cc ('k') | content/browser/cert_store.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef CONTENT_BROWSER_CERT_STORE_H_
6 #define CONTENT_BROWSER_CERT_STORE_H_
7 #pragma once
8
9 #include <map>
10
11 #include "base/memory/singleton.h"
12 #include "base/synchronization/lock.h"
13 #include "content/common/content_export.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16 #include "net/base/x509_certificate.h"
17
18 // The purpose of the cert store is to provide an easy way to store/retrieve
19 // X509Certificate objects. When stored, an X509Certificate object is
20 // associated with a RenderProcessHost. If all the RenderProcessHosts
21 // associated with the cert have exited, the cert is removed from the store.
22 // This class is used by the SSLManager to keep track of the certs associated
23 // to loaded resources.
24 // It can be accessed from the UI and IO threads (it is thread-safe).
25 // Note that the cert ids will overflow if we register more than 2^32 - 1 certs
26 // in 1 browsing session (which is highly unlikely to happen).
27
28 class CONTENT_EXPORT CertStore : public content::NotificationObserver {
29 public:
30 // Returns the singleton instance of the CertStore.
31 static CertStore* GetInstance();
32
33 // Stores the specified cert and returns the id associated with it. The cert
34 // is associated to the specified RenderProcessHost.
35 // When all the RenderProcessHosts associated with a cert have exited, the
36 // cert is removed from the store.
37 // Note: ids starts at 1.
38 virtual int StoreCert(net::X509Certificate* cert, int render_process_host_id);
39
40 // Tries to retrieve the previously stored cert associated with the specified
41 // |cert_id|. Returns whether the cert could be found, and, if |cert| is
42 // non-NULL, copies it in.
43 virtual bool RetrieveCert(int cert_id,
44 scoped_refptr<net::X509Certificate>* cert);
45
46 // content::NotificationObserver implementation.
47 virtual void Observe(int type,
48 const content::NotificationSource& source,
49 const content::NotificationDetails& details) OVERRIDE;
50 protected:
51 CertStore();
52 virtual ~CertStore();
53
54 private:
55 friend struct DefaultSingletonTraits<CertStore>;
56
57 void RegisterForNotification();
58
59 // Remove the specified cert from id_to_cert_ and cert_to_id_.
60 // NOTE: the caller (RemoveCertsForRenderProcesHost) must hold cert_lock_.
61 void RemoveCertInternal(int cert_id);
62
63 // Removes all the certs associated with the specified process from the store.
64 void RemoveCertsForRenderProcesHost(int render_process_host_id);
65
66 typedef std::multimap<int, int> IDMap;
67 typedef std::map<int, scoped_refptr<net::X509Certificate> > CertMap;
68 typedef std::map<net::X509Certificate*, int, net::X509Certificate::LessThan>
69 ReverseCertMap;
70
71 // Is only used on the UI Thread.
72 content::NotificationRegistrar registrar_;
73
74 IDMap process_id_to_cert_id_;
75 IDMap cert_id_to_process_id_;
76
77 CertMap id_to_cert_;
78 ReverseCertMap cert_to_id_;
79
80 int next_cert_id_;
81
82 // This lock protects: process_to_ids_, id_to_processes_, id_to_cert_ and
83 // cert_to_id_.
84 base::Lock cert_lock_;
85
86 DISALLOW_COPY_AND_ASSIGN(CertStore);
87 };
88
89 #endif // CONTENT_BROWSER_CERT_STORE_H_
OLDNEW
« no previous file with comments | « chrome/browser/website_settings_model_unittest.cc ('k') | content/browser/cert_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698