forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wraps HostResolverImpl and replaces almost all direct use of HostResolverImpl. In subsequent CLs, this will become a per-context object around the mostly-global HostResolverImpl, but until then, there should be no functional difference from this CL alone. Just adding an additional layer of indirection, generally invisible to callers. In a slight deviation from a previous version of this work (crrev.com/c/1418880), the new object is what implements the HostResolver interface (not HostResolverImpl) to avoid including the per-context parameters (especially HostCache) in the interface and keep them implementation details between ContextHostResolver and HostResolverImpl. This also led to separating off ProcTaskParams (to host_resolver_proc.h) as its no longer clearly owned by either ContextHostResolver or HostResolverImpl (parameter to one, used by the other) and it's now desirable to limit #includes of host_resolver_impl.h. Bug: 934402 Change-Id: I0a88614854011d52335d3a7bb335ba6a85fe0aa3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1481599 Reviewed-by: Paul Jensen <pauljensen@chromium.org> Commit-Queue: Paul Jensen <pauljensen@chromium.org> Auto-Submit: Eric Orth <ericorth@chromium.org> Cr-Commit-Position: refs/heads/master@{#638820}
- Loading branch information
Eric Orth
authored and
Commit Bot
committed
Mar 7, 2019
1 parent
b4231cb
commit 5906622
Showing
23 changed files
with
456 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Copyright (c) 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "net/dns/context_host_resolver.h" | ||
|
||
#include <utility> | ||
|
||
#include "base/strings/string_piece.h" | ||
#include "base/time/tick_clock.h" | ||
#include "net/dns/dns_client.h" | ||
#include "net/dns/dns_config.h" | ||
#include "net/dns/host_resolver_impl.h" | ||
#include "net/dns/host_resolver_proc.h" | ||
|
||
namespace net { | ||
|
||
ContextHostResolver::ContextHostResolver(std::unique_ptr<HostResolverImpl> impl) | ||
: impl_(std::move(impl)) {} | ||
|
||
ContextHostResolver::~ContextHostResolver() = default; | ||
|
||
std::unique_ptr<HostResolver::ResolveHostRequest> | ||
ContextHostResolver::CreateRequest( | ||
const HostPortPair& host, | ||
const NetLogWithSource& source_net_log, | ||
const base::Optional<ResolveHostParameters>& optional_parameters) { | ||
return impl_->CreateRequest(host, source_net_log, optional_parameters); | ||
} | ||
|
||
std::unique_ptr<HostResolver::MdnsListener> | ||
ContextHostResolver::CreateMdnsListener(const HostPortPair& host, | ||
DnsQueryType query_type) { | ||
return impl_->CreateMdnsListener(host, query_type); | ||
} | ||
|
||
void ContextHostResolver::SetDnsClientEnabled(bool enabled) { | ||
impl_->SetDnsClientEnabled(enabled); | ||
} | ||
|
||
HostCache* ContextHostResolver::GetHostCache() { | ||
return impl_->GetHostCache(); | ||
} | ||
|
||
bool ContextHostResolver::HasCached(base::StringPiece hostname, | ||
HostCache::Entry::Source* source_out, | ||
HostCache::EntryStaleness* stale_out, | ||
bool* secure_out) const { | ||
return impl_->HasCached(hostname, source_out, stale_out, secure_out); | ||
} | ||
|
||
std::unique_ptr<base::Value> ContextHostResolver::GetDnsConfigAsValue() const { | ||
return impl_->GetDnsConfigAsValue(); | ||
} | ||
|
||
void ContextHostResolver::SetNoIPv6OnWifi(bool no_ipv6_on_wifi) { | ||
impl_->SetNoIPv6OnWifi(no_ipv6_on_wifi); | ||
} | ||
|
||
bool ContextHostResolver::GetNoIPv6OnWifi() { | ||
return impl_->GetNoIPv6OnWifi(); | ||
} | ||
|
||
void ContextHostResolver::SetDnsConfigOverrides( | ||
const DnsConfigOverrides& overrides) { | ||
impl_->SetDnsConfigOverrides(overrides); | ||
} | ||
|
||
void ContextHostResolver::SetRequestContext( | ||
URLRequestContext* request_context) { | ||
impl_->SetRequestContext(request_context); | ||
} | ||
|
||
const std::vector<DnsConfig::DnsOverHttpsServerConfig>* | ||
ContextHostResolver::GetDnsOverHttpsServersForTesting() const { | ||
return impl_->GetDnsOverHttpsServersForTesting(); | ||
} | ||
|
||
size_t ContextHostResolver::LastRestoredCacheSize() const { | ||
return impl_->LastRestoredCacheSize(); | ||
} | ||
|
||
size_t ContextHostResolver::CacheSize() const { | ||
return impl_->CacheSize(); | ||
} | ||
|
||
void ContextHostResolver::SetProcParamsForTesting( | ||
const ProcTaskParams& proc_params) { | ||
impl_->set_proc_params_for_test(proc_params); | ||
} | ||
|
||
void ContextHostResolver::SetDnsClientForTesting( | ||
std::unique_ptr<DnsClient> dns_client) { | ||
impl_->SetDnsClient(std::move(dns_client)); | ||
} | ||
|
||
void ContextHostResolver::SetBaseDnsConfigForTesting( | ||
const DnsConfig& base_config) { | ||
impl_->SetBaseDnsConfigForTesting(base_config); | ||
} | ||
|
||
void ContextHostResolver::SetTickClockForTesting( | ||
const base::TickClock* tick_clock) { | ||
impl_->SetTickClockForTesting(tick_clock); | ||
} | ||
|
||
} // namespace net |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef NET_DNS_CONTEXT_HOST_RESOLVER_H_ | ||
#define NET_DNS_CONTEXT_HOST_RESOLVER_H_ | ||
|
||
#include <memory> | ||
#include <vector> | ||
|
||
#include "net/base/net_export.h" | ||
#include "net/dns/host_resolver.h" | ||
|
||
namespace base { | ||
class TickClock; | ||
} // namespace base | ||
|
||
namespace net { | ||
|
||
class DnsClient; | ||
struct DnsConfig; | ||
class HostResolverImpl; | ||
struct ProcTaskParams; | ||
|
||
// Wrapper for HostResolverImpl that sets per-context parameters for created | ||
// requests. Except for tests, typically only interacted with through the | ||
// HostResolver interface. | ||
// | ||
// See HostResolver::Create[...]() methods for construction. | ||
// | ||
// TODO(crbug.com/934402): Construct individually for each URLRequestContext | ||
// rather than using this as the singleton shared resolver. | ||
class NET_EXPORT ContextHostResolver : public HostResolver { | ||
public: | ||
// Creates a ContextHostResolver that forwards all of its requests through | ||
// |impl|. | ||
explicit ContextHostResolver(std::unique_ptr<HostResolverImpl> impl); | ||
~ContextHostResolver() override; | ||
|
||
// HostResolver methods: | ||
std::unique_ptr<ResolveHostRequest> CreateRequest( | ||
const HostPortPair& host, | ||
const NetLogWithSource& net_log, | ||
const base::Optional<ResolveHostParameters>& optional_parameters) | ||
override; | ||
std::unique_ptr<MdnsListener> CreateMdnsListener( | ||
const HostPortPair& host, | ||
DnsQueryType query_type) override; | ||
void SetDnsClientEnabled(bool enabled) override; | ||
HostCache* GetHostCache() override; | ||
bool HasCached(base::StringPiece hostname, | ||
HostCache::Entry::Source* source_out, | ||
HostCache::EntryStaleness* stale_out, | ||
bool* secure_out) const override; | ||
std::unique_ptr<base::Value> GetDnsConfigAsValue() const override; | ||
void SetNoIPv6OnWifi(bool no_ipv6_on_wifi) override; | ||
bool GetNoIPv6OnWifi() override; | ||
void SetDnsConfigOverrides(const DnsConfigOverrides& overrides) override; | ||
void SetRequestContext(URLRequestContext* request_context) override; | ||
const std::vector<DnsConfig::DnsOverHttpsServerConfig>* | ||
GetDnsOverHttpsServersForTesting() const override; | ||
|
||
// Returns the number of host cache entries that were restored, or 0 if there | ||
// is no cache. | ||
size_t LastRestoredCacheSize() const; | ||
// Returns the number of entries in the host cache, or 0 if there is no cache. | ||
size_t CacheSize() const; | ||
|
||
void SetProcParamsForTesting(const ProcTaskParams& proc_params); | ||
void SetDnsClientForTesting(std::unique_ptr<DnsClient> dns_client); | ||
void SetBaseDnsConfigForTesting(const DnsConfig& base_config); | ||
void SetTickClockForTesting(const base::TickClock* tick_clock); | ||
|
||
private: | ||
// TODO(crbug.com/934402): Make this a non-owned pointer to the singleton | ||
// resolver. | ||
std::unique_ptr<HostResolverImpl> impl_; | ||
}; | ||
|
||
} // namespace net | ||
|
||
#endif // NET_DNS_CONTEXT_HOST_RESOLVER_H_ |
Oops, something went wrong.