| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/certificate_provider/certificate_requests.h" | 5 #include "chrome/browser/chromeos/certificate_provider/certificate_requests.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 base::Timer timeout; | 32 base::Timer timeout; |
| 33 | 33 |
| 34 // Extensions that this request is still waiting for. | 34 // Extensions that this request is still waiting for. |
| 35 std::set<std::string> pending_extensions; | 35 std::set<std::string> pending_extensions; |
| 36 | 36 |
| 37 // For every extension that replied to this request, there is one entry from | 37 // For every extension that replied to this request, there is one entry from |
| 38 // extension id to the reported certificates. | 38 // extension id to the reported certificates. |
| 39 std::map<std::string, CertificateInfoList> extension_to_certificates; | 39 std::map<std::string, CertificateInfoList> extension_to_certificates; |
| 40 | 40 |
| 41 // The callback that must be run with the final list of certificates. | 41 // The callback that must be run with the final list of certificates. |
| 42 base::Callback<void(const net::CertificateList&)> callback; | 42 base::Callback<void(net::ClientCertIdentityList)> callback; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 CertificateRequests::CertificateRequests() {} | 45 CertificateRequests::CertificateRequests() {} |
| 46 | 46 |
| 47 CertificateRequests::~CertificateRequests() {} | 47 CertificateRequests::~CertificateRequests() {} |
| 48 | 48 |
| 49 int CertificateRequests::AddRequest( | 49 int CertificateRequests::AddRequest( |
| 50 const std::vector<std::string>& extension_ids, | 50 const std::vector<std::string>& extension_ids, |
| 51 const base::Callback<void(const net::CertificateList&)>& callback, | 51 const base::Callback<void(net::ClientCertIdentityList)>& callback, |
| 52 const base::Callback<void(int)>& timeout_callback) { | 52 const base::Callback<void(int)>& timeout_callback) { |
| 53 std::unique_ptr<CertificateRequestState> state(new CertificateRequestState); | 53 std::unique_ptr<CertificateRequestState> state(new CertificateRequestState); |
| 54 state->callback = callback; | 54 state->callback = callback; |
| 55 state->pending_extensions.insert(extension_ids.begin(), extension_ids.end()); | 55 state->pending_extensions.insert(extension_ids.begin(), extension_ids.end()); |
| 56 | 56 |
| 57 const int request_id = next_free_request_id_++; | 57 const int request_id = next_free_request_id_++; |
| 58 state->timeout.Start( | 58 state->timeout.Start( |
| 59 FROM_HERE, base::TimeDelta::FromMinutes(kGetCertificatesTimeoutInMinutes), | 59 FROM_HERE, base::TimeDelta::FromMinutes(kGetCertificatesTimeoutInMinutes), |
| 60 base::Bind(timeout_callback, request_id)); | 60 base::Bind(timeout_callback, request_id)); |
| 61 | 61 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 80 return false; | 80 return false; |
| 81 | 81 |
| 82 state.extension_to_certificates[extension_id] = certificate_infos; | 82 state.extension_to_certificates[extension_id] = certificate_infos; |
| 83 *completed = state.pending_extensions.empty(); | 83 *completed = state.pending_extensions.empty(); |
| 84 return true; | 84 return true; |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool CertificateRequests::RemoveRequest( | 87 bool CertificateRequests::RemoveRequest( |
| 88 int request_id, | 88 int request_id, |
| 89 std::map<std::string, CertificateInfoList>* certificates, | 89 std::map<std::string, CertificateInfoList>* certificates, |
| 90 base::Callback<void(const net::CertificateList&)>* callback) { | 90 base::Callback<void(net::ClientCertIdentityList)>* callback) { |
| 91 const auto it = requests_.find(request_id); | 91 const auto it = requests_.find(request_id); |
| 92 if (it == requests_.end()) | 92 if (it == requests_.end()) |
| 93 return false; | 93 return false; |
| 94 | 94 |
| 95 CertificateRequestState& state = *it->second; | 95 CertificateRequestState& state = *it->second; |
| 96 *certificates = state.extension_to_certificates; | 96 *certificates = state.extension_to_certificates; |
| 97 *callback = state.callback; | 97 *callback = state.callback; |
| 98 requests_.erase(it); | 98 requests_.erase(it); |
| 99 DVLOG(2) << "Completed certificate request " << request_id; | 99 DVLOG(2) << "Completed certificate request " << request_id; |
| 100 return true; | 100 return true; |
| 101 } | 101 } |
| 102 | 102 |
| 103 std::vector<int> CertificateRequests::DropExtension( | 103 std::vector<int> CertificateRequests::DropExtension( |
| 104 const std::string& extension_id) { | 104 const std::string& extension_id) { |
| 105 std::vector<int> completed_requests; | 105 std::vector<int> completed_requests; |
| 106 for (const auto& entry : requests_) { | 106 for (const auto& entry : requests_) { |
| 107 DVLOG(2) << "Remove extension " << extension_id | 107 DVLOG(2) << "Remove extension " << extension_id |
| 108 << " from certificate request " << entry.first; | 108 << " from certificate request " << entry.first; |
| 109 | 109 |
| 110 CertificateRequestState& state = *entry.second.get(); | 110 CertificateRequestState& state = *entry.second.get(); |
| 111 state.pending_extensions.erase(extension_id); | 111 state.pending_extensions.erase(extension_id); |
| 112 if (state.pending_extensions.empty()) | 112 if (state.pending_extensions.empty()) |
| 113 completed_requests.push_back(entry.first); | 113 completed_requests.push_back(entry.first); |
| 114 } | 114 } |
| 115 return completed_requests; | 115 return completed_requests; |
| 116 } | 116 } |
| 117 | 117 |
| 118 } // namespace certificate_provider | 118 } // namespace certificate_provider |
| 119 } // namespace chromeos | 119 } // namespace chromeos |
| OLD | NEW |