Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 NET_CERT_NET_CERT_NET_FETCHER_H_ | |
| 6 #define NET_CERT_NET_CERT_NET_FETCHER_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/threading/thread_checker.h" | |
| 14 #include "net/base/net_errors.h" | |
| 15 #include "net/base/net_export.h" | |
| 16 #include "net/cert/cert_net_fetcher.h" | |
| 17 | |
| 18 namespace net { | |
| 19 | |
| 20 class URLRequestContext; | |
| 21 | |
| 22 // CertNetFetcherImpl is an implementation of CertNetFetcher that uses the | |
| 23 // network stack. | |
| 24 // | |
| 25 // For more details refer to the documentation for the interface. | |
| 26 class NET_EXPORT CertNetFetcherImpl : public CertNetFetcher { | |
| 27 public: | |
| 28 using FetchCallback = | |
| 29 base::Callback<void(Error, const std::vector<uint8_t>&)>; | |
| 30 | |
| 31 // Initializes CertNetFetcherImpl using the specified URLRequestContext for | |
| 32 // issuing requests. |context| must remain valid for the entire lifetime of | |
| 33 // the CertNetFetcherImpl. | |
| 34 explicit CertNetFetcherImpl(URLRequestContext* context); | |
| 35 | |
| 36 // Deletion implicitly cancels any outstanding requests. | |
| 37 ~CertNetFetcherImpl() override; | |
| 38 | |
| 39 void CancelRequest(RequestId request_id) override; | |
| 40 | |
| 41 RequestId FetchCaIssuers(const GURL& url, | |
| 42 int timeout_milliseconds, | |
| 43 int max_response_bytes, | |
| 44 const FetchCallback& callback) override; | |
| 45 | |
| 46 RequestId FetchCrl(const GURL& url, | |
| 47 int timeout_milliseconds, | |
| 48 int max_response_bytes, | |
| 49 const FetchCallback& callback) override; | |
| 50 | |
| 51 RequestId FetchOcsp(const GURL& url, | |
| 52 int timeout_milliseconds, | |
| 53 int max_response_bytes, | |
| 54 const FetchCallback& callback) override; | |
| 55 | |
| 56 private: | |
| 57 struct Request; | |
| 58 class Job; | |
| 59 struct JobToRequestParamsComparator; | |
| 60 struct RequestParams; | |
|
davidben
2015/03/27 23:34:32
Nit: ordering. I think it's classes before structs
| |
| 61 | |
| 62 struct JobComparator { | |
| 63 bool operator()(const Job* job1, const Job* job2) const; | |
| 64 }; | |
| 65 | |
| 66 using JobSet = std::set<Job*, JobComparator>; | |
| 67 | |
| 68 // Starts an asynchronous request to fetch the given URL. On completion | |
| 69 // |callback| will be invoked. | |
| 70 // | |
| 71 // Completion of the request will never occur synchronously. In other words it | |
| 72 // is guaranteed that |callback| will only be invoked once the Fetch*() method | |
| 73 // has returned. | |
| 74 RequestId Fetch(scoped_ptr<RequestParams> request_params, | |
| 75 const FetchCallback& callback); | |
| 76 | |
| 77 // Finds a job with a matching RequestPararms or returns NULL if there was no | |
| 78 // match. | |
| 79 Job* FindJob(const RequestParams& params); | |
| 80 | |
| 81 // Removes |job| from the in progress jobs and transfers ownership to the | |
| 82 // caller. | |
| 83 scoped_ptr<Job> RemoveJob(Job* job); | |
| 84 | |
| 85 // Indicates which Job is currently executing inside of OnJobCompleted(). | |
| 86 void SetCurrentlyCompletingJob(Job* job); | |
| 87 | |
| 88 // The in-progress jobs. This set does not contain the job which is actively | |
| 89 // invoking callbacks (OnJobCompleted). Instead that is tracked by | |
| 90 // |currently_completing_job_|. | |
| 91 JobSet jobs_; | |
| 92 | |
| 93 // The Job that is currently executing OnJobCompleted(). There can be at most | |
| 94 // one such job. This pointer is not owned. | |
| 95 Job* currently_completing_job_; | |
| 96 | |
| 97 // Not owned. CertNetFetcherImpl must outlive the URLRequestContext. | |
| 98 URLRequestContext* context_; | |
| 99 | |
| 100 base::ThreadChecker thread_checker_; | |
| 101 | |
| 102 DISALLOW_COPY_AND_ASSIGN(CertNetFetcherImpl); | |
| 103 }; | |
| 104 | |
| 105 } // namespace net | |
| 106 | |
| 107 #endif // NET_CERT_NET_CERT_NET_FETCHER_H_ | |
| OLD | NEW |