#include "services/cert_verifier/cert_net_url_loader/cert_net_fetcher_url_loader.h"
#include <memory>
#include <tuple>
#include <utility>
#include "base/check_op.h"
#include "base/containers/span.h"
#include "base/containers/to_vector.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/not_fatal_until.h"
#include "base/numerics/safe_math.h"
#include "base/ranges/algorithm.h"
#include "base/sequence_checker.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "net/base/load_flags.h"
#include "net/cert/cert_net_fetcher.h"
#include "net/http/http_request_headers.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/redirect_info.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace cert_verifier {
namespace {
const int kMaxResponseSizeInBytesForCrl = …;
const int kMaxResponseSizeInBytesForAia = …;
const int kTimeoutSeconds = …;
class Job;
struct JobToRequestParamsComparator;
struct JobComparator { … };
JobSet;
BindNewURLLoaderFactoryCallback;
}
class CertNetFetcherURLLoader::AsyncCertNetFetcherURLLoader { … };
namespace {
net::Error CanFetchUrl(const GURL& url) { … }
base::TimeDelta GetTimeout(int timeout_milliseconds) { … }
size_t GetMaxResponseBytes(int max_response_bytes,
size_t default_max_response_bytes) { … }
enum HttpMethod { … };
}
class CertNetFetcherURLLoader::RequestCore
: public base::RefCountedThreadSafe<RequestCore> { … };
struct CertNetFetcherURLLoader::RequestParams { … };
CertNetFetcherURLLoader::RequestParams::RequestParams()
: … { … }
bool CertNetFetcherURLLoader::RequestParams::operator<(
const RequestParams& other) const { … }
namespace {
class Job { … };
}
void CertNetFetcherURLLoader::RequestCore::SignalImmediateError() { … }
void CertNetFetcherURLLoader::RequestCore::CancelJob() { … }
void CertNetFetcherURLLoader::RequestCore::CancelJobOnTaskRunner() { … }
namespace {
Job::Job(std::unique_ptr<CertNetFetcherURLLoader::RequestParams> request_params,
CertNetFetcherURLLoader::AsyncCertNetFetcherURLLoader* parent)
: … { … }
Job::~Job() { … }
void Job::AttachRequest(
scoped_refptr<CertNetFetcherURLLoader::RequestCore> request) { … }
void Job::DetachRequest(CertNetFetcherURLLoader::RequestCore* request) { … }
void Job::StartURLLoader(network::mojom::URLLoaderFactory* factory) { … }
void Job::Cancel() { … }
void Job::OnReceivedRedirect(
const GURL& url_before_redirect,
const net::RedirectInfo& redirect_info,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* removed_headers) { … }
void Job::OnResponseStarted(
const GURL& final_url,
const network::mojom::URLResponseHead& response_head) { … }
void Job::OnUrlLoaderCompleted(std::unique_ptr<std::string> response_body) { … }
void Job::OnJobCompleted(net::Error error,
std::unique_ptr<std::string> response_body) { … }
void Job::CompleteAndClearRequests(net::Error error,
std::unique_ptr<std::string> response_body) { … }
void Job::FailRequest(net::Error error) { … }
}
CertNetFetcherURLLoader::AsyncCertNetFetcherURLLoader::
AsyncCertNetFetcherURLLoader(
mojo::PendingRemote<network::mojom::URLLoaderFactory>
factory_pending_remote,
BindNewURLLoaderFactoryCallback bind_new_url_loader_factory_cb)
: … { … }
CertNetFetcherURLLoader::AsyncCertNetFetcherURLLoader::
~AsyncCertNetFetcherURLLoader() { … }
void CertNetFetcherURLLoader::AsyncCertNetFetcherURLLoader::
DisconnectURLLoaderFactoryForTesting() { … }
bool JobComparator::operator()(const Job* job1, const Job* job2) const { … }
void CertNetFetcherURLLoader::AsyncCertNetFetcherURLLoader::Fetch(
std::unique_ptr<RequestParams> request_params,
scoped_refptr<RequestCore> request) { … }
void CertNetFetcherURLLoader::AsyncCertNetFetcherURLLoader::Shutdown() { … }
void CertNetFetcherURLLoader::AsyncCertNetFetcherURLLoader::
RebindURLLoaderFactory() { … }
namespace {
struct JobToRequestParamsComparator { … };
}
Job* CertNetFetcherURLLoader::AsyncCertNetFetcherURLLoader::FindJob(
const RequestParams& params) { … }
std::unique_ptr<Job>
CertNetFetcherURLLoader::AsyncCertNetFetcherURLLoader::RemoveJob(Job* job) { … }
namespace {
class CertNetFetcherRequestImpl : public net::CertNetFetcher::Request { … };
}
CertNetFetcherURLLoader::CertNetFetcherURLLoader()
: … { … }
CertNetFetcherURLLoader::~CertNetFetcherURLLoader() = default;
void CertNetFetcherURLLoader::SetURLLoaderFactoryAndReconnector(
mojo::PendingRemote<network::mojom::URLLoaderFactory> factory,
base::RepeatingCallback<
void(mojo::PendingReceiver<network::mojom::URLLoaderFactory>)>
bind_new_url_loader_factory_cb) { … }
base::TimeDelta CertNetFetcherURLLoader::GetDefaultTimeoutForTesting() { … }
void CertNetFetcherURLLoader::DisconnectURLLoaderFactoryForTesting() { … }
void CertNetFetcherURLLoader::Shutdown() { … }
std::unique_ptr<net::CertNetFetcher::Request>
CertNetFetcherURLLoader::FetchCaIssuers(const GURL& url,
int timeout_milliseconds,
int max_response_bytes) { … }
std::unique_ptr<net::CertNetFetcher::Request> CertNetFetcherURLLoader::FetchCrl(
const GURL& url,
int timeout_milliseconds,
int max_response_bytes) { … }
std::unique_ptr<net::CertNetFetcher::Request>
CertNetFetcherURLLoader::FetchOcsp(const GURL& url,
int timeout_milliseconds,
int max_response_bytes) { … }
void CertNetFetcherURLLoader::DoFetchOnTaskRunner(
std::unique_ptr<RequestParams> request_params,
scoped_refptr<RequestCore> request) { … }
std::unique_ptr<CertNetFetcherURLLoader::Request>
CertNetFetcherURLLoader::DoFetch(
std::unique_ptr<RequestParams> request_params) { … }
}