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/sign_requests.h" | 5 #include "chrome/browser/chromeos/certificate_provider/sign_requests.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/rand_util.h" | |
8 | 9 |
9 namespace chromeos { | 10 namespace chromeos { |
10 namespace certificate_provider { | 11 namespace certificate_provider { |
11 | 12 |
12 SignRequests::RequestsState::RequestsState() {} | 13 SignRequests::RequestsState::RequestsState() {} |
13 | 14 |
14 SignRequests::RequestsState::RequestsState(const RequestsState& other) = | 15 SignRequests::RequestsState::RequestsState(const RequestsState& other) = |
15 default; | 16 default; |
16 | 17 |
17 SignRequests::RequestsState::~RequestsState() {} | 18 SignRequests::RequestsState::~RequestsState() {} |
18 | 19 |
19 SignRequests::SignRequests() {} | 20 SignRequests::SignRequests() {} |
20 | 21 |
21 SignRequests::~SignRequests() {} | 22 SignRequests::~SignRequests() {} |
22 | 23 |
23 int SignRequests::AddRequest(const std::string& extension_id, | 24 int SignRequests::AddRequest(const std::string& extension_id, |
24 const net::SSLPrivateKey::SignCallback& callback) { | 25 const net::SSLPrivateKey::SignCallback& callback) { |
25 RequestsState& state = extension_to_requests_[extension_id]; | 26 RequestsState& state = extension_to_requests_[extension_id]; |
26 const int request_id = state.next_free_id++; | 27 // Generate a random request id so that extensions using |
emaxx
2016/09/19 14:01:42
Is this comment accurate?
My understanding of the
igorcov
2016/09/19 15:42:35
I've changed this to original code because now as
| |
28 // chrome.certificateProvider can not guess another extension's request id. | |
29 int request_id = base::RandInt(0, INT_MAX); | |
30 while (state.pending_requests.find(request_id) != | |
emaxx
2016/09/19 14:01:42
nit: Do-while loop would be a bit more natural (yo
igorcov
2016/09/19 15:42:35
Acknowledged.
| |
31 state.pending_requests.end()) { | |
32 request_id = base::RandInt(0, INT_MAX); | |
33 } | |
27 state.pending_requests[request_id] = callback; | 34 state.pending_requests[request_id] = callback; |
28 return request_id; | 35 return request_id; |
29 } | 36 } |
30 | 37 |
31 bool SignRequests::RemoveRequest(const std::string& extension_id, | 38 bool SignRequests::RemoveRequest(const std::string& extension_id, |
32 int request_id, | 39 int request_id, |
33 net::SSLPrivateKey::SignCallback* callback) { | 40 net::SSLPrivateKey::SignCallback* callback) { |
34 RequestsState& state = extension_to_requests_[extension_id]; | 41 RequestsState& state = extension_to_requests_[extension_id]; |
35 std::map<int, net::SSLPrivateKey::SignCallback>& pending = | 42 std::map<int, net::SSLPrivateKey::SignCallback>& pending = |
36 state.pending_requests; | 43 state.pending_requests; |
(...skipping 13 matching lines...) Expand all Loading... | |
50 for (const auto& entry : | 57 for (const auto& entry : |
51 extension_to_requests_[extension_id].pending_requests) { | 58 extension_to_requests_[extension_id].pending_requests) { |
52 callbacks.push_back(entry.second); | 59 callbacks.push_back(entry.second); |
53 } | 60 } |
54 extension_to_requests_.erase(extension_id); | 61 extension_to_requests_.erase(extension_id); |
55 return callbacks; | 62 return callbacks; |
56 } | 63 } |
57 | 64 |
58 } // namespace certificate_provider | 65 } // namespace certificate_provider |
59 } // namespace chromeos | 66 } // namespace chromeos |
OLD | NEW |