Skip to content

Commit

Permalink
NetworkIsolationKeys + PAC scripts PS5: ProxyResolver
Browse files Browse the repository at this point in the history
Wire NetworkIsolationKey through ProxyResolver API and all
implementations. Also wire it through the Proxy Resolver Service API.

net/ isn't yet passing a NetworkIsolationKey() to the ProxyResolver API,
so this shouldn't affect behavior yet.

Bug: 1021661
Change-Id: Ia9dab8ac7b5062ea85435022e85d1f1720c7da76
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1906247
Commit-Queue: Matt Menke <mmenke@chromium.org>
Reviewed-by: Eric Roman <eroman@chromium.org>
Reviewed-by: Mike West <mkwst@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715022}
  • Loading branch information
Matt Menke authored and Commit Bot committed Nov 13, 2019
1 parent 9f90ec1 commit cd522ee
Show file tree
Hide file tree
Showing 18 changed files with 304 additions and 120 deletions.
3 changes: 3 additions & 0 deletions net/dns/mock_host_resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,9 @@ HangingHostResolver::CreateRequest(
const NetworkIsolationKey& network_isolation_key,
const NetLogWithSource& source_net_log,
const base::Optional<ResolveHostParameters>& optional_parameters) {
last_host_ = host;
last_network_isolation_key_ = network_isolation_key;

if (shutting_down_)
return CreateFailingRequest(ERR_CONTEXT_SHUT_DOWN);

Expand Down
11 changes: 11 additions & 0 deletions net/dns/mock_host_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "base/synchronization/waitable_event.h"
#include "base/threading/thread_checker.h"
#include "net/base/completion_once_callback.h"
#include "net/base/network_isolation_key.h"
#include "net/dns/dns_config.h"
#include "net/dns/host_resolver.h"
#include "net/dns/host_resolver_proc.h"
Expand Down Expand Up @@ -485,10 +486,20 @@ class HangingHostResolver : public HostResolver {
// differentiation between a cancelled and a hung task.
int num_cancellations() const { return num_cancellations_; }

// Return the corresponding values passed to the most recent call to
// CreateRequest()
const HostPortPair& last_host() const { return last_host_; }
const NetworkIsolationKey& last_network_isolation_key() const {
return last_network_isolation_key_;
}

private:
class RequestImpl;
class ProbeRequestImpl;

HostPortPair last_host_;
NetworkIsolationKey last_network_isolation_key_;

int num_cancellations_ = 0;
bool shutting_down_ = false;
base::WeakPtrFactory<HangingHostResolver> weak_ptr_factory_{this};
Expand Down
2 changes: 2 additions & 0 deletions net/http/http_network_transaction_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ class CapturingProxyResolver : public ProxyResolver {
~CapturingProxyResolver() override = default;

int GetProxyForURL(const GURL& url,
const NetworkIsolationKey& network_isolation_key,
ProxyInfo* results,
CompletionOnceCallback callback,
std::unique_ptr<Request>* request,
Expand Down Expand Up @@ -5531,6 +5532,7 @@ class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver {

// ProxyResolver implementation.
int GetProxyForURL(const GURL& url,
const NetworkIsolationKey& network_isolation_key,
ProxyInfo* results,
CompletionOnceCallback callback,
std::unique_ptr<Request>* request,
Expand Down
17 changes: 10 additions & 7 deletions net/proxy_resolution/mock_proxy_resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ MockAsyncProxyResolver::~MockAsyncProxyResolver() = default;

int MockAsyncProxyResolver::GetProxyForURL(
const GURL& url,
const NetworkIsolationKey& network_isolation_key,
ProxyInfo* results,
CompletionOnceCallback callback,
std::unique_ptr<Request>* request,
Expand Down Expand Up @@ -169,13 +170,15 @@ ForwardingProxyResolver::ForwardingProxyResolver(ProxyResolver* impl)
: impl_(impl) {
}

int ForwardingProxyResolver::GetProxyForURL(const GURL& query_url,
ProxyInfo* results,
CompletionOnceCallback callback,
std::unique_ptr<Request>* request,
const NetLogWithSource& net_log) {
return impl_->GetProxyForURL(query_url, results, std::move(callback), request,
net_log);
int ForwardingProxyResolver::GetProxyForURL(
const GURL& query_url,
const NetworkIsolationKey& network_isolation_key,
ProxyInfo* results,
CompletionOnceCallback callback,
std::unique_ptr<Request>* request,
const NetLogWithSource& net_log) {
return impl_->GetProxyForURL(query_url, network_isolation_key, results,
std::move(callback), request, net_log);
}

} // namespace net
3 changes: 3 additions & 0 deletions net/proxy_resolution/mock_proxy_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/macros.h"
#include "net/base/completion_once_callback.h"
#include "net/base/net_errors.h"
#include "net/base/network_isolation_key.h"
#include "net/proxy_resolution/proxy_resolver.h"
#include "net/proxy_resolution/proxy_resolver_factory.h"
#include "url/gurl.h"
Expand Down Expand Up @@ -60,6 +61,7 @@ class MockAsyncProxyResolver : public ProxyResolver {

// ProxyResolver implementation.
int GetProxyForURL(const GURL& url,
const NetworkIsolationKey& network_isolation_key,
ProxyInfo* results,
CompletionOnceCallback callback,
std::unique_ptr<Request>* request,
Expand Down Expand Up @@ -148,6 +150,7 @@ class ForwardingProxyResolver : public ProxyResolver {

// ProxyResolver overrides.
int GetProxyForURL(const GURL& query_url,
const NetworkIsolationKey& network_isolation_key,
ProxyInfo* results,
CompletionOnceCallback callback,
std::unique_ptr<Request>* request,
Expand Down
18 changes: 14 additions & 4 deletions net/proxy_resolution/multi_threaded_proxy_resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "base/threading/thread_restrictions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "net/base/net_errors.h"
#include "net/base/network_isolation_key.h"
#include "net/log/net_log.h"
#include "net/log/net_log_event_type.h"
#include "net/log/net_log_with_source.h"
Expand All @@ -29,6 +30,8 @@

namespace net {

class NetworkIsolationKey;

// http://crbug.com/69710
class MultiThreadedProxyResolverScopedAllowJoinOnIO
: public base::ScopedAllowBaseSyncPrimitivesOutsideBlockingScope {};
Expand Down Expand Up @@ -122,6 +125,7 @@ class MultiThreadedProxyResolver : public ProxyResolver,

// ProxyResolver implementation:
int GetProxyForURL(const GURL& url,
const NetworkIsolationKey& network_isolation_key,
ProxyInfo* results,
CompletionOnceCallback callback,
std::unique_ptr<Request>* request,
Expand Down Expand Up @@ -269,13 +273,15 @@ class MultiThreadedProxyResolver::GetProxyForURLJob : public Job {
// |url| -- the URL of the query.
// |results| -- the structure to fill with proxy resolve results.
GetProxyForURLJob(const GURL& url,
const NetworkIsolationKey& network_isolation_key,
ProxyInfo* results,
CompletionOnceCallback callback,
const NetLogWithSource& net_log)
: callback_(std::move(callback)),
results_(results),
net_log_(net_log),
url_(url),
network_isolation_key_(network_isolation_key),
was_waiting_for_thread_(false) {
DCHECK(callback_);
}
Expand Down Expand Up @@ -303,8 +309,9 @@ class MultiThreadedProxyResolver::GetProxyForURLJob : public Job {
void Run(scoped_refptr<base::SingleThreadTaskRunner> origin_runner) override {
ProxyResolver* resolver = executor()->resolver();
DCHECK(resolver);
int rv = resolver->GetProxyForURL(
url_, &results_buf_, CompletionOnceCallback(), nullptr, net_log_);
int rv =
resolver->GetProxyForURL(url_, network_isolation_key_, &results_buf_,
CompletionOnceCallback(), nullptr, net_log_);
DCHECK_NE(rv, ERR_IO_PENDING);

origin_runner->PostTask(
Expand Down Expand Up @@ -334,7 +341,9 @@ class MultiThreadedProxyResolver::GetProxyForURLJob : public Job {

// Can be used on either "origin" or worker thread.
NetLogWithSource net_log_;

const GURL url_;
const NetworkIsolationKey network_isolation_key_;

// Usable from within DoQuery on the worker thread.
ProxyInfo results_buf_;
Expand Down Expand Up @@ -436,15 +445,16 @@ MultiThreadedProxyResolver::~MultiThreadedProxyResolver() {

int MultiThreadedProxyResolver::GetProxyForURL(
const GURL& url,
const NetworkIsolationKey& network_isolation_key,
ProxyInfo* results,
CompletionOnceCallback callback,
std::unique_ptr<Request>* request,
const NetLogWithSource& net_log) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(!callback.is_null());

scoped_refptr<GetProxyForURLJob> job(
new GetProxyForURLJob(url, results, std::move(callback), net_log));
scoped_refptr<GetProxyForURLJob> job(new GetProxyForURLJob(
url, network_isolation_key, results, std::move(callback), net_log));

// Completion will be notified through |callback|, unless the caller cancels
// the request using |request|.
Expand Down
Loading

0 comments on commit cd522ee

Please sign in to comment.