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

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: rebase to tot 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 "base/bind.h"
11 #include "base/callback.h"
12 #include "base/location.h"
13 #include "base/task_runner.h"
10 #include "net/base/crypto_module.h" 14 #include "net/base/crypto_module.h"
11 #include "net/cert/x509_certificate.h" 15 #include "net/cert/x509_certificate.h"
12 16
13 namespace net { 17 namespace net {
14 18
15 NSSCertDatabaseChromeOS::NSSCertDatabaseChromeOS( 19 NSSCertDatabaseChromeOS::NSSCertDatabaseChromeOS(
16 crypto::ScopedPK11Slot public_slot, 20 crypto::ScopedPK11Slot public_slot,
17 crypto::ScopedPK11Slot private_slot) 21 crypto::ScopedPK11Slot private_slot)
18 : public_slot_(public_slot.Pass()), 22 : public_slot_(public_slot.Pass()),
19 private_slot_(private_slot.Pass()) { 23 private_slot_(private_slot.Pass()),
20 profile_filter_.Init(GetPublicSlot(), GetPrivateSlot()); 24 profile_filter_(new NSSProfileFilterChromeOS) {
25 profile_filter_->Init(GetPublicSlot(), GetPrivateSlot());
21 } 26 }
22 27
23 NSSCertDatabaseChromeOS::~NSSCertDatabaseChromeOS() {} 28 NSSCertDatabaseChromeOS::~NSSCertDatabaseChromeOS() {}
24 29
25 void NSSCertDatabaseChromeOS::ListCerts(CertificateList* certs) { 30 void NSSCertDatabaseChromeOS::ListCertsSync(CertificateList* certs) {
26 NSSCertDatabase::ListCerts(certs); 31 ListCertsImpl(profile_filter_, certs);
32 }
27 33
28 size_t pre_size = certs->size(); 34 void NSSCertDatabaseChromeOS::ListCerts(
29 certs->erase(std::remove_if( 35 const base::Callback<void(scoped_ptr<CertificateList> certs)>& callback) {
30 certs->begin(), 36 scoped_ptr<CertificateList> certs(new CertificateList());
31 certs->end(), 37 CertificateList* raw_certs = certs.get();
32 NSSProfileFilterChromeOS::CertNotAllowedForProfilePredicate( 38
33 profile_filter_)), 39 GetSlowTaskRunner()->PostTaskAndReply(
34 certs->end()); 40 FROM_HERE,
35 DVLOG(1) << "filtered " << pre_size - certs->size() << " of " << pre_size 41 base::Bind(&NSSCertDatabaseChromeOS::ListCertsImpl,
36 << " certs"; 42 profile_filter_,
43 base::Unretained(raw_certs)),
44 base::Bind(callback, base::Passed(&certs)));
37 } 45 }
38 46
39 crypto::ScopedPK11Slot NSSCertDatabaseChromeOS::GetPublicSlot() const { 47 crypto::ScopedPK11Slot NSSCertDatabaseChromeOS::GetPublicSlot() const {
40 return crypto::ScopedPK11Slot( 48 return crypto::ScopedPK11Slot(
41 public_slot_ ? PK11_ReferenceSlot(public_slot_.get()) : NULL); 49 public_slot_ ? PK11_ReferenceSlot(public_slot_.get()) : NULL);
42 } 50 }
43 51
44 crypto::ScopedPK11Slot NSSCertDatabaseChromeOS::GetPrivateSlot() const { 52 crypto::ScopedPK11Slot NSSCertDatabaseChromeOS::GetPrivateSlot() const {
45 return crypto::ScopedPK11Slot( 53 return crypto::ScopedPK11Slot(
46 private_slot_ ? PK11_ReferenceSlot(private_slot_.get()) : NULL); 54 private_slot_ ? PK11_ReferenceSlot(private_slot_.get()) : NULL);
47 } 55 }
48 56
49 void NSSCertDatabaseChromeOS::ListModules(CryptoModuleList* modules, 57 void NSSCertDatabaseChromeOS::ListModules(CryptoModuleList* modules,
50 bool need_rw) const { 58 bool need_rw) const {
51 NSSCertDatabase::ListModules(modules, need_rw); 59 NSSCertDatabase::ListModules(modules, need_rw);
52 60
53 size_t pre_size = modules->size(); 61 size_t pre_size = modules->size();
54 modules->erase( 62 modules->erase(
55 std::remove_if( 63 std::remove_if(
56 modules->begin(), 64 modules->begin(),
57 modules->end(), 65 modules->end(),
58 NSSProfileFilterChromeOS::ModuleNotAllowedForProfilePredicate( 66 NSSProfileFilterChromeOS::ModuleNotAllowedForProfilePredicate(
59 profile_filter_)), 67 profile_filter_)),
60 modules->end()); 68 modules->end());
61 DVLOG(1) << "filtered " << pre_size - modules->size() << " of " << pre_size 69 DVLOG(1) << "filtered " << pre_size - modules->size() << " of " << pre_size
62 << " modules"; 70 << " modules";
63 } 71 }
64 72
73 void NSSCertDatabaseChromeOS::ListCertsImpl(
74 const scoped_refptr<NSSProfileFilterChromeOS> profile_filter,
75 CertificateList* certs) {
76 NSSCertDatabase::ListCertsImpl(certs);
77
78 size_t pre_size = certs->size();
79 certs->erase(std::remove_if(
80 certs->begin(),
81 certs->end(),
82 NSSProfileFilterChromeOS::CertNotAllowedForProfilePredicate(
83 profile_filter)),
84 certs->end());
85 DVLOG(1) << "filtered " << pre_size - certs->size() << " of " << pre_size
86 << " certs";
87 }
88
65 } // namespace net 89 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698