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