Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / net / cert_net / cert_net_fetcher_impl.h
blobac5cd90afef21483213fa31510156dfcd9853c18
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 NET_CERT_NET_CERT_NET_FETCHER_H_
6 #define NET_CERT_NET_CERT_NET_FETCHER_H_
8 #include <set>
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/threading/thread_checker.h"
13 #include "net/base/net_errors.h"
14 #include "net/base/net_export.h"
15 #include "net/cert/cert_net_fetcher.h"
17 namespace net {
19 class URLRequestContext;
21 // CertNetFetcherImpl is an implementation of CertNetFetcher that uses the
22 // network stack.
24 // For more details refer to the documentation for the interface.
25 class NET_EXPORT CertNetFetcherImpl : public CertNetFetcher {
26 public:
27 // Initializes CertNetFetcherImpl using the specified URLRequestContext for
28 // issuing requests. |context| must remain valid for the entire lifetime of
29 // the CertNetFetcherImpl.
30 explicit CertNetFetcherImpl(URLRequestContext* context);
32 // Deletion implicitly cancels any outstanding requests.
33 ~CertNetFetcherImpl() override;
35 WARN_UNUSED_RESULT scoped_ptr<Request> FetchCaIssuers(
36 const GURL& url,
37 int timeout_milliseconds,
38 int max_response_bytes,
39 const FetchCallback& callback) override;
41 WARN_UNUSED_RESULT scoped_ptr<Request> FetchCrl(
42 const GURL& url,
43 int timeout_milliseconds,
44 int max_response_bytes,
45 const FetchCallback& callback) override;
47 WARN_UNUSED_RESULT scoped_ptr<Request> FetchOcsp(
48 const GURL& url,
49 int timeout_milliseconds,
50 int max_response_bytes,
51 const FetchCallback& callback) override;
53 private:
54 class RequestImpl;
55 class Job;
56 struct JobToRequestParamsComparator;
57 struct RequestParams;
59 struct JobComparator {
60 bool operator()(const Job* job1, const Job* job2) const;
63 // Owns the jobs.
64 using JobSet = std::set<Job*, JobComparator>;
66 // Starts an asynchronous request to fetch the given URL. On completion
67 // |callback| will be invoked.
69 // Completion of the request will never occur synchronously. In other words it
70 // is guaranteed that |callback| will only be invoked once the Fetch*() method
71 // has returned.
72 WARN_UNUSED_RESULT scoped_ptr<Request> Fetch(
73 scoped_ptr<RequestParams> request_params,
74 const FetchCallback& callback);
76 // Finds a job with a matching RequestPararms or returns nullptr if there was
77 // no match.
78 Job* FindJob(const RequestParams& params);
80 // Removes |job| from the in progress jobs and transfers ownership to the
81 // caller.
82 scoped_ptr<Job> RemoveJob(Job* job);
84 // Indicates which Job is currently executing inside of OnJobCompleted().
85 void SetCurrentlyCompletingJob(Job* job);
86 void ClearCurrentlyCompletingJob(Job* job);
87 bool IsCurrentlyCompletingJob(Job* job);
89 // The in-progress jobs. This set does not contain the job which is actively
90 // invoking callbacks (OnJobCompleted). Instead that is tracked by
91 // |currently_completing_job_|.
92 JobSet jobs_;
94 // The Job that is currently executing OnJobCompleted(). There can be at most
95 // one such job. This pointer is not owned.
96 Job* currently_completing_job_;
98 // Not owned. CertNetFetcherImpl must outlive the URLRequestContext.
99 URLRequestContext* context_;
101 base::ThreadChecker thread_checker_;
103 DISALLOW_COPY_AND_ASSIGN(CertNetFetcherImpl);
106 } // namespace net
108 #endif // NET_CERT_NET_CERT_NET_FETCHER_H_