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

Side by Side Diff: content/browser/cert_store_impl.cc

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

Powered by Google App Engine
This is Rietveld 408576698