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

Side by Side Diff: content/browser/cert_store_impl.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 | « content/browser/cert_store.cc ('k') | content/browser/cert_store_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_CERT_STORE_H_ 5 #ifndef CONTENT_BROWSER_CERT_STORE_IMPL_H_
6 #define CONTENT_BROWSER_CERT_STORE_H_ 6 #define CONTENT_BROWSER_CERT_STORE_IMPL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 10
11 #include "base/memory/singleton.h" 11 #include "base/memory/singleton.h"
12 #include "base/synchronization/lock.h" 12 #include "base/synchronization/lock.h"
13 #include "content/common/content_export.h" 13 #include "content/public/browser/cert_store.h"
14 #include "content/public/browser/notification_observer.h" 14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h" 15 #include "content/public/browser/notification_registrar.h"
16 #include "net/base/x509_certificate.h" 16 #include "net/base/x509_certificate.h"
17 17
18 // The purpose of the cert store is to provide an easy way to store/retrieve 18 class CertStoreImpl : public content::CertStore,
19 // X509Certificate objects. When stored, an X509Certificate object is 19 public content::NotificationObserver {
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: 20 public:
30 // Returns the singleton instance of the CertStore. 21 // Returns the singleton instance of the CertStore.
31 static CertStore* GetInstance(); 22 static CertStoreImpl* GetInstance();
32 23
33 // Stores the specified cert and returns the id associated with it. The cert 24 // CertStore implementation:
34 // is associated to the specified RenderProcessHost. 25 virtual int StoreCert(net::X509Certificate* cert,
35 // When all the RenderProcessHosts associated with a cert have exited, the 26 int render_process_host_id) OVERRIDE;
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, 27 virtual bool RetrieveCert(int cert_id,
44 scoped_refptr<net::X509Certificate>* cert); 28 scoped_refptr<net::X509Certificate>* cert) OVERRIDE;
45 29
46 // content::NotificationObserver implementation. 30 // content::NotificationObserver implementation.
47 virtual void Observe(int type, 31 virtual void Observe(int type,
48 const content::NotificationSource& source, 32 const content::NotificationSource& source,
49 const content::NotificationDetails& details) OVERRIDE; 33 const content::NotificationDetails& details) OVERRIDE;
50 protected: 34 protected:
51 CertStore(); 35 CertStoreImpl();
52 virtual ~CertStore(); 36 virtual ~CertStoreImpl();
53 37
54 private: 38 private:
55 friend struct DefaultSingletonTraits<CertStore>; 39 friend struct DefaultSingletonTraits<CertStoreImpl>;
56 40
57 void RegisterForNotification(); 41 void RegisterForNotification();
58 42
59 // Remove the specified cert from id_to_cert_ and cert_to_id_. 43 // Remove the specified cert from id_to_cert_ and cert_to_id_.
60 // NOTE: the caller (RemoveCertsForRenderProcesHost) must hold cert_lock_. 44 // NOTE: the caller (RemoveCertsForRenderProcesHost) must hold cert_lock_.
61 void RemoveCertInternal(int cert_id); 45 void RemoveCertInternal(int cert_id);
62 46
63 // Removes all the certs associated with the specified process from the store. 47 // Removes all the certs associated with the specified process from the store.
64 void RemoveCertsForRenderProcesHost(int render_process_host_id); 48 void RemoveCertsForRenderProcesHost(int render_process_host_id);
65 49
(...skipping 10 matching lines...) Expand all
76 60
77 CertMap id_to_cert_; 61 CertMap id_to_cert_;
78 ReverseCertMap cert_to_id_; 62 ReverseCertMap cert_to_id_;
79 63
80 int next_cert_id_; 64 int next_cert_id_;
81 65
82 // This lock protects: process_to_ids_, id_to_processes_, id_to_cert_ and 66 // This lock protects: process_to_ids_, id_to_processes_, id_to_cert_ and
83 // cert_to_id_. 67 // cert_to_id_.
84 base::Lock cert_lock_; 68 base::Lock cert_lock_;
85 69
86 DISALLOW_COPY_AND_ASSIGN(CertStore); 70 DISALLOW_COPY_AND_ASSIGN(CertStoreImpl);
87 }; 71 };
88 72
89 #endif // CONTENT_BROWSER_CERT_STORE_H_ 73 #endif // CONTENT_BROWSER_CERT_STORE_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/cert_store.cc ('k') | content/browser/cert_store_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698