Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / certificate_provider / certificate_requests.h
blobaaa8375560479c59c8e866a30217712054edda6e
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_CERTIFICATE_REQUESTS_H_
6 #define CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_CERTIFICATE_REQUESTS_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/callback_forward.h"
13 #include "base/containers/scoped_ptr_map.h"
14 #include "base/macros.h"
15 #include "chrome/browser/chromeos/certificate_provider/certificate_info.h"
16 #include "net/cert/x509_certificate.h"
18 namespace chromeos {
19 namespace certificate_provider {
21 class CertificateRequests {
22 public:
23 CertificateRequests();
24 ~CertificateRequests();
26 // Returns the id of the new request. |callback| will be stored with this
27 // request and be returned by RemoveRequest(). |timeout_callback| will be
28 // called with the request id if this request times out before
29 // SetCertificates() was called for all extensions in |extension_ids|.
30 int AddRequest(
31 const std::vector<std::string>& extension_ids,
32 const base::Callback<void(const net::CertificateList&)>& callback,
33 const base::Callback<void(int)>& timeout_callback);
35 // Returns whether this reply was expected, i.e. the request with |request_id|
36 // was waiting for a reply from this extension. If it was expected, the
37 // certificates are stored and |completed| is set to whether this request has
38 // no more pending replies. Otherwise |completed| will be set to false.
39 bool SetCertificates(const std::string& extension_id,
40 int request_id,
41 const CertificateInfoList& certificate_infos,
42 bool* completed);
44 // If this request is pending, stores the collected certificates in
45 // |certificates|, sets |callback|, drops the request and returns true.
46 // Otherwise returns false.
47 bool RemoveRequest(
48 int request_id,
49 std::map<std::string, CertificateInfoList>* certificates,
50 base::Callback<void(const net::CertificateList&)>* callback);
52 // Removes this extension from all pending requests and returns the ids of
53 // all completed requests.
54 std::vector<int> DropExtension(const std::string& extension_id);
56 private:
57 struct CertificateRequestState;
59 base::ScopedPtrMap<int, scoped_ptr<CertificateRequestState>> requests_;
60 int next_free_request_id_ = 0;
62 DISALLOW_COPY_AND_ASSIGN(CertificateRequests);
65 } // namespace certificate_provider
66 } // namespace chromeos
68 #endif // CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_CERTIFICATE_REQUESTS_H_