pneubeck | 7ab2635c | 2015-09-04 14:12:08 | [diff] [blame] | 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. |
| 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 | |
| 15 | namespace chromeos { |
| 16 | namespace certificate_provider { |
| 17 | |
| 18 | class 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 Benjamin | 8f2d2c1 | 2018-02-27 00:08:26 | [diff] [blame^] | 26 | net::SSLPrivateKey::SignCallback callback); |
pneubeck | 7ab2635c | 2015-09-04 14:12:08 | [diff] [blame] | 27 | |
| 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 Benjamin | 8f2d2c1 | 2018-02-27 00:08:26 | [diff] [blame^] | 30 | // callback that was provided with AddRequest(). |
pneubeck | 7ab2635c | 2015-09-04 14:12:08 | [diff] [blame] | 31 | 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 Benjamin | 8f2d2c1 | 2018-02-27 00:08:26 | [diff] [blame^] | 44 | RequestsState(RequestsState&& other); |
pneubeck | 7ab2635c | 2015-09-04 14:12:08 | [diff] [blame] | 45 | ~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_ |