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

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

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

Powered by Google App Engine
This is Rietveld 408576698