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

Side by Side Diff: net/cert/nss_cert_database_chromeos.cc

Issue 144423007: Make NSSCertDatabase::ListCerts work async on a worker thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added bug # 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "net/cert/nss_cert_database_chromeos.h" 5 #include "net/cert/nss_cert_database_chromeos.h"
6 6
7 #include <cert.h> 7 #include <cert.h>
8 #include <pk11pub.h> 8 #include <pk11pub.h>
9 9
10 #include <algorithm>
11
12 #include "base/bind.h"
13 #include "base/callback.h"
14 #include "base/location.h"
15 #include "base/task_runner.h"
10 #include "net/base/crypto_module.h" 16 #include "net/base/crypto_module.h"
11 #include "net/cert/x509_certificate.h" 17 #include "net/cert/x509_certificate.h"
12 18
13 namespace net { 19 namespace net {
14 20
15 NSSCertDatabaseChromeOS::NSSCertDatabaseChromeOS( 21 NSSCertDatabaseChromeOS::NSSCertDatabaseChromeOS(
16 crypto::ScopedPK11Slot public_slot, 22 crypto::ScopedPK11Slot public_slot,
17 crypto::ScopedPK11Slot private_slot) 23 crypto::ScopedPK11Slot private_slot)
18 : public_slot_(public_slot.Pass()), 24 : public_slot_(public_slot.Pass()),
19 private_slot_(private_slot.Pass()) { 25 private_slot_(private_slot.Pass()) {
20 profile_filter_.Init(GetPublicSlot(), GetPrivateSlot()); 26 profile_filter_.Init(GetPublicSlot(), GetPrivateSlot());
21 } 27 }
22 28
23 NSSCertDatabaseChromeOS::~NSSCertDatabaseChromeOS() {} 29 NSSCertDatabaseChromeOS::~NSSCertDatabaseChromeOS() {}
24 30
25 void NSSCertDatabaseChromeOS::ListCerts(CertificateList* certs) { 31 void NSSCertDatabaseChromeOS::ListCertsSync(CertificateList* certs) {
26 NSSCertDatabase::ListCerts(certs); 32 ListCertsImpl(profile_filter_, certs);
33 }
27 34
28 size_t pre_size = certs->size(); 35 void NSSCertDatabaseChromeOS::ListCerts(
29 certs->erase(std::remove_if( 36 const base::Callback<void(scoped_ptr<CertificateList> certs)>& callback) {
30 certs->begin(), 37 scoped_ptr<CertificateList> certs(new CertificateList());
31 certs->end(), 38 CertificateList* raw_certs = certs.get();
stevenjb 2014/02/04 22:28:42 nit: unnecessary.
32 NSSProfileFilterChromeOS::CertNotAllowedForProfilePredicate( 39
33 profile_filter_)), 40 GetSlowTaskRunner()->PostTaskAndReply(
34 certs->end()); 41 FROM_HERE,
35 DVLOG(1) << "filtered " << pre_size - certs->size() << " of " << pre_size 42 base::Bind(&NSSCertDatabaseChromeOS::ListCertsImpl,
36 << " certs"; 43 profile_filter_,
44 base::Unretained(raw_certs)),
45 base::Bind(callback, base::Passed(&certs)));
37 } 46 }
38 47
39 crypto::ScopedPK11Slot NSSCertDatabaseChromeOS::GetPublicSlot() const { 48 crypto::ScopedPK11Slot NSSCertDatabaseChromeOS::GetPublicSlot() const {
40 return crypto::ScopedPK11Slot( 49 return crypto::ScopedPK11Slot(
41 public_slot_ ? PK11_ReferenceSlot(public_slot_.get()) : NULL); 50 public_slot_ ? PK11_ReferenceSlot(public_slot_.get()) : NULL);
42 } 51 }
43 52
44 crypto::ScopedPK11Slot NSSCertDatabaseChromeOS::GetPrivateSlot() const { 53 crypto::ScopedPK11Slot NSSCertDatabaseChromeOS::GetPrivateSlot() const {
45 return crypto::ScopedPK11Slot( 54 return crypto::ScopedPK11Slot(
46 private_slot_ ? PK11_ReferenceSlot(private_slot_.get()) : NULL); 55 private_slot_ ? PK11_ReferenceSlot(private_slot_.get()) : NULL);
47 } 56 }
48 57
49 void NSSCertDatabaseChromeOS::ListModules(CryptoModuleList* modules, 58 void NSSCertDatabaseChromeOS::ListModules(CryptoModuleList* modules,
50 bool need_rw) const { 59 bool need_rw) const {
51 NSSCertDatabase::ListModules(modules, need_rw); 60 NSSCertDatabase::ListModules(modules, need_rw);
52 61
53 size_t pre_size = modules->size(); 62 size_t pre_size = modules->size();
54 modules->erase( 63 modules->erase(
55 std::remove_if( 64 std::remove_if(
56 modules->begin(), 65 modules->begin(),
57 modules->end(), 66 modules->end(),
58 NSSProfileFilterChromeOS::ModuleNotAllowedForProfilePredicate( 67 NSSProfileFilterChromeOS::ModuleNotAllowedForProfilePredicate(
59 profile_filter_)), 68 profile_filter_)),
60 modules->end()); 69 modules->end());
61 DVLOG(1) << "filtered " << pre_size - modules->size() << " of " << pre_size 70 DVLOG(1) << "filtered " << pre_size - modules->size() << " of " << pre_size
62 << " modules"; 71 << " modules";
63 } 72 }
64 73
74 void NSSCertDatabaseChromeOS::ListCertsImpl(
75 const NSSProfileFilterChromeOS& profile_filter,
76 CertificateList* certs) {
77 NSSCertDatabase::ListCertsImpl(certs);
78
79 size_t pre_size = certs->size();
80 certs->erase(std::remove_if(
81 certs->begin(),
82 certs->end(),
83 NSSProfileFilterChromeOS::CertNotAllowedForProfilePredicate(
84 profile_filter)),
85 certs->end());
86 DVLOG(1) << "filtered " << pre_size - certs->size() << " of " << pre_size
87 << " certs";
88 }
89
65 } // namespace net 90 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698