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 #ifndef NET_CERT_NSS_CERT_DATABASE_H_ | 5 #ifndef NET_CERT_NSS_CERT_DATABASE_H_ |
6 #define NET_CERT_NSS_CERT_DATABASE_H_ | 6 #define NET_CERT_NSS_CERT_DATABASE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
19 #include "crypto/scoped_nss_types.h" | 19 #include "crypto/scoped_nss_types.h" |
20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
21 #include "net/base/net_export.h" | 21 #include "net/base/net_export.h" |
22 #include "net/cert/cert_type.h" | 22 #include "net/cert/cert_type.h" |
23 #include "net/cert/x509_certificate.h" | 23 #include "net/cert/x509_certificate.h" |
24 | 24 |
25 namespace base { | 25 namespace base { |
26 template <class ObserverType> | 26 template <class ObserverType> |
27 class ObserverListThreadSafe; | 27 class ObserverListThreadSafe; |
| 28 class TaskRunner; |
28 } | 29 } |
29 | 30 |
30 namespace net { | 31 namespace net { |
31 | 32 |
32 class CryptoModule; | 33 class CryptoModule; |
33 typedef std::vector<scoped_refptr<CryptoModule> > CryptoModuleList; | 34 typedef std::vector<scoped_refptr<CryptoModule> > CryptoModuleList; |
34 | 35 |
35 // Provides functions to manipulate the NSS certificate stores. | 36 // Provides functions to manipulate the NSS certificate stores. |
36 // Forwards notifications about certificate changes to the global CertDatabase | 37 // Forwards notifications about certificate changes to the global CertDatabase |
37 // singleton. | 38 // singleton. |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 // thread. Never calls |callback| synchronously. | 229 // thread. Never calls |callback| synchronously. |
229 void DeleteCertAndKeyAsync(const scoped_refptr<X509Certificate>& cert, | 230 void DeleteCertAndKeyAsync(const scoped_refptr<X509Certificate>& cert, |
230 const DeleteCertCallback& callback); | 231 const DeleteCertCallback& callback); |
231 | 232 |
232 // Check whether cert is stored in a readonly slot. | 233 // Check whether cert is stored in a readonly slot. |
233 bool IsReadOnly(const X509Certificate* cert) const; | 234 bool IsReadOnly(const X509Certificate* cert) const; |
234 | 235 |
235 // Check whether cert is stored in a hardware slot. | 236 // Check whether cert is stored in a hardware slot. |
236 bool IsHardwareBacked(const X509Certificate* cert) const; | 237 bool IsHardwareBacked(const X509Certificate* cert) const; |
237 | 238 |
| 239 // Overrides task runner that's used for running slow tasks. |
| 240 void SetSlowTaskRunnerForTest( |
| 241 const scoped_refptr<base::TaskRunner>& task_runner); |
| 242 |
238 protected: | 243 protected: |
239 // Certificate listing implementation used by |ListCerts*| and | 244 // Certificate listing implementation used by |ListCerts*| and |
240 // |ListCertsSync|. Static so it may safely be used on the worker thread. | 245 // |ListCertsSync|. Static so it may safely be used on the worker thread. |
241 // If |slot| is NULL, obtains the certs of all slots, otherwise only of | 246 // If |slot| is NULL, obtains the certs of all slots, otherwise only of |
242 // |slot|. | 247 // |slot|. |
243 static void ListCertsImpl(crypto::ScopedPK11Slot slot, | 248 static void ListCertsImpl(crypto::ScopedPK11Slot slot, |
244 CertificateList* certs); | 249 CertificateList* certs); |
245 | 250 |
| 251 // Gets task runner that should be used for slow tasks like certificate |
| 252 // listing. Defaults to a base::WorkerPool runner, but may be overriden |
| 253 // in tests (see SetSlowTaskRunnerForTest). |
| 254 scoped_refptr<base::TaskRunner> GetSlowTaskRunner() const; |
| 255 |
246 protected: | 256 protected: |
247 // Broadcasts notifications to all registered observers. | 257 // Broadcasts notifications to all registered observers. |
248 void NotifyObserversCertDBChanged(); | 258 void NotifyObserversCertDBChanged(); |
249 | 259 |
250 private: | 260 private: |
251 // Registers |observer| to receive notifications of certificate changes. The | 261 // Registers |observer| to receive notifications of certificate changes. The |
252 // thread on which this is called is the thread on which |observer| will be | 262 // thread on which this is called is the thread on which |observer| will be |
253 // called back with notifications. | 263 // called back with notifications. |
254 // NOTE: Observers registered here will only receive notifications generated | 264 // NOTE: Observers registered here will only receive notifications generated |
255 // directly through the NSSCertDatabase, but not those from the CertDatabase. | 265 // directly through the NSSCertDatabase, but not those from the CertDatabase. |
(...skipping 12 matching lines...) Expand all Loading... |
268 // Certificate removal implementation used by |DeleteCertAndKey*|. Static so | 278 // Certificate removal implementation used by |DeleteCertAndKey*|. Static so |
269 // it may safely be used on the worker thread. | 279 // it may safely be used on the worker thread. |
270 static bool DeleteCertAndKeyImpl(scoped_refptr<X509Certificate> cert); | 280 static bool DeleteCertAndKeyImpl(scoped_refptr<X509Certificate> cert); |
271 | 281 |
272 crypto::ScopedPK11Slot public_slot_; | 282 crypto::ScopedPK11Slot public_slot_; |
273 crypto::ScopedPK11Slot private_slot_; | 283 crypto::ScopedPK11Slot private_slot_; |
274 | 284 |
275 // A helper observer that forwards events from this database to CertDatabase. | 285 // A helper observer that forwards events from this database to CertDatabase. |
276 std::unique_ptr<Observer> cert_notification_forwarder_; | 286 std::unique_ptr<Observer> cert_notification_forwarder_; |
277 | 287 |
| 288 // Task runner that should be used in tests if set. |
| 289 scoped_refptr<base::TaskRunner> slow_task_runner_for_test_; |
| 290 |
278 const scoped_refptr<base::ObserverListThreadSafe<Observer>> observer_list_; | 291 const scoped_refptr<base::ObserverListThreadSafe<Observer>> observer_list_; |
279 | 292 |
280 base::WeakPtrFactory<NSSCertDatabase> weak_factory_; | 293 base::WeakPtrFactory<NSSCertDatabase> weak_factory_; |
281 | 294 |
282 DISALLOW_COPY_AND_ASSIGN(NSSCertDatabase); | 295 DISALLOW_COPY_AND_ASSIGN(NSSCertDatabase); |
283 }; | 296 }; |
284 | 297 |
285 } // namespace net | 298 } // namespace net |
286 | 299 |
287 #endif // NET_CERT_NSS_CERT_DATABASE_H_ | 300 #endif // NET_CERT_NSS_CERT_DATABASE_H_ |
OLD | NEW |