summaryrefslogtreecommitdiff
path: root/net/cert_net/cert_net_fetcher_url_request.h
blob: 3ec14ca1741fcf09e4ca2fde5f83eb28e30b0f52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_CERT_NET_CERT_NET_FETCHER_URL_REQUEST_H_
#define NET_CERT_NET_CERT_NET_FETCHER_URL_REQUEST_H_

#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "net/base/net_export.h"
#include "net/cert/cert_net_fetcher.h"

namespace base {
class SingleThreadTaskRunner;
}

namespace net {

class URLRequestContext;

// A CertNetFetcher that issues requests through the provided
// URLRequestContext. The URLRequestContext must stay valid until the returned
// CertNetFetcher's Shutdown method is called. The CertNetFetcher is to be
// created and shutdown on the network thread. Its Fetch methods are to be used
// on a *different* thread, since it gives a blocking interface to URL fetching.
class NET_EXPORT CertNetFetcherURLRequest : public CertNetFetcher {
 public:
  class AsyncCertNetFetcherURLRequest;
  class RequestCore;
  struct RequestParams;

  // Creates the CertNetFetcherURLRequest. SetURLRequestContext must be called
  // before the fetcher can be used.
  CertNetFetcherURLRequest();

  // Set the URLRequestContext this fetcher should use.
  // |context_| must stay valid until Shutdown() is called.
  void SetURLRequestContext(URLRequestContext* context);

  // Returns the default timeout value. Intended for test use only.
  static base::TimeDelta GetDefaultTimeoutForTesting();

  // CertNetFetcher impl:
  void Shutdown() override;
  std::unique_ptr<Request> FetchCaIssuers(const GURL& url,
                                          int timeout_milliseconds,
                                          int max_response_bytes) override;
  std::unique_ptr<Request> FetchCrl(const GURL& url,
                                    int timeout_milliseconds,
                                    int max_response_bytes) override;
  [[nodiscard]] std::unique_ptr<Request> FetchOcsp(
      const GURL& url,
      int timeout_milliseconds,
      int max_response_bytes) override;

 private:
  ~CertNetFetcherURLRequest() override;

  void DoFetchOnNetworkSequence(std::unique_ptr<RequestParams> request_params,
                                scoped_refptr<RequestCore> request);

  std::unique_ptr<Request> DoFetch(
      std::unique_ptr<RequestParams> request_params);

  scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
  // Not owned. |context_| must stay valid until Shutdown() is called.
  raw_ptr<URLRequestContext> context_ = nullptr;
  std::unique_ptr<AsyncCertNetFetcherURLRequest> impl_;
};

}  // namespace net

#endif  // NET_CERT_NET_CERT_NET_FETCHER_URL_REQUEST_H_