Update dns_transaction.cc
This commit is contained in:
parent
18cbecc6ac
commit
2a8de594e1
1 changed files with 23 additions and 16 deletions
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) 2022 The Chromium Authors. All rights reserved.
|
// Copyright (c) 2022 The Chromium Authors and Alex313031. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
@ -451,12 +451,14 @@ class DnsHTTPAttempt : public DnsAttempt, public URLRequest::Delegate {
|
||||||
|
|
||||||
int Start(CompletionOnceCallback callback) override {
|
int Start(CompletionOnceCallback callback) override {
|
||||||
callback_ = std::move(callback);
|
callback_ = std::move(callback);
|
||||||
request_->Start();
|
// Start the request asynchronously to avoid reentrancy in
|
||||||
|
// the network stack.
|
||||||
|
base::SequencedTaskRunnerHandle::Get()->PostTask(
|
||||||
|
FROM_HERE, base::BindOnce(&DnsHTTPAttempt::StartAsync,
|
||||||
|
weak_factory_.GetWeakPtr()));
|
||||||
return ERR_IO_PENDING;
|
return ERR_IO_PENDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cancel() { request_.reset(); }
|
|
||||||
|
|
||||||
const DnsQuery* GetQuery() const override { return query_.get(); }
|
const DnsQuery* GetQuery() const override { return query_.get(); }
|
||||||
const DnsResponse* GetResponse() const override {
|
const DnsResponse* GetResponse() const override {
|
||||||
const DnsResponse* resp = response_.get();
|
const DnsResponse* resp = response_.get();
|
||||||
|
@ -561,6 +563,11 @@ class DnsHTTPAttempt : public DnsAttempt, public URLRequest::Delegate {
|
||||||
bool IsPending() const override { return !callback_.is_null(); }
|
bool IsPending() const override { return !callback_.is_null(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void StartAsync() {
|
||||||
|
DCHECK(request_);
|
||||||
|
request_->Start();
|
||||||
|
}
|
||||||
|
|
||||||
void ResponseCompleted(int net_error) {
|
void ResponseCompleted(int net_error) {
|
||||||
request_.reset();
|
request_.reset();
|
||||||
std::move(callback_).Run(CompleteResponse(net_error));
|
std::move(callback_).Run(CompleteResponse(net_error));
|
||||||
|
@ -618,14 +625,14 @@ void ConstructDnsHTTPAttempt(DnsSession* session,
|
||||||
query = std::make_unique<DnsQuery>(*attempts->at(0)->GetQuery());
|
query = std::make_unique<DnsQuery>(*attempts->at(0)->GetQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
DCHECK_LT(doh_server_index, session->config().dns_over_https_servers.size());
|
DCHECK_LT(doh_server_index, session->config().doh_config.servers().size());
|
||||||
const DnsOverHttpsServerConfig& doh_config =
|
const DnsOverHttpsServerConfig& doh_server =
|
||||||
session->config().dns_over_https_servers[doh_server_index];
|
session->config().doh_config.servers()[doh_server_index];
|
||||||
GURL gurl_without_parameters(
|
GURL gurl_without_parameters(
|
||||||
GetURLFromTemplateWithoutParameters(doh_config.server_template()));
|
GetURLFromTemplateWithoutParameters(doh_server.server_template()));
|
||||||
attempts->push_back(std::make_unique<DnsHTTPAttempt>(
|
attempts->push_back(std::make_unique<DnsHTTPAttempt>(
|
||||||
doh_server_index, std::move(query), doh_config.server_template(),
|
doh_server_index, std::move(query), doh_server.server_template(),
|
||||||
gurl_without_parameters, doh_config.use_post(), url_request_context,
|
gurl_without_parameters, doh_server.use_post(), url_request_context,
|
||||||
isolation_info, request_priority));
|
isolation_info, request_priority));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -913,12 +920,12 @@ class DnsOverHttpsProbeRunner : public DnsProbeRunner {
|
||||||
base::WeakPtr<ResolveContext> context)
|
base::WeakPtr<ResolveContext> context)
|
||||||
: session_(session), context_(context) {
|
: session_(session), context_(context) {
|
||||||
DCHECK(session_);
|
DCHECK(session_);
|
||||||
DCHECK(!session_->config().dns_over_https_servers.empty());
|
DCHECK(!session_->config().doh_config.servers().empty());
|
||||||
DCHECK(context_);
|
DCHECK(context_);
|
||||||
|
|
||||||
DNSDomainFromDot(kDoHProbeHostname, &formatted_probe_hostname_);
|
DNSDomainFromDot(kDoHProbeHostname, &formatted_probe_hostname_);
|
||||||
|
|
||||||
for (size_t i = 0; i < session_->config().dns_over_https_servers.size();
|
for (size_t i = 0; i < session_->config().doh_config.servers().size();
|
||||||
i++) {
|
i++) {
|
||||||
probe_stats_list_.push_back(nullptr);
|
probe_stats_list_.push_back(nullptr);
|
||||||
}
|
}
|
||||||
|
@ -930,9 +937,9 @@ class DnsOverHttpsProbeRunner : public DnsProbeRunner {
|
||||||
DCHECK(session_);
|
DCHECK(session_);
|
||||||
DCHECK(context_);
|
DCHECK(context_);
|
||||||
|
|
||||||
|
const auto& config = session_->config().doh_config;
|
||||||
// Start probe sequences for any servers where it is not currently running.
|
// Start probe sequences for any servers where it is not currently running.
|
||||||
for (size_t i = 0; i < session_->config().dns_over_https_servers.size();
|
for (size_t i = 0; i < config.servers().size(); i++) {
|
||||||
i++) {
|
|
||||||
if (!probe_stats_list_[i]) {
|
if (!probe_stats_list_[i]) {
|
||||||
probe_stats_list_[i] = std::make_unique<ProbeStats>();
|
probe_stats_list_[i] = std::make_unique<ProbeStats>();
|
||||||
ContinueProbe(i, probe_stats_list_[i]->weak_factory.GetWeakPtr(),
|
ContinueProbe(i, probe_stats_list_[i]->weak_factory.GetWeakPtr(),
|
||||||
|
@ -1254,7 +1261,7 @@ class DnsTransactionImpl : public DnsTransaction,
|
||||||
if (secure_ && result.attempt) {
|
if (secure_ && result.attempt) {
|
||||||
size_t server_index = result.attempt->server_index();
|
size_t server_index = result.attempt->server_index();
|
||||||
doh_provider_id = GetDohProviderIdForHistogramFromServerConfig(
|
doh_provider_id = GetDohProviderIdForHistogramFromServerConfig(
|
||||||
session_->config().dns_over_https_servers[server_index]);
|
session_->config().doh_config.servers()[server_index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::move(callback_).Run(this, result.rv, response, doh_provider_id);
|
std::move(callback_).Run(this, result.rv, response, doh_provider_id);
|
||||||
|
@ -1270,7 +1277,7 @@ class DnsTransactionImpl : public DnsTransaction,
|
||||||
|
|
||||||
DnsConfig config = session_->config();
|
DnsConfig config = session_->config();
|
||||||
if (secure_) {
|
if (secure_) {
|
||||||
DCHECK_GT(config.dns_over_https_servers.size(), 0u);
|
DCHECK(!config.doh_config.servers().empty());
|
||||||
RecordAttemptUma(DnsAttemptType::kHttp);
|
RecordAttemptUma(DnsAttemptType::kHttp);
|
||||||
return MakeHTTPAttempt();
|
return MakeHTTPAttempt();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue