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

Side by Side Diff: chrome/browser/chromeos/certificate_provider/sign_requests.cc

Issue 2094333002: Implementation for chrome.certificateProvider.requestPin/stopPinRequest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed review comments Created 4 years, 3 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
OLDNEW
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];
stevenjb 2016/09/12 21:16:39 Add comment, e.g.: // Generate a random request id
igorcov 2016/09/13 14:19:32 Done.
26 const int request_id = state.next_free_id++; 27 int request_id = base::RandInt(0, INT_MAX);
28 while (state.pending_requests.find(request_id) !=
29 state.pending_requests.end()) {
30 request_id = base::RandInt(0, INT_MAX);
31 }
27 state.pending_requests[request_id] = callback; 32 state.pending_requests[request_id] = callback;
28 return request_id; 33 return request_id;
29 } 34 }
30 35
31 bool SignRequests::RemoveRequest(const std::string& extension_id, 36 bool SignRequests::RemoveRequest(const std::string& extension_id,
32 int request_id, 37 int request_id,
33 net::SSLPrivateKey::SignCallback* callback) { 38 net::SSLPrivateKey::SignCallback* callback) {
34 RequestsState& state = extension_to_requests_[extension_id]; 39 RequestsState& state = extension_to_requests_[extension_id];
35 std::map<int, net::SSLPrivateKey::SignCallback>& pending = 40 std::map<int, net::SSLPrivateKey::SignCallback>& pending =
36 state.pending_requests; 41 state.pending_requests;
(...skipping 13 matching lines...) Expand all
50 for (const auto& entry : 55 for (const auto& entry :
51 extension_to_requests_[extension_id].pending_requests) { 56 extension_to_requests_[extension_id].pending_requests) {
52 callbacks.push_back(entry.second); 57 callbacks.push_back(entry.second);
53 } 58 }
54 extension_to_requests_.erase(extension_id); 59 extension_to_requests_.erase(extension_id);
55 return callbacks; 60 return callbacks;
56 } 61 }
57 62
58 } // namespace certificate_provider 63 } // namespace certificate_provider
59 } // namespace chromeos 64 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698