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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/certificate_provider/sign_requests.h"
7 #include "base/callback.h"
10 namespace certificate_provider
{
12 SignRequests::RequestsState::RequestsState() {}
14 SignRequests::RequestsState::~RequestsState() {}
16 SignRequests::SignRequests() {}
18 SignRequests::~SignRequests() {}
20 int SignRequests::AddRequest(const std::string
& extension_id
,
21 const net::SSLPrivateKey::SignCallback
& callback
) {
22 RequestsState
& state
= extension_to_requests_
[extension_id
];
23 const int request_id
= state
.next_free_id
++;
24 state
.pending_requests
[request_id
] = callback
;
28 bool SignRequests::RemoveRequest(const std::string
& extension_id
,
30 net::SSLPrivateKey::SignCallback
* callback
) {
31 RequestsState
& state
= extension_to_requests_
[extension_id
];
32 std::map
<int, net::SSLPrivateKey::SignCallback
>& pending
=
33 state
.pending_requests
;
34 const auto it
= pending
.find(request_id
);
35 if (it
== pending
.end())
39 *callback
= it
->second
;
44 std::vector
<net::SSLPrivateKey::SignCallback
> SignRequests::RemoveAllRequests(
45 const std::string
& extension_id
) {
46 std::vector
<net::SSLPrivateKey::SignCallback
> callbacks
;
47 for (const auto& entry
:
48 extension_to_requests_
[extension_id
].pending_requests
) {
49 callbacks
.push_back(entry
.second
);
51 extension_to_requests_
.erase(extension_id
);
55 } // namespace certificate_provider
56 } // namespace chromeos