| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "content/browser/cert_store.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 | 9 |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "content/browser/renderer_host/render_process_host.h" | 11 #include "content/browser/renderer_host/render_process_host.h" |
| 12 #include "content/browser/renderer_host/render_view_host.h" | 12 #include "content/browser/renderer_host/render_view_host.h" |
| 13 #include "content/common/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
| 14 #include "content/public/browser/notification_types.h" | 14 #include "content/public/browser/notification_types.h" |
| 15 | 15 |
| 16 template <typename T> | 16 template <typename T> |
| 17 struct MatchSecond { | 17 struct MatchSecond { |
| 18 explicit MatchSecond(const T& t) : value(t) {} | 18 explicit MatchSecond(const T& t) : value(t) {} |
| 19 | 19 |
| 20 template<typename Pair> | 20 template<typename Pair> |
| 21 bool operator()(const Pair& p) const { | 21 bool operator()(const Pair& p) const { |
| 22 return (value == p.second); | 22 return (value == p.second); |
| 23 } | 23 } |
| 24 T value; | 24 T value; |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 // static | 27 // static |
| 28 CertStore* CertStore::GetInstance() { | 28 CertStore* CertStore::GetInstance() { |
| 29 return Singleton<CertStore>::get(); | 29 return Singleton<CertStore>::get(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 CertStore::CertStore() : next_cert_id_(1) { | 32 CertStore::CertStore() : next_cert_id_(1) { |
| 33 // We watch for RenderProcess termination, as this is how we clear | 33 // We watch for RenderProcess termination, as this is how we clear |
| 34 // certificates for now. | 34 // certificates for now. |
| 35 // TODO(jcampan): we should be listening to events such as resource cached/ | 35 // TODO(jcampan): we should be listening to events such as resource cached/ |
| 36 // removed from cache, and remove the cert when we know it | 36 // removed from cache, and remove the cert when we know it |
| 37 // is not used anymore. | 37 // is not used anymore. |
| 38 | 38 |
| 39 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 39 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 40 NotificationService::AllBrowserContextsAndSources()); | 40 content::NotificationService::AllBrowserContextsAndSources()); |
| 41 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 41 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 42 NotificationService::AllBrowserContextsAndSources()); | 42 content::NotificationService::AllBrowserContextsAndSources()); |
| 43 } | 43 } |
| 44 | 44 |
| 45 CertStore::~CertStore() { | 45 CertStore::~CertStore() { |
| 46 } | 46 } |
| 47 | 47 |
| 48 int CertStore::StoreCert(net::X509Certificate* cert, int process_id) { | 48 int CertStore::StoreCert(net::X509Certificate* cert, int process_id) { |
| 49 DCHECK(cert); | 49 DCHECK(cert); |
| 50 base::AutoLock autoLock(cert_lock_); | 50 base::AutoLock autoLock(cert_lock_); |
| 51 | 51 |
| 52 int cert_id; | 52 int cert_id; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 | 138 |
| 139 void CertStore::Observe(int type, | 139 void CertStore::Observe(int type, |
| 140 const content::NotificationSource& source, | 140 const content::NotificationSource& source, |
| 141 const content::NotificationDetails& details) { | 141 const content::NotificationDetails& details) { |
| 142 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED || | 142 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED || |
| 143 type == content::NOTIFICATION_RENDERER_PROCESS_CLOSED); | 143 type == content::NOTIFICATION_RENDERER_PROCESS_CLOSED); |
| 144 RenderProcessHost* rph = content::Source<RenderProcessHost>(source).ptr(); | 144 RenderProcessHost* rph = content::Source<RenderProcessHost>(source).ptr(); |
| 145 DCHECK(rph); | 145 DCHECK(rph); |
| 146 RemoveCertsForRenderProcesHost(rph->id()); | 146 RemoveCertsForRenderProcesHost(rph->id()); |
| 147 } | 147 } |
| OLD | NEW |