Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / chromeos / platform_keys / platform_keys.cc
blob40cb72ccc6f3de8c4f1afb7f44aa791a1e140951
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/platform_keys/platform_keys.h"
7 #include <map>
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/location.h"
12 #include "base/threading/worker_pool.h"
13 #include "net/base/hash_value.h"
14 #include "net/cert/x509_certificate.h"
16 namespace chromeos {
18 namespace platform_keys {
20 namespace {
22 void IntersectOnWorkerThread(const net::CertificateList& certs1,
23 const net::CertificateList& certs2,
24 net::CertificateList* intersection) {
25 std::map<net::SHA256HashValue, scoped_refptr<net::X509Certificate>,
26 net::SHA256HashValueLessThan> fingerprints2;
28 // Fill the map with fingerprints of certs from |certs2|.
29 for (const auto& cert2 : certs2) {
30 fingerprints2[net::X509Certificate::CalculateFingerprint256(
31 cert2->os_cert_handle())] = cert2;
34 // Compare each cert from |certs1| with the entries of the map.
35 for (const auto& cert1 : certs1) {
36 const net::SHA256HashValue fingerprint1 =
37 net::X509Certificate::CalculateFingerprint256(cert1->os_cert_handle());
38 const auto it = fingerprints2.find(fingerprint1);
39 if (it == fingerprints2.end())
40 continue;
41 const auto& cert2 = it->second;
42 DCHECK(cert1->Equals(cert2.get()));
43 intersection->push_back(cert1);
47 } // namespace
49 const char kTokenIdUser[] = "user";
50 const char kTokenIdSystem[] = "system";
52 ClientCertificateRequest::ClientCertificateRequest() {
55 ClientCertificateRequest::~ClientCertificateRequest() {
58 void IntersectCertificates(
59 const net::CertificateList& certs1,
60 const net::CertificateList& certs2,
61 const base::Callback<void(scoped_ptr<net::CertificateList>)>& callback) {
62 scoped_ptr<net::CertificateList> intersection(new net::CertificateList);
63 net::CertificateList* const intersection_ptr = intersection.get();
64 if (!base::WorkerPool::PostTaskAndReply(
65 FROM_HERE, base::Bind(&IntersectOnWorkerThread, certs1, certs2,
66 intersection_ptr),
67 base::Bind(callback, base::Passed(&intersection)),
68 false /* task_is_slow */)) {
69 callback.Run(make_scoped_ptr(new net::CertificateList));
73 } // namespace platform_keys
75 } // namespace chromeos