1 // Copyright 2015 The Chromium Authors 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_URL_REQUEST_H_ 6 #define NET_CERT_NET_CERT_NET_FETCHER_URL_REQUEST_H_ 7 8 #include "base/memory/raw_ptr.h" 9 #include "base/memory/scoped_refptr.h" 10 #include "net/base/net_export.h" 11 #include "net/cert/cert_net_fetcher.h" 12 13 namespace base { 14 class SingleThreadTaskRunner; 15 } 16 17 namespace net { 18 19 class URLRequestContext; 20 21 // A CertNetFetcher that issues requests through the provided 22 // URLRequestContext. The URLRequestContext must stay valid until the returned 23 // CertNetFetcher's Shutdown method is called. The CertNetFetcher is to be 24 // created and shutdown on the network thread. Its Fetch methods are to be used 25 // on a *different* thread, since it gives a blocking interface to URL fetching. 26 class NET_EXPORT CertNetFetcherURLRequest : public CertNetFetcher { 27 public: 28 class AsyncCertNetFetcherURLRequest; 29 class RequestCore; 30 struct RequestParams; 31 32 // Creates the CertNetFetcherURLRequest. SetURLRequestContext must be called 33 // before the fetcher can be used. 34 CertNetFetcherURLRequest(); 35 36 // Set the URLRequestContext this fetcher should use. 37 // |context_| must stay valid until Shutdown() is called. 38 void SetURLRequestContext(URLRequestContext* context); 39 40 // Returns the default timeout value. Intended for test use only. 41 static base::TimeDelta GetDefaultTimeoutForTesting(); 42 43 // CertNetFetcher impl: 44 void Shutdown() override; 45 std::unique_ptr<Request> FetchCaIssuers(const GURL& url, 46 int timeout_milliseconds, 47 int max_response_bytes) override; 48 std::unique_ptr<Request> FetchCrl(const GURL& url, 49 int timeout_milliseconds, 50 int max_response_bytes) override; 51 [[nodiscard]] std::unique_ptr<Request> FetchOcsp( 52 const GURL& url, 53 int timeout_milliseconds, 54 int max_response_bytes) override; 55 56 private: 57 ~CertNetFetcherURLRequest() override; 58 59 void DoFetchOnNetworkSequence(std::unique_ptr<RequestParams> request_params, 60 scoped_refptr<RequestCore> request); 61 62 std::unique_ptr<Request> DoFetch( 63 std::unique_ptr<RequestParams> request_params); 64 65 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 66 // Not owned. |context_| must stay valid until Shutdown() is called. 67 raw_ptr<URLRequestContext> context_ = nullptr; 68 std::unique_ptr<AsyncCertNetFetcherURLRequest> impl_; 69 }; 70 71 } // namespace net 72 73 #endif // NET_CERT_NET_CERT_NET_FETCHER_URL_REQUEST_H_ 74