OLD | NEW |
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 #include "content/browser/cert_store_impl.h" | 5 #include "content/browser/cert_store_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "content/browser/renderer_host/render_process_host_impl.h" | 12 #include "content/browser/renderer_host/render_process_host_impl.h" |
13 #include "content/browser/renderer_host/render_view_host_impl.h" | 13 #include "content/browser/renderer_host/render_view_host_impl.h" |
14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
16 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
17 | 17 |
| 18 namespace content { |
| 19 |
| 20 namespace { |
| 21 |
18 template <typename T> | 22 template <typename T> |
19 struct MatchSecond { | 23 struct MatchSecond { |
20 explicit MatchSecond(const T& t) : value(t) {} | 24 explicit MatchSecond(const T& t) : value(t) {} |
21 | 25 |
22 template<typename Pair> | 26 template<typename Pair> |
23 bool operator()(const Pair& p) const { | 27 bool operator()(const Pair& p) const { |
24 return (value == p.second); | 28 return (value == p.second); |
25 } | 29 } |
26 T value; | 30 T value; |
27 }; | 31 }; |
28 | 32 |
| 33 } // namespace |
| 34 |
29 // static | 35 // static |
30 content::CertStore* content::CertStore::GetInstance() { | 36 CertStore* CertStore::GetInstance() { |
31 return CertStoreImpl::GetInstance(); | 37 return CertStoreImpl::GetInstance(); |
32 } | 38 } |
33 | 39 |
34 // static | 40 // static |
35 CertStoreImpl* CertStoreImpl::GetInstance() { | 41 CertStoreImpl* CertStoreImpl::GetInstance() { |
36 return Singleton<CertStoreImpl>::get(); | 42 return Singleton<CertStoreImpl>::get(); |
37 } | 43 } |
38 | 44 |
39 CertStoreImpl::CertStoreImpl() : next_cert_id_(1) { | 45 CertStoreImpl::CertStoreImpl() : next_cert_id_(1) { |
40 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | 46 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
41 RegisterForNotification(); | 47 RegisterForNotification(); |
42 } else { | 48 } else { |
43 content::BrowserThread::PostTask( | 49 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
44 content::BrowserThread::UI, FROM_HERE, | |
45 base::Bind(&CertStoreImpl::RegisterForNotification, | 50 base::Bind(&CertStoreImpl::RegisterForNotification, |
46 base::Unretained(this))); | 51 base::Unretained(this))); |
47 } | 52 } |
48 } | 53 } |
49 | 54 |
50 CertStoreImpl::~CertStoreImpl() { | 55 CertStoreImpl::~CertStoreImpl() { |
51 } | 56 } |
52 | 57 |
53 void CertStoreImpl::RegisterForNotification() { | 58 void CertStoreImpl::RegisterForNotification() { |
54 // We watch for RenderProcess termination, as this is how we clear | 59 // We watch for RenderProcess termination, as this is how we clear |
55 // certificates for now. | 60 // certificates for now. |
56 // TODO(jcampan): we should be listening to events such as resource cached/ | 61 // TODO(jcampan): we should be listening to events such as resource cached/ |
57 // removed from cache, and remove the cert when we know it | 62 // removed from cache, and remove the cert when we know it |
58 // is not used anymore. | 63 // is not used anymore. |
59 | 64 |
60 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 65 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
61 content::NotificationService::AllBrowserContextsAndSources()); | 66 NotificationService::AllBrowserContextsAndSources()); |
62 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 67 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED, |
63 content::NotificationService::AllBrowserContextsAndSources()); | 68 NotificationService::AllBrowserContextsAndSources()); |
64 } | 69 } |
65 | 70 |
66 int CertStoreImpl::StoreCert(net::X509Certificate* cert, int process_id) { | 71 int CertStoreImpl::StoreCert(net::X509Certificate* cert, int process_id) { |
67 DCHECK(cert); | 72 DCHECK(cert); |
68 base::AutoLock auto_lock(cert_lock_); | 73 base::AutoLock auto_lock(cert_lock_); |
69 | 74 |
70 int cert_id; | 75 int cert_id; |
71 | 76 |
72 // Do we already know this cert? | 77 // Do we already know this cert? |
73 ReverseCertMap::iterator cert_iter = cert_to_id_.find(cert); | 78 ReverseCertMap::iterator cert_iter = cert_to_id_.find(cert); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // The current cert id is not referenced by any other processes, so | 166 // The current cert id is not referenced by any other processes, so |
162 // remove it from id_to_cert_ and cert_to_id_. | 167 // remove it from id_to_cert_ and cert_to_id_. |
163 RemoveCertInternal(cert_id); | 168 RemoveCertInternal(cert_id); |
164 } | 169 } |
165 } | 170 } |
166 if (process_ids.first != process_ids.second) | 171 if (process_ids.first != process_ids.second) |
167 process_id_to_cert_id_.erase(process_ids.first, process_ids.second); | 172 process_id_to_cert_id_.erase(process_ids.first, process_ids.second); |
168 } | 173 } |
169 | 174 |
170 void CertStoreImpl::Observe(int type, | 175 void CertStoreImpl::Observe(int type, |
171 const content::NotificationSource& source, | 176 const NotificationSource& source, |
172 const content::NotificationDetails& details) { | 177 const NotificationDetails& details) { |
173 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED || | 178 DCHECK(type == NOTIFICATION_RENDERER_PROCESS_TERMINATED || |
174 type == content::NOTIFICATION_RENDERER_PROCESS_CLOSED); | 179 type == NOTIFICATION_RENDERER_PROCESS_CLOSED); |
175 content::RenderProcessHost* rph = | 180 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr(); |
176 content::Source<content::RenderProcessHost>(source).ptr(); | |
177 DCHECK(rph); | 181 DCHECK(rph); |
178 RemoveCertsForRenderProcesHost(rph->GetID()); | 182 RemoveCertsForRenderProcesHost(rph->GetID()); |
179 } | 183 } |
| 184 |
| 185 } // namespace content |
OLD | NEW |