OLD | NEW |
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 "chrome/browser/chromeos/net/client_cert_store_chromeos.h" | 5 #include "chrome/browser/chromeos/net/client_cert_store_chromeos.h" |
6 | 6 |
7 #include <cert.h> | 7 #include <cert.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/threading/worker_pool.h" | 15 #include "base/task_scheduler/post_task.h" |
16 #include "chrome/browser/chromeos/certificate_provider/certificate_provider.h" | 16 #include "chrome/browser/chromeos/certificate_provider/certificate_provider.h" |
17 #include "crypto/nss_crypto_module_delegate.h" | 17 #include "crypto/nss_crypto_module_delegate.h" |
18 #include "net/ssl/ssl_cert_request_info.h" | 18 #include "net/ssl/ssl_cert_request_info.h" |
19 | 19 |
20 namespace chromeos { | 20 namespace chromeos { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 class CertNotAllowedPredicate { | 24 class CertNotAllowedPredicate { |
25 public: | 25 public: |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 const net::SSLCertRequestInfo* request, | 74 const net::SSLCertRequestInfo* request, |
75 net::CertificateList* selected_certs, | 75 net::CertificateList* selected_certs, |
76 const base::Closure& callback, | 76 const base::Closure& callback, |
77 const net::CertificateList& additional_certs) { | 77 const net::CertificateList& additional_certs) { |
78 std::unique_ptr<crypto::CryptoModuleBlockingPasswordDelegate> | 78 std::unique_ptr<crypto::CryptoModuleBlockingPasswordDelegate> |
79 password_delegate; | 79 password_delegate; |
80 if (!password_delegate_factory_.is_null()) { | 80 if (!password_delegate_factory_.is_null()) { |
81 password_delegate.reset( | 81 password_delegate.reset( |
82 password_delegate_factory_.Run(request->host_and_port)); | 82 password_delegate_factory_.Run(request->host_and_port)); |
83 } | 83 } |
84 if (base::WorkerPool::PostTaskAndReply( | 84 base::PostTaskWithTraitsAndReply( |
85 FROM_HERE, | 85 FROM_HERE, |
86 base::Bind(&ClientCertStoreChromeOS::GetAndFilterCertsOnWorkerThread, | 86 base::TaskTraits().WithPriority(base::TaskPriority::BACKGROUND), |
87 base::Unretained(this), base::Passed(&password_delegate), | 87 base::Bind(&ClientCertStoreChromeOS::GetAndFilterCertsOnWorkerThread, |
88 request, additional_certs, selected_certs), | 88 base::Unretained(this), base::Passed(&password_delegate), |
89 callback, true)) { | 89 request, additional_certs, selected_certs), |
90 return; | 90 callback); |
91 } | |
92 // If the task could not be posted, behave as if there were no certificates | |
93 // which requires to clear |selected_certs|. | |
94 selected_certs->clear(); | |
95 callback.Run(); | |
96 } | 91 } |
97 | 92 |
98 void ClientCertStoreChromeOS::GetAndFilterCertsOnWorkerThread( | 93 void ClientCertStoreChromeOS::GetAndFilterCertsOnWorkerThread( |
99 std::unique_ptr<crypto::CryptoModuleBlockingPasswordDelegate> | 94 std::unique_ptr<crypto::CryptoModuleBlockingPasswordDelegate> |
100 password_delegate, | 95 password_delegate, |
101 const net::SSLCertRequestInfo* request, | 96 const net::SSLCertRequestInfo* request, |
102 const net::CertificateList& additional_certs, | 97 const net::CertificateList& additional_certs, |
103 net::CertificateList* selected_certs) { | 98 net::CertificateList* selected_certs) { |
104 net::CertificateList unfiltered_certs; | 99 net::CertificateList unfiltered_certs; |
105 net::ClientCertStoreNSS::GetPlatformCertsOnWorkerThread( | 100 net::ClientCertStoreNSS::GetPlatformCertsOnWorkerThread( |
106 std::move(password_delegate), &unfiltered_certs); | 101 std::move(password_delegate), &unfiltered_certs); |
107 | 102 |
108 unfiltered_certs.erase( | 103 unfiltered_certs.erase( |
109 std::remove_if(unfiltered_certs.begin(), unfiltered_certs.end(), | 104 std::remove_if(unfiltered_certs.begin(), unfiltered_certs.end(), |
110 CertNotAllowedPredicate(cert_filter_.get())), | 105 CertNotAllowedPredicate(cert_filter_.get())), |
111 unfiltered_certs.end()); | 106 unfiltered_certs.end()); |
112 | 107 |
113 unfiltered_certs.insert(unfiltered_certs.end(), additional_certs.begin(), | 108 unfiltered_certs.insert(unfiltered_certs.end(), additional_certs.begin(), |
114 additional_certs.end()); | 109 additional_certs.end()); |
115 | 110 |
116 net::ClientCertStoreNSS::FilterCertsOnWorkerThread(unfiltered_certs, *request, | 111 net::ClientCertStoreNSS::FilterCertsOnWorkerThread(unfiltered_certs, *request, |
117 selected_certs); | 112 selected_certs); |
118 } | 113 } |
119 | 114 |
120 } // namespace chromeos | 115 } // namespace chromeos |
OLD | NEW |