Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / certificate_provider / sign_requests.h
blobdf0b078c6755061f7c5be1af2f7d5b8b1941d2c3
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 #ifndef CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_SIGN_REQUESTS_H_
6 #define CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_SIGN_REQUESTS_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/macros.h"
13 #include "net/ssl/ssl_private_key.h"
15 namespace chromeos {
16 namespace certificate_provider {
18 class SignRequests {
19 public:
20 SignRequests();
21 ~SignRequests();
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,
26 const net::SSLPrivateKey::SignCallback& callback);
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
30 // callback that was provided with AddRequest(). |callback| may be a nullptr.
31 bool RemoveRequest(const std::string& extension_id,
32 int request_id,
33 net::SSLPrivateKey::SignCallback* callback);
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);
40 private:
41 // Holds state of all sign requests to a single extension.
42 struct RequestsState {
43 RequestsState();
44 ~RequestsState();
46 // Maps from request id to the SignCallback that must be called with the
47 // signature or error.
48 std::map<int, net::SSLPrivateKey::SignCallback> pending_requests;
50 // The request id that will be used for the next sign request to this
51 // extension.
52 int next_free_id = 0;
55 // Contains the state of all sign requests per extension.
56 std::map<std::string, RequestsState> extension_to_requests_;
58 DISALLOW_COPY_AND_ASSIGN(SignRequests);
61 } // namespace certificate_provider
62 } // namespace chromeos
64 #endif // CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_SIGN_REQUESTS_H_