OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/cert_store.h" | 5 #include "chrome/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-inl.h" | 10 #include "base/stl_util-inl.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 AutoLock autoLock(cert_lock_); | 50 AutoLock autoLock(cert_lock_); |
51 | 51 |
52 int cert_id; | 52 int cert_id; |
53 | 53 |
54 // Do we already know this cert? | 54 // Do we already know this cert? |
55 ReverseCertMap::iterator cert_iter = cert_to_id_.find(cert); | 55 ReverseCertMap::iterator cert_iter = cert_to_id_.find(cert); |
56 if (cert_iter == cert_to_id_.end()) { | 56 if (cert_iter == cert_to_id_.end()) { |
57 cert_id = next_cert_id_++; | 57 cert_id = next_cert_id_++; |
| 58 // We use 0 as an invalid cert_id value. In the unlikely event that |
| 59 // next_cert_id_ wraps around, we reset it to 1. |
| 60 if (next_cert_id_ == 0) |
| 61 next_cert_id_ = 1; |
58 cert->AddRef(); | 62 cert->AddRef(); |
59 id_to_cert_[cert_id] = cert; | 63 id_to_cert_[cert_id] = cert; |
60 cert_to_id_[cert] = cert_id; | 64 cert_to_id_[cert] = cert_id; |
61 } else { | 65 } else { |
62 cert_id = cert_iter->second; | 66 cert_id = cert_iter->second; |
63 } | 67 } |
64 | 68 |
65 // Let's update process_id_to_cert_id_. | 69 // Let's update process_id_to_cert_id_. |
66 if (std::find_if(process_id_to_cert_id_.lower_bound(process_id), | 70 if (std::find_if(process_id_to_cert_id_.lower_bound(process_id), |
67 process_id_to_cert_id_.upper_bound(process_id), | 71 process_id_to_cert_id_.upper_bound(process_id), |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 138 |
135 void CertStore::Observe(NotificationType type, | 139 void CertStore::Observe(NotificationType type, |
136 const NotificationSource& source, | 140 const NotificationSource& source, |
137 const NotificationDetails& details) { | 141 const NotificationDetails& details) { |
138 DCHECK(type == NotificationType::RENDERER_PROCESS_TERMINATED || | 142 DCHECK(type == NotificationType::RENDERER_PROCESS_TERMINATED || |
139 type == NotificationType::RENDERER_PROCESS_CLOSED); | 143 type == NotificationType::RENDERER_PROCESS_CLOSED); |
140 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr(); | 144 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr(); |
141 DCHECK(rph); | 145 DCHECK(rph); |
142 RemoveCertsForRenderProcesHost(rph->id()); | 146 RemoveCertsForRenderProcesHost(rph->id()); |
143 } | 147 } |
OLD | NEW |