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

Side by Side Diff: net/cert/nss_cert_database.h

Issue 144423007: Make NSSCertDatabase::ListCerts work async on a worker thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 10 months 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
« no previous file with comments | « chromeos/network/onc/onc_certificate_importer_impl.cc ('k') | net/cert/nss_cert_database.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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 <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback_forward.h"
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
13 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
14 #include "crypto/scoped_nss_types.h" 15 #include "crypto/scoped_nss_types.h"
15 #include "net/base/net_export.h" 16 #include "net/base/net_export.h"
16 #include "net/cert/cert_type.h" 17 #include "net/cert/cert_type.h"
17 #include "net/cert/x509_certificate.h" 18 #include "net/cert/x509_certificate.h"
18 19
19 namespace base { 20 namespace base {
20 template <typename T> struct DefaultLazyInstanceTraits; 21 template <typename T> struct DefaultLazyInstanceTraits;
22 class TaskRunner;
21 } 23 }
22 template <class ObserverType> class ObserverListThreadSafe; 24 template <class ObserverType> class ObserverListThreadSafe;
23 25
24 namespace net { 26 namespace net {
25 27
26 class CryptoModule; 28 class CryptoModule;
27 typedef std::vector<scoped_refptr<CryptoModule> > CryptoModuleList; 29 typedef std::vector<scoped_refptr<CryptoModule> > CryptoModuleList;
28 30
29 // Provides functions to manipulate the NSS certificate stores. 31 // Provides functions to manipulate the NSS certificate stores.
30 class NET_EXPORT NSSCertDatabase { 32 class NET_EXPORT NSSCertDatabase {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 enum { 86 enum {
85 TRUST_DEFAULT = 0, 87 TRUST_DEFAULT = 0,
86 TRUSTED_SSL = 1 << 0, 88 TRUSTED_SSL = 1 << 0,
87 TRUSTED_EMAIL = 1 << 1, 89 TRUSTED_EMAIL = 1 << 1,
88 TRUSTED_OBJ_SIGN = 1 << 2, 90 TRUSTED_OBJ_SIGN = 1 << 2,
89 DISTRUSTED_SSL = 1 << 3, 91 DISTRUSTED_SSL = 1 << 3,
90 DISTRUSTED_EMAIL = 1 << 4, 92 DISTRUSTED_EMAIL = 1 << 4,
91 DISTRUSTED_OBJ_SIGN = 1 << 5, 93 DISTRUSTED_OBJ_SIGN = 1 << 5,
92 }; 94 };
93 95
96 typedef base::Callback<void(scoped_ptr<CertificateList> certs)>
97 ListCertsCallback;
98
94 // DEPRECATED: See http://crbug.com/329735. 99 // DEPRECATED: See http://crbug.com/329735.
95 static NSSCertDatabase* GetInstance(); 100 static NSSCertDatabase* GetInstance();
96 101
97 // Get a list of unique certificates in the certificate database (one 102 // Get a list of unique certificates in the certificate database (one
98 // instance of all certificates). 103 // instance of all certificates).
99 virtual void ListCerts(CertificateList* certs); 104 // DEPRECATED by |ListCerts|. See http://crbug.com/340460.
105 virtual void ListCertsSync(CertificateList* certs);
106
107 // Asynchronously get a list of unique certificates in the certificate
108 // database (one instance of all certificates). Note that the callback may be
109 // run even after the database is deleted.
110 virtual void ListCerts(const ListCertsCallback& callback);
100 111
101 // Get the default slot for public key data. 112 // Get the default slot for public key data.
102 virtual crypto::ScopedPK11Slot GetPublicSlot() const; 113 virtual crypto::ScopedPK11Slot GetPublicSlot() const;
103 114
104 // Get the default slot for private key or mixed private/public key data. 115 // Get the default slot for private key or mixed private/public key data.
105 virtual crypto::ScopedPK11Slot GetPrivateSlot() const; 116 virtual crypto::ScopedPK11Slot GetPrivateSlot() const;
106 117
107 // Get the default module for public key data. 118 // Get the default module for public key data.
108 // The returned pointer must be stored in a scoped_refptr<CryptoModule>. 119 // The returned pointer must be stored in a scoped_refptr<CryptoModule>.
109 // DEPRECATED: use GetPublicSlot instead. 120 // DEPRECATED: use GetPublicSlot instead.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 // NOTE: CertDatabase::AddObserver should be preferred. Observers registered 213 // NOTE: CertDatabase::AddObserver should be preferred. Observers registered
203 // here will only recieve notifications generated directly through the 214 // here will only recieve notifications generated directly through the
204 // NSSCertDatabase, but not those from the CertDatabase. The CertDatabase 215 // NSSCertDatabase, but not those from the CertDatabase. The CertDatabase
205 // observers will recieve both. 216 // observers will recieve both.
206 void AddObserver(Observer* observer); 217 void AddObserver(Observer* observer);
207 218
208 // Unregisters |observer| from receiving notifications. This must be called 219 // Unregisters |observer| from receiving notifications. This must be called
209 // on the same thread on which AddObserver() was called. 220 // on the same thread on which AddObserver() was called.
210 void RemoveObserver(Observer* observer); 221 void RemoveObserver(Observer* observer);
211 222
223 // Overrides task runner that's used for running slow tasks.
224 void SetSlowTaskRunnerForTest(
225 const scoped_refptr<base::TaskRunner>& task_runner);
226
212 protected: 227 protected:
213 NSSCertDatabase(); 228 NSSCertDatabase();
214 virtual ~NSSCertDatabase(); 229 virtual ~NSSCertDatabase();
215 230
231 // Certificate listing implementation used by |ListCerts| and |ListCertsSync|.
232 // Static so it may safely be used on the worker thread.
233 static void ListCertsImpl(CertificateList* certs);
234
235 // Gets task runner that should be used for slow tasks like certificate
236 // listing. Defaults to a base::WorkerPool runner, but may be overriden
237 // in tests (see SetSlowTaskRunnerForTest).
238 scoped_refptr<base::TaskRunner> GetSlowTaskRunner() const;
239
216 private: 240 private:
217 friend struct base::DefaultLazyInstanceTraits<NSSCertDatabase>; 241 friend struct base::DefaultLazyInstanceTraits<NSSCertDatabase>;
218 242
219 // Broadcasts notifications to all registered observers. 243 // Broadcasts notifications to all registered observers.
220 void NotifyObserversOfCertAdded(const X509Certificate* cert); 244 void NotifyObserversOfCertAdded(const X509Certificate* cert);
221 void NotifyObserversOfCertRemoved(const X509Certificate* cert); 245 void NotifyObserversOfCertRemoved(const X509Certificate* cert);
222 void NotifyObserversOfCACertChanged(const X509Certificate* cert); 246 void NotifyObserversOfCACertChanged(const X509Certificate* cert);
223 247
248 // Task runner that should be used in tests if set.
249 scoped_refptr<base::TaskRunner> slow_task_runner_for_test_;
250
224 const scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; 251 const scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_;
225 252
226 DISALLOW_COPY_AND_ASSIGN(NSSCertDatabase); 253 DISALLOW_COPY_AND_ASSIGN(NSSCertDatabase);
227 }; 254 };
228 255
229 } // namespace net 256 } // namespace net
230 257
231 #endif // NET_CERT_NSS_CERT_DATABASE_H_ 258 #endif // NET_CERT_NSS_CERT_DATABASE_H_
OLDNEW
« no previous file with comments | « chromeos/network/onc/onc_certificate_importer_impl.cc ('k') | net/cert/nss_cert_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698