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