blob: d27884b94ca91a38187b0a0a7ed715fc9085953a [file] [log] [blame]
pneubeck7ab2635c2015-09-04 14:12:081// 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.
4
5#ifndef CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_SIGN_REQUESTS_H_
6#define CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_SIGN_REQUESTS_H_
7
8#include <map>
9#include <string>
10#include <vector>
11
12#include "base/macros.h"
13#include "net/ssl/ssl_private_key.h"
14
15namespace chromeos {
16namespace certificate_provider {
17
18class SignRequests {
19 public:
20 SignRequests();
21 ~SignRequests();
22
23 // Returns the id of the new request. The returned request id is specific to
24 // the given extension.
25 int AddRequest(const std::string& extension_id,
David Benjamin8f2d2c12018-02-27 00:08:2626 net::SSLPrivateKey::SignCallback callback);
pneubeck7ab2635c2015-09-04 14:12:0827
28 // Returns false if no request with the given id for |extension_id|
29 // could be found. Otherwise removes the request and sets |callback| to the
David Benjamin8f2d2c12018-02-27 00:08:2630 // callback that was provided with AddRequest().
pneubeck7ab2635c2015-09-04 14:12:0831 bool RemoveRequest(const std::string& extension_id,
32 int request_id,
33 net::SSLPrivateKey::SignCallback* callback);
34
35 // Remove all pending requests for this extension and return their
36 // callbacks.
37 std::vector<net::SSLPrivateKey::SignCallback> RemoveAllRequests(
38 const std::string& extension_id);
39
40 private:
41 // Holds state of all sign requests to a single extension.
42 struct RequestsState {
43 RequestsState();
David Benjamin8f2d2c12018-02-27 00:08:2644 RequestsState(RequestsState&& other);
pneubeck7ab2635c2015-09-04 14:12:0845 ~RequestsState();
46
47 // Maps from request id to the SignCallback that must be called with the
48 // signature or error.
49 std::map<int, net::SSLPrivateKey::SignCallback> pending_requests;
50
51 // The request id that will be used for the next sign request to this
52 // extension.
53 int next_free_id = 0;
54 };
55
56 // Contains the state of all sign requests per extension.
57 std::map<std::string, RequestsState> extension_to_requests_;
58
59 DISALLOW_COPY_AND_ASSIGN(SignRequests);
60};
61
62} // namespace certificate_provider
63} // namespace chromeos
64
65#endif // CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_SIGN_REQUESTS_H_