Commit 3b81bc1a authored by sammc's avatar sammc Committed by Commit bot

Add ProxyResolverFactoryV8Tracing.

This changes ProxyResolverV8Tracing to use the new ProxyResolver and
ProxyResolverFactory interfaces.

BUG=467403
NOPRESUBMIT=true

Review URL: https://codereview.chromium.org/1126513002

Cr-Commit-Position: refs/heads/master@{#330074}
parent c314676f
// Copyright 2015 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.
alert('Prepare to DIE!');
var x = null;
return x.split('-'); // Throws exception.
function FindProxyForURL(url, host) {
return "PROXY i-approve-this-message:42";
}
......@@ -10,6 +10,7 @@
#include "net/base/net_errors.h"
#include "net/dns/host_resolver_mojo.h"
#include "net/proxy/mojo_proxy_resolver_impl.h"
#include "net/proxy/proxy_resolver_error_observer.h"
#include "net/proxy/proxy_resolver_factory.h"
#include "net/proxy/proxy_resolver_v8.h"
#include "net/proxy/proxy_resolver_v8_tracing.h"
......@@ -18,30 +19,15 @@
namespace net {
namespace {
class DefaultProxyResolverFactory : public LegacyProxyResolverFactory {
public:
DefaultProxyResolverFactory(
HostResolver* host_resolver,
const ProxyResolver::LoadStateChangedCallback& callback)
: LegacyProxyResolverFactory(true),
host_resolver_(host_resolver),
callback_(callback) {}
scoped_ptr<ProxyResolver> CreateProxyResolver() override {
return make_scoped_ptr(new ProxyResolverV8Tracing(host_resolver_, nullptr,
nullptr, callback_));
}
private:
HostResolver* const host_resolver_;
const ProxyResolver::LoadStateChangedCallback callback_;
};
scoped_ptr<ProxyResolverErrorObserver> ReturnNullErrorObserver() {
return nullptr;
}
scoped_ptr<ProxyResolverFactory> CreateDefaultProxyResolver(
HostResolver* host_resolver,
const ProxyResolver::LoadStateChangedCallback& callback) {
return make_scoped_ptr(
new DefaultProxyResolverFactory(host_resolver, callback));
return make_scoped_ptr(new ProxyResolverFactoryV8Tracing(
host_resolver, nullptr, callback, base::Bind(&ReturnNullErrorObserver)));
}
class LoadStateChangeForwarder
......
......@@ -74,6 +74,14 @@ NetworkDelegateErrorObserver::~NetworkDelegateErrorObserver() {
core_->Shutdown();
}
// static
scoped_ptr<ProxyResolverErrorObserver> NetworkDelegateErrorObserver::Create(
NetworkDelegate* network_delegate,
const scoped_refptr<base::SingleThreadTaskRunner>& origin_runner) {
return make_scoped_ptr(
new NetworkDelegateErrorObserver(network_delegate, origin_runner.get()));
}
void NetworkDelegateErrorObserver::OnPACScriptError(
int line_number,
const base::string16& error) {
......
......@@ -7,6 +7,7 @@
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "net/proxy/proxy_resolver_error_observer.h"
namespace base {
......@@ -26,6 +27,10 @@ class NET_EXPORT_PRIVATE NetworkDelegateErrorObserver
base::SingleThreadTaskRunner* origin_runner);
~NetworkDelegateErrorObserver() override;
static scoped_ptr<ProxyResolverErrorObserver> Create(
NetworkDelegate* network_delegate,
const scoped_refptr<base::SingleThreadTaskRunner>& origin_runner);
// ProxyResolverErrorObserver implementation.
void OnPACScriptError(int line_number, const base::string16& error) override;
......
......@@ -4,6 +4,10 @@
#include "net/proxy/proxy_resolver_v8_tracing.h"
#include <map>
#include <string>
#include <vector>
#include "base/bind.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/stringprintf.h"
......@@ -64,10 +68,9 @@ base::Value* NetLogErrorCallback(int line_number,
return dict;
}
} // namespace
// The Job class is responsible for executing GetProxyForURL() and
// SetPacScript(), since both of these operations share similar code.
// creating ProxyResolverV8 instances, since both of these operations share
// similar code.
//
// The DNS for these operations can operate in either blocking or
// non-blocking mode. Blocking mode is used as a fallback when the PAC script
......@@ -80,17 +83,41 @@ base::Value* NetLogErrorCallback(int line_number,
// The lifetime of Jobs does not exceed that of the ProxyResolverV8Tracing that
// spawned it. Destruction might happen on either the origin thread or the
// worker thread.
class ProxyResolverV8Tracing::Job
: public base::RefCountedThreadSafe<ProxyResolverV8Tracing::Job>,
public ProxyResolverV8::JSBindings {
class Job : public base::RefCountedThreadSafe<Job>,
public ProxyResolverV8::JSBindings {
public:
// |parent| is non-owned. It is the ProxyResolverV8Tracing that spawned this
// Job, and must oulive it.
explicit Job(ProxyResolverV8Tracing* parent);
struct Params {
Params(
const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner,
HostResolver* host_resolver,
ProxyResolverErrorObserver* error_observer,
NetLog* net_log,
ProxyResolver::LoadStateChangedCallback on_load_state_changed,
int* num_outstanding_callbacks)
: v8_resolver(nullptr),
worker_task_runner(worker_task_runner),
host_resolver(host_resolver),
error_observer(error_observer),
net_log(net_log),
on_load_state_changed(on_load_state_changed),
num_outstanding_callbacks(num_outstanding_callbacks) {}
ProxyResolverV8* v8_resolver;
scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner;
HostResolver* host_resolver;
ProxyResolverErrorObserver* error_observer;
NetLog* net_log;
ProxyResolver::LoadStateChangedCallback on_load_state_changed;
int* num_outstanding_callbacks;
};
// |params| is non-owned. It contains the parameters for this Job, and must
// outlive it.
explicit Job(const Params* params);
// Called from origin thread.
void StartSetPacScript(
void StartCreateV8Resolver(
const scoped_refptr<ProxyResolverScriptData>& script_data,
scoped_ptr<ProxyResolverV8>* resolver,
const CompletionCallback& callback);
// Called from origin thread.
......@@ -107,10 +134,10 @@ class ProxyResolverV8Tracing::Job
private:
typedef std::map<std::string, std::string> DnsCache;
friend class base::RefCountedThreadSafe<ProxyResolverV8Tracing::Job>;
friend class base::RefCountedThreadSafe<Job>;
enum Operation {
SET_PAC_SCRIPT,
CREATE_V8_RESOLVER,
GET_PROXY_FOR_URL,
};
......@@ -129,7 +156,7 @@ class ProxyResolverV8Tracing::Job
void ReleaseCallback();
ProxyResolverV8* v8_resolver();
base::MessageLoop* worker_loop();
const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner();
HostResolver* host_resolver();
ProxyResolverErrorObserver* error_observer();
NetLog* net_log();
......@@ -203,9 +230,9 @@ class ProxyResolverV8Tracing::Job
// completion callback is expected to run.
scoped_refptr<base::SingleThreadTaskRunner> origin_runner_;
// The ProxyResolverV8Tracing which spawned this Job.
// The Parameters for this Job.
// Initialized on origin thread and then accessed from both threads.
ProxyResolverV8Tracing* parent_;
const Params* const params_;
// The callback to run (on the origin thread) when the Job finishes.
// Should only be accessed from origin thread.
......@@ -236,10 +263,11 @@ class ProxyResolverV8Tracing::Job
scoped_refptr<Job> owned_self_reference_;
// -------------------------------------------------------
// State specific to SET_PAC_SCRIPT.
// State specific to CREATE_V8_RESOLVER.
// -------------------------------------------------------
scoped_refptr<ProxyResolverScriptData> script_data_;
scoped_ptr<ProxyResolverV8>* resolver_out_;
// -------------------------------------------------------
// State specific to GET_PROXY_FOR_URL.
......@@ -295,34 +323,82 @@ class ProxyResolverV8Tracing::Job
AddressList pending_dns_addresses_;
};
ProxyResolverV8Tracing::Job::Job(ProxyResolverV8Tracing* parent)
class ProxyResolverV8Tracing : public ProxyResolver,
public base::NonThreadSafe {
public:
// Constructs a ProxyResolver that will issue DNS requests through
// |job_params->host_resolver|, forward Javascript errors through
// |error_observer|, and log Javascript errors and alerts to
// |job_params->net_log|. When the LoadState for a request changes,
// |job_params->on_load_state_changed| will be invoked with the RequestHandle
// for that request with the new LoadState.
//
// Note that the constructor takes ownership of |error_observer|, whereas
// |job_params->host_resolver| and |job_params->net_log| are expected to
// outlive |this|.
ProxyResolverV8Tracing(scoped_ptr<ProxyResolverErrorObserver> error_observer,
scoped_ptr<base::Thread> thread,
scoped_ptr<ProxyResolverV8> resolver,
scoped_ptr<Job::Params> job_params);
~ProxyResolverV8Tracing() override;
// ProxyResolver implementation:
int GetProxyForURL(const GURL& url,
ProxyInfo* results,
const CompletionCallback& callback,
RequestHandle* request,
const BoundNetLog& net_log) override;
void CancelRequest(RequestHandle request) override;
LoadState GetLoadState(RequestHandle request) const override;
void CancelSetPacScript() override;
int SetPacScript(const scoped_refptr<ProxyResolverScriptData>& script_data,
const CompletionCallback& callback) override;
private:
// The worker thread on which the ProxyResolverV8 will be run.
scoped_ptr<base::Thread> thread_;
scoped_ptr<ProxyResolverV8> v8_resolver_;
scoped_ptr<ProxyResolverErrorObserver> error_observer_;
scoped_ptr<Job::Params> job_params_;
// The number of outstanding (non-cancelled) jobs.
int num_outstanding_callbacks_;
DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8Tracing);
};
Job::Job(const Job::Params* params)
: origin_runner_(base::ThreadTaskRunnerHandle::Get()),
parent_(parent),
params_(params),
event_(true, false),
last_num_dns_(0),
pending_dns_(NULL) {
CheckIsOnOriginThread();
}
void ProxyResolverV8Tracing::Job::StartSetPacScript(
void Job::StartCreateV8Resolver(
const scoped_refptr<ProxyResolverScriptData>& script_data,
scoped_ptr<ProxyResolverV8>* resolver,
const CompletionCallback& callback) {
CheckIsOnOriginThread();
resolver_out_ = resolver;
script_data_ = script_data;
// Script initialization uses blocking DNS since there isn't any
// advantage to using non-blocking mode here. That is because the
// parent ProxyService can't submit any ProxyResolve requests until
// initialization has completed successfully!
Start(SET_PAC_SCRIPT, true /*blocking*/, callback);
Start(CREATE_V8_RESOLVER, true /*blocking*/, callback);
}
void ProxyResolverV8Tracing::Job::StartGetProxyForURL(
const GURL& url,
ProxyInfo* results,
const BoundNetLog& net_log,
const CompletionCallback& callback) {
void Job::StartGetProxyForURL(const GURL& url,
ProxyInfo* results,
const BoundNetLog& net_log,
const CompletionCallback& callback) {
CheckIsOnOriginThread();
url_ = url;
......@@ -332,7 +408,7 @@ void ProxyResolverV8Tracing::Job::StartGetProxyForURL(
Start(GET_PROXY_FOR_URL, false /*non-blocking*/, callback);
}
void ProxyResolverV8Tracing::Job::Cancel() {
void Job::Cancel() {
CheckIsOnOriginThread();
// There are several possibilities to consider for cancellation:
......@@ -367,7 +443,7 @@ void ProxyResolverV8Tracing::Job::Cancel() {
owned_self_reference_ = NULL;
}
LoadState ProxyResolverV8Tracing::Job::GetLoadState() const {
LoadState Job::GetLoadState() const {
CheckIsOnOriginThread();
if (pending_dns_)
......@@ -376,66 +452,65 @@ LoadState ProxyResolverV8Tracing::Job::GetLoadState() const {
return LOAD_STATE_RESOLVING_PROXY_FOR_URL;
}
ProxyResolverV8Tracing::Job::~Job() {
Job::~Job() {
DCHECK(!pending_dns_);
DCHECK(callback_.is_null());
}
void ProxyResolverV8Tracing::Job::CheckIsOnWorkerThread() const {
DCHECK_EQ(base::MessageLoop::current(), parent_->thread_->message_loop());
void Job::CheckIsOnWorkerThread() const {
DCHECK(params_->worker_task_runner->BelongsToCurrentThread());
}
void ProxyResolverV8Tracing::Job::CheckIsOnOriginThread() const {
void Job::CheckIsOnOriginThread() const {
DCHECK(origin_runner_->BelongsToCurrentThread());
}
void ProxyResolverV8Tracing::Job::SetCallback(
const CompletionCallback& callback) {
void Job::SetCallback(const CompletionCallback& callback) {
CheckIsOnOriginThread();
DCHECK(callback_.is_null());
parent_->num_outstanding_callbacks_++;
(*params_->num_outstanding_callbacks)++;
callback_ = callback;
}
void ProxyResolverV8Tracing::Job::ReleaseCallback() {
void Job::ReleaseCallback() {
CheckIsOnOriginThread();
DCHECK(!callback_.is_null());
CHECK_GT(parent_->num_outstanding_callbacks_, 0);
parent_->num_outstanding_callbacks_--;
CHECK_GT(*params_->num_outstanding_callbacks, 0);
(*params_->num_outstanding_callbacks)--;
callback_.Reset();
// For good measure, clear this other user-owned pointer.
user_results_ = NULL;
}
ProxyResolverV8* ProxyResolverV8Tracing::Job::v8_resolver() {
return parent_->v8_resolver_.get();
ProxyResolverV8* Job::v8_resolver() {
return params_->v8_resolver;
}
base::MessageLoop* ProxyResolverV8Tracing::Job::worker_loop() {
return parent_->thread_->message_loop();
const scoped_refptr<base::SingleThreadTaskRunner>& Job::worker_task_runner() {
return params_->worker_task_runner;
}
HostResolver* ProxyResolverV8Tracing::Job::host_resolver() {
return parent_->host_resolver_;
HostResolver* Job::host_resolver() {
return params_->host_resolver;
}
ProxyResolverErrorObserver* ProxyResolverV8Tracing::Job::error_observer() {
return parent_->error_observer_.get();
ProxyResolverErrorObserver* Job::error_observer() {
return params_->error_observer;
}
NetLog* ProxyResolverV8Tracing::Job::net_log() {
return parent_->net_log_;
NetLog* Job::net_log() {
return params_->net_log;
}
void ProxyResolverV8Tracing::Job::NotifyCaller(int result) {
void Job::NotifyCaller(int result) {
CheckIsOnWorkerThread();
origin_runner_->PostTask(
FROM_HERE, base::Bind(&Job::NotifyCallerOnOriginLoop, this, result));
}
void ProxyResolverV8Tracing::Job::NotifyCallerOnOriginLoop(int result) {
void Job::NotifyCallerOnOriginLoop(int result) {
CheckIsOnOriginThread();
if (cancelled_.IsSet())
......@@ -448,13 +523,6 @@ void ProxyResolverV8Tracing::Job::NotifyCallerOnOriginLoop(int result) {
*user_results_ = results_;
}
// There is only ever 1 outstanding SET_PAC_SCRIPT job. It needs to be
// tracked to support cancellation.
if (operation_ == SET_PAC_SCRIPT) {
DCHECK_EQ(parent_->set_pac_script_job_.get(), this);
parent_->set_pac_script_job_ = NULL;
}
CompletionCallback callback = callback_;
ReleaseCallback();
callback.Run(result);
......@@ -462,8 +530,9 @@ void ProxyResolverV8Tracing::Job::NotifyCallerOnOriginLoop(int result) {
owned_self_reference_ = NULL;
}
void ProxyResolverV8Tracing::Job::Start(Operation op, bool blocking_dns,
const CompletionCallback& callback) {
void Job::Start(Operation op,
bool blocking_dns,
const CompletionCallback& callback) {
CheckIsOnOriginThread();
operation_ = op;
......@@ -472,12 +541,12 @@ void ProxyResolverV8Tracing::Job::Start(Operation op, bool blocking_dns,
owned_self_reference_ = this;
worker_loop()->PostTask(FROM_HERE,
blocking_dns_ ? base::Bind(&Job::ExecuteBlocking, this) :
base::Bind(&Job::ExecuteNonBlocking, this));
worker_task_runner()->PostTask(
FROM_HERE, blocking_dns_ ? base::Bind(&Job::ExecuteBlocking, this)
: base::Bind(&Job::ExecuteNonBlocking, this));
}
void ProxyResolverV8Tracing::Job::ExecuteBlocking() {
void Job::ExecuteBlocking() {
CheckIsOnWorkerThread();
DCHECK(blocking_dns_);
......@@ -487,7 +556,7 @@ void ProxyResolverV8Tracing::Job::ExecuteBlocking() {
NotifyCaller(ExecuteProxyResolver());
}
void ProxyResolverV8Tracing::Job::ExecuteNonBlocking() {
void Job::ExecuteNonBlocking() {
CheckIsOnWorkerThread();
DCHECK(!blocking_dns_);
......@@ -518,18 +587,23 @@ void ProxyResolverV8Tracing::Job::ExecuteNonBlocking() {
NotifyCaller(result);
}
int ProxyResolverV8Tracing::Job::ExecuteProxyResolver() {
JSBindings* prev_bindings = v8_resolver()->js_bindings();
v8_resolver()->set_js_bindings(this);
int Job::ExecuteProxyResolver() {
int result = ERR_UNEXPECTED; // Initialized to silence warnings.
switch (operation_) {
case SET_PAC_SCRIPT:
result = v8_resolver()->SetPacScript(
script_data_, CompletionCallback());
case CREATE_V8_RESOLVER: {
scoped_ptr<ProxyResolverV8> resolver(new ProxyResolverV8);
resolver->set_js_bindings(this);
result = resolver->SetPacScript(script_data_, CompletionCallback());
resolver->set_js_bindings(nullptr);
if (result == OK)
*resolver_out_ = resolver.Pass();
break;
case GET_PROXY_FOR_URL:
}
case GET_PROXY_FOR_URL: {
JSBindings* prev_bindings = v8_resolver()->js_bindings();
v8_resolver()->set_js_bindings(this);
result = v8_resolver()->GetProxyForURL(
url_,
// Important: Do not write directly into |user_results_|, since if the
......@@ -539,18 +613,18 @@ int ProxyResolverV8Tracing::Job::ExecuteProxyResolver() {
CompletionCallback(),
NULL,
bound_net_log_);
v8_resolver()->set_js_bindings(prev_bindings);
break;
}
}
v8_resolver()->set_js_bindings(prev_bindings);
return result;
}
bool ProxyResolverV8Tracing::Job::ResolveDns(const std::string& host,
ResolveDnsOperation op,
std::string* output,
bool* terminate) {
bool Job::ResolveDns(const std::string& host,
ResolveDnsOperation op,
std::string* output,
bool* terminate) {
if (cancelled_.IsSet()) {
*terminate = true;
return false;
......@@ -566,18 +640,17 @@ bool ProxyResolverV8Tracing::Job::ResolveDns(const std::string& host,
ResolveDnsNonBlocking(host, op, output, terminate);
}
void ProxyResolverV8Tracing::Job::Alert(const base::string16& message) {
void Job::Alert(const base::string16& message) {
HandleAlertOrError(true, -1, message);
}
void ProxyResolverV8Tracing::Job::OnError(int line_number,
const base::string16& error) {
void Job::OnError(int line_number, const base::string16& error) {
HandleAlertOrError(false, line_number, error);
}
bool ProxyResolverV8Tracing::Job::ResolveDnsBlocking(const std::string& host,
ResolveDnsOperation op,
std::string* output) {
bool Job::ResolveDnsBlocking(const std::string& host,
ResolveDnsOperation op,
std::string* output) {
CheckIsOnWorkerThread();
// Check if the DNS result for this host has already been cached.
......@@ -601,10 +674,10 @@ bool ProxyResolverV8Tracing::Job::ResolveDnsBlocking(const std::string& host,
return rv;
}
bool ProxyResolverV8Tracing::Job::ResolveDnsNonBlocking(const std::string& host,
ResolveDnsOperation op,
std::string* output,
bool* terminate) {
bool Job::ResolveDnsNonBlocking(const std::string& host,
ResolveDnsOperation op,
std::string* output,
bool* terminate) {
CheckIsOnWorkerThread();
if (abandoned_) {
......@@ -654,10 +727,9 @@ bool ProxyResolverV8Tracing::Job::ResolveDnsNonBlocking(const std::string& host,
return false;
}
bool ProxyResolverV8Tracing::Job::PostDnsOperationAndWait(
const std::string& host, ResolveDnsOperation op,
bool* completed_synchronously) {
bool Job::PostDnsOperationAndWait(const std::string& host,
ResolveDnsOperation op,
bool* completed_synchronously) {
// Post the DNS request to the origin thread.
DCHECK(!pending_dns_);
pending_dns_host_ = host;
......@@ -676,7 +748,7 @@ bool ProxyResolverV8Tracing::Job::PostDnsOperationAndWait(
return true;
}
void ProxyResolverV8Tracing::Job::DoDnsOperation() {
void Job::DoDnsOperation() {
CheckIsOnOriginThread();
DCHECK(!pending_dns_);
......@@ -708,8 +780,8 @@ void ProxyResolverV8Tracing::Job::DoDnsOperation() {
} else {
DCHECK(dns_request);
pending_dns_ = dns_request;
if (!parent_->on_load_state_changed_.is_null()) {
parent_->on_load_state_changed_.Run(
if (!params_->on_load_state_changed.is_null()) {
params_->on_load_state_changed.Run(
this, LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT);
}
// OnDnsOperationComplete() will be called by host resolver on completion.
......@@ -722,7 +794,7 @@ void ProxyResolverV8Tracing::Job::DoDnsOperation() {
}
}
void ProxyResolverV8Tracing::Job::OnDnsOperationComplete(int result) {
void Job::OnDnsOperationComplete(int result) {
CheckIsOnOriginThread();
DCHECK(!cancelled_.IsSet());
......@@ -732,10 +804,10 @@ void ProxyResolverV8Tracing::Job::OnDnsOperationComplete(int result) {
pending_dns_addresses_);
pending_dns_ = NULL;
if (!parent_->on_load_state_changed_.is_null() &&
if (!params_->on_load_state_changed.is_null() &&
!pending_dns_completed_synchronously_ && !cancelled_.IsSet()) {
parent_->on_load_state_changed_.Run(this,
LOAD_STATE_RESOLVING_PROXY_FOR_URL);
params_->on_load_state_changed.Run(this,
LOAD_STATE_RESOLVING_PROXY_FOR_URL);
}
if (blocking_dns_) {
......@@ -746,12 +818,12 @@ void ProxyResolverV8Tracing::Job::OnDnsOperationComplete(int result) {
if (!blocking_dns_ && !pending_dns_completed_synchronously_) {
// Restart. This time it should make more progress due to having
// cached items.
worker_loop()->PostTask(FROM_HERE,
base::Bind(&Job::ExecuteNonBlocking, this));
worker_task_runner()->PostTask(FROM_HERE,
base::Bind(&Job::ExecuteNonBlocking, this));
}
}
void ProxyResolverV8Tracing::Job::ScheduleRestartWithBlockingDns() {
void Job::ScheduleRestartWithBlockingDns() {
CheckIsOnWorkerThread();
DCHECK(!should_restart_with_blocking_dns_);
......@@ -764,11 +836,10 @@ void ProxyResolverV8Tracing::Job::ScheduleRestartWithBlockingDns() {
should_restart_with_blocking_dns_ = true;
}
bool ProxyResolverV8Tracing::Job::GetDnsFromLocalCache(
const std::string& host,
ResolveDnsOperation op,
std::string* output,
bool* return_value) {
bool Job::GetDnsFromLocalCache(const std::string& host,
ResolveDnsOperation op,
std::string* output,
bool* return_value) {
CheckIsOnWorkerThread();
DnsCache::const_iterator it = dns_cache_.find(MakeDnsCacheKey(host, op));
......@@ -780,11 +851,10 @@ bool ProxyResolverV8Tracing::Job::GetDnsFromLocalCache(
return true;
}
void ProxyResolverV8Tracing::Job::SaveDnsToLocalCache(
const std::string& host,
ResolveDnsOperation op,
int net_error,
const AddressList& addresses) {
void Job::SaveDnsToLocalCache(const std::string& host,
ResolveDnsOperation op,
int net_error,
const AddressList& addresses) {
CheckIsOnOriginThread();
// Serialize the result into a string to save to the cache.
......@@ -809,8 +879,8 @@ void ProxyResolverV8Tracing::Job::SaveDnsToLocalCache(
}
// static
HostResolver::RequestInfo ProxyResolverV8Tracing::Job::MakeDnsRequestInfo(
const std::string& host, ResolveDnsOperation op) {
HostResolver::RequestInfo Job::MakeDnsRequestInfo(const std::string& host,
ResolveDnsOperation op) {
HostPortPair host_port = HostPortPair(host, 80);
if (op == MY_IP_ADDRESS || op == MY_IP_ADDRESS_EX) {
host_port.set_host(GetHostName());
......@@ -831,15 +901,14 @@ HostResolver::RequestInfo ProxyResolverV8Tracing::Job::MakeDnsRequestInfo(
return info;
}
std::string ProxyResolverV8Tracing::Job::MakeDnsCacheKey(
const std::string& host, ResolveDnsOperation op) {
std::string Job::MakeDnsCacheKey(const std::string& host,
ResolveDnsOperation op) {
return base::StringPrintf("%d:%s", op, host.c_str());
}
void ProxyResolverV8Tracing::Job::HandleAlertOrError(
bool is_alert,
int line_number,
const base::string16& message) {
void Job::HandleAlertOrError(bool is_alert,
int line_number,
const base::string16& message) {
CheckIsOnWorkerThread();
if (cancelled_.IsSet())
......@@ -871,7 +940,7 @@ void ProxyResolverV8Tracing::Job::HandleAlertOrError(
alerts_and_errors_.push_back(entry);
}
void ProxyResolverV8Tracing::Job::DispatchBufferedAlertsAndErrors() {
void Job::DispatchBufferedAlertsAndErrors() {
CheckIsOnWorkerThread();
DCHECK(!blocking_dns_);
DCHECK(!abandoned_);
......@@ -882,8 +951,9 @@ void ProxyResolverV8Tracing::Job::DispatchBufferedAlertsAndErrors() {
}
}
void ProxyResolverV8Tracing::Job::DispatchAlertOrError(
bool is_alert, int line_number, const base::string16& message) {
void Job::DispatchAlertOrError(bool is_alert,
int line_number,
const base::string16& message) {
CheckIsOnWorkerThread();
// Note that the handling of cancellation is racy with regard to
......@@ -925,7 +995,7 @@ void ProxyResolverV8Tracing::Job::DispatchAlertOrError(
}
}
void ProxyResolverV8Tracing::Job::LogEventToCurrentRequestAndGlobally(
void Job::LogEventToCurrentRequestAndGlobally(
NetLog::EventType type,
const NetLog::ParametersCallback& parameters_callback) {
CheckIsOnWorkerThread();
......@@ -937,46 +1007,26 @@ void ProxyResolverV8Tracing::Job::LogEventToCurrentRequestAndGlobally(
}
ProxyResolverV8Tracing::ProxyResolverV8Tracing(
HostResolver* host_resolver,
ProxyResolverErrorObserver* error_observer,
NetLog* net_log)
: ProxyResolverV8Tracing(host_resolver,
error_observer,
net_log,
LoadStateChangedCallback()) {
}
ProxyResolverV8Tracing::ProxyResolverV8Tracing(
HostResolver* host_resolver,
ProxyResolverErrorObserver* error_observer,
NetLog* net_log,
const LoadStateChangedCallback& on_load_state_changed)
scoped_ptr<ProxyResolverErrorObserver> error_observer,
scoped_ptr<base::Thread> thread,
scoped_ptr<ProxyResolverV8> resolver,
scoped_ptr<Job::Params> job_params)
: ProxyResolver(true /*expects_pac_bytes*/),
host_resolver_(host_resolver),
error_observer_(error_observer),
net_log_(net_log),
num_outstanding_callbacks_(0),
on_load_state_changed_(on_load_state_changed) {
DCHECK(host_resolver);
// Start up the thread.
thread_.reset(new base::Thread("Proxy resolver"));
base::Thread::Options options;
options.timer_slack = base::TIMER_SLACK_MAXIMUM;
CHECK(thread_->StartWithOptions(options));
v8_resolver_.reset(new ProxyResolverV8);
thread_(thread.Pass()),
v8_resolver_(resolver.Pass()),
error_observer_(error_observer.Pass()),
job_params_(job_params.Pass()),
num_outstanding_callbacks_(0) {
job_params_->num_outstanding_callbacks = &num_outstanding_callbacks_;
}
ProxyResolverV8Tracing::~ProxyResolverV8Tracing() {
// Note, all requests should have been cancelled.
CHECK(!set_pac_script_job_.get());
CHECK_EQ(0, num_outstanding_callbacks_);
// Join the worker thread. See http://crbug.com/69710. Note that we call
// Stop() here instead of simply clearing thread_ since there may be pending
// callbacks on the worker thread which want to dereference thread_.
// Join the worker thread. See http://crbug.com/69710.
base::ThreadRestrictions::ScopedAllowIO allow_io;
thread_->Stop();
thread_.reset();
}
int ProxyResolverV8Tracing::GetProxyForURL(const GURL& url,
......@@ -986,9 +1036,8 @@ int ProxyResolverV8Tracing::GetProxyForURL(const GURL& url,
const BoundNetLog& net_log) {
DCHECK(CalledOnValidThread());
DCHECK(!callback.is_null());
DCHECK(!set_pac_script_job_.get());
scoped_refptr<Job> job = new Job(this);
scoped_refptr<Job> job = new Job(job_params_.get());
if (request)
*request = job.get();
......@@ -1008,27 +1057,144 @@ LoadState ProxyResolverV8Tracing::GetLoadState(RequestHandle request) const {
}
void ProxyResolverV8Tracing::CancelSetPacScript() {
DCHECK(set_pac_script_job_.get());
set_pac_script_job_->Cancel();
set_pac_script_job_ = NULL;
NOTREACHED();
}
int ProxyResolverV8Tracing::SetPacScript(
const scoped_refptr<ProxyResolverScriptData>& script_data,
const CompletionCallback& callback) {
DCHECK(CalledOnValidThread());
DCHECK(!callback.is_null());
NOTREACHED();
return ERR_NOT_IMPLEMENTED;
}
// Note that there should not be any outstanding (non-cancelled) Jobs when
// setting the PAC script (ProxyService should guarantee this). If there are,
// then they might complete in strange ways after the new script is set.
DCHECK(!set_pac_script_job_.get());
CHECK_EQ(0, num_outstanding_callbacks_);
} // namespace
set_pac_script_job_ = new Job(this);
set_pac_script_job_->StartSetPacScript(script_data, callback);
class ProxyResolverFactoryV8Tracing::CreateJob
: public ProxyResolverFactory::Request {
public:
CreateJob(ProxyResolverFactoryV8Tracing* factory,
HostResolver* host_resolver,
scoped_ptr<ProxyResolverErrorObserver> error_observer,
NetLog* net_log,
const ProxyResolver::LoadStateChangedCallback&
load_state_changed_callback,
const scoped_refptr<ProxyResolverScriptData>& pac_script,
scoped_ptr<ProxyResolver>* resolver_out,
const CompletionCallback& callback)
: factory_(factory),
thread_(new base::Thread("Proxy Resolver")),
error_observer_(error_observer.Pass()),
resolver_out_(resolver_out),
callback_(callback),
num_outstanding_callbacks_(0) {
// Start up the thread.
base::Thread::Options options;
options.timer_slack = base::TIMER_SLACK_MAXIMUM;
CHECK(thread_->StartWithOptions(options));
job_params_.reset(new Job::Params(
thread_->task_runner(), host_resolver, error_observer_.get(), net_log,
load_state_changed_callback, &num_outstanding_callbacks_));
create_resolver_job_ = new Job(job_params_.get());
create_resolver_job_->StartCreateV8Resolver(
pac_script, &v8_resolver_,
base::Bind(
&ProxyResolverFactoryV8Tracing::CreateJob::OnV8ResolverCreated,
base::Unretained(this)));
}
~CreateJob() override {
if (factory_) {
factory_->RemoveJob(this);
DCHECK(create_resolver_job_);
create_resolver_job_->Cancel();
StopWorkerThread();
}
DCHECK_EQ(0, num_outstanding_callbacks_);
}
void FactoryDestroyed() {
factory_ = nullptr;
create_resolver_job_->Cancel();
create_resolver_job_ = nullptr;
StopWorkerThread();
}
private:
void OnV8ResolverCreated(int error) {
DCHECK(factory_);
if (error == OK) {
job_params_->v8_resolver = v8_resolver_.get();
resolver_out_->reset(
new ProxyResolverV8Tracing(error_observer_.Pass(), thread_.Pass(),
v8_resolver_.Pass(), job_params_.Pass()));
} else {
StopWorkerThread();
}
factory_->RemoveJob(this);
factory_ = nullptr;
create_resolver_job_ = nullptr;
callback_.Run(error);
}
void StopWorkerThread() {
// Join the worker thread. See http://crbug.com/69710.
base::ThreadRestrictions::ScopedAllowIO allow_io;
thread_.reset();
}
ProxyResolverFactoryV8Tracing* factory_;
scoped_ptr<base::Thread> thread_;
scoped_ptr<ProxyResolverErrorObserver> error_observer_;
scoped_ptr<Job::Params> job_params_;
scoped_refptr<Job> create_resolver_job_;
scoped_ptr<ProxyResolverV8> v8_resolver_;
scoped_ptr<ProxyResolver>* resolver_out_;
const CompletionCallback callback_;
int num_outstanding_callbacks_;
DISALLOW_COPY_AND_ASSIGN(CreateJob);
};
ProxyResolverFactoryV8Tracing::ProxyResolverFactoryV8Tracing(
HostResolver* host_resolver,
NetLog* net_log,
const ProxyResolver::LoadStateChangedCallback& callback,
const base::Callback<scoped_ptr<ProxyResolverErrorObserver>()>&
error_observer_factory)
: ProxyResolverFactory(true),
host_resolver_(host_resolver),
net_log_(net_log),
load_state_changed_callback_(callback),
error_observer_factory_(error_observer_factory) {
}
ProxyResolverFactoryV8Tracing::~ProxyResolverFactoryV8Tracing() {
for (auto job : jobs_) {
job->FactoryDestroyed();
}
}
// ProxyResolverFactory override.
int ProxyResolverFactoryV8Tracing::CreateProxyResolver(
const scoped_refptr<ProxyResolverScriptData>& pac_script,
scoped_ptr<ProxyResolver>* resolver,
const CompletionCallback& callback,
scoped_ptr<Request>* request) {
scoped_ptr<CreateJob> job(new CreateJob(
this, host_resolver_,
error_observer_factory_.is_null() ? nullptr
: error_observer_factory_.Run(),
net_log_, load_state_changed_callback_, pac_script, resolver, callback));
jobs_.insert(job.get());
*request = job.Pass();
return ERR_IO_PENDING;
}
void ProxyResolverFactoryV8Tracing::RemoveJob(
ProxyResolverFactoryV8Tracing::CreateJob* job) {
size_t erased = jobs_.erase(job);
DCHECK_EQ(1u, erased);
}
} // namespace net
......@@ -5,93 +5,62 @@
#ifndef NET_PROXY_PROXY_RESOLVER_V8_TRACING_H_
#define NET_PROXY_PROXY_RESOLVER_V8_TRACING_H_
#include <set>
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/non_thread_safe.h"
#include "net/base/net_export.h"
#include "net/proxy/proxy_resolver.h"
namespace base {
class Thread;
class SingleThreadTaskRunner;
} // namespace base
#include "net/proxy/proxy_resolver_factory.h"
namespace net {
class HostResolver;
class NetLog;
class ProxyResolverErrorObserver;
class ProxyResolverV8;
// ProxyResolverV8Tracing is a non-blocking ProxyResolver. It executes
// ProxyResolverFactoryV8Tracing is a ProxyResolverFactory that returns
// non-blocking ProxyResolver instances. Each ProxyResolver instance executes
// ProxyResolverV8 on a single helper thread, and does some magic to avoid
// blocking in DNS. For more details see the design document:
// https://docs.google.com/a/google.com/document/d/16Ij5OcVnR3s0MH4Z5XkhI9VTPoMJdaBn9rKreAmGOdE/edit?pli=1
class NET_EXPORT_PRIVATE ProxyResolverV8Tracing
: public ProxyResolver,
NON_EXPORTED_BASE(public base::NonThreadSafe) {
class NET_EXPORT ProxyResolverFactoryV8Tracing : public ProxyResolverFactory {
public:
// Constructs a ProxyResolver that will issue DNS requests through
// |host_resolver|, forward Javascript errors through |error_observer|, and
// log Javascript errors and alerts to |net_log|.
//
// Note that the constructor takes ownership of |error_observer|, whereas
// |host_resolver| and |net_log| are expected to outlive |this|.
ProxyResolverV8Tracing(HostResolver* host_resolver,
ProxyResolverErrorObserver* error_observer,
NetLog* net_log);
// Constructs a ProxyResolver that will issue DNS requests through
// |host_resolver|, forward Javascript errors through |error_observer|, and
// log Javascript errors and alerts to |net_log|. When the LoadState for a
// request changes, |on_load_state_changed| will be invoked with the
// RequestHandle for that request with the new LoadState.
//
// Note that the constructor takes ownership of |error_observer|, whereas
// |host_resolver| and |net_log| are expected to outlive |this|.
ProxyResolverV8Tracing(HostResolver* host_resolver,
ProxyResolverErrorObserver* error_observer,
NetLog* net_log,
const LoadStateChangedCallback& on_load_state_changed);
~ProxyResolverV8Tracing() override;
// ProxyResolver implementation:
int GetProxyForURL(const GURL& url,
ProxyInfo* results,
const CompletionCallback& callback,
RequestHandle* request,
const BoundNetLog& net_log) override;
void CancelRequest(RequestHandle request) override;
LoadState GetLoadState(RequestHandle request) const override;
void CancelSetPacScript() override;
int SetPacScript(const scoped_refptr<ProxyResolverScriptData>& script_data,
const CompletionCallback& callback) override;
// Note that |host_resolver| and |net_log| are expected to outlive |this| and
// any ProxyResolver instances created using |this|. |error_observer_factory|
// will be invoked once per CreateProxyResolver() call to create a
// ProxyResolverErrorObserver to be used by the ProxyResolver instance
// returned by that call.
ProxyResolverFactoryV8Tracing(
HostResolver* host_resolver,
NetLog* net_log,
const ProxyResolver::LoadStateChangedCallback& callback,
const base::Callback<scoped_ptr<ProxyResolverErrorObserver>()>&
error_observer_factory);
~ProxyResolverFactoryV8Tracing() override;
// ProxyResolverFactory override.
int CreateProxyResolver(
const scoped_refptr<ProxyResolverScriptData>& pac_script,
scoped_ptr<ProxyResolver>* resolver,
const CompletionCallback& callback,
scoped_ptr<Request>* request) override;
private:
class Job;
// The worker thread on which the ProxyResolverV8 will be run.
scoped_ptr<base::Thread> thread_;
scoped_ptr<ProxyResolverV8> v8_resolver_;
// Non-owned host resolver, which is to be operated on the origin thread.
HostResolver* host_resolver_;
scoped_ptr<ProxyResolverErrorObserver> error_observer_;
NetLog* net_log_;
class CreateJob;
// The outstanding SetPacScript operation, or NULL.
scoped_refptr<Job> set_pac_script_job_;
void RemoveJob(CreateJob* job);
// The number of outstanding (non-cancelled) jobs.
int num_outstanding_callbacks_;
HostResolver* const host_resolver_;
NetLog* const net_log_;
const ProxyResolver::LoadStateChangedCallback load_state_changed_callback_;
const base::Callback<scoped_ptr<ProxyResolverErrorObserver>()>
error_observer_factory_;
// Invoked when the load state for a request changes.
const LoadStateChangedCallback on_load_state_changed_;
std::set<CreateJob*> jobs_;
DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8Tracing);
DISALLOW_COPY_AND_ASSIGN(ProxyResolverFactoryV8Tracing);
};
} // namespace net
......
......@@ -4,6 +4,8 @@
#include "net/proxy/proxy_resolver_v8_tracing.h"
#include <string>
#include "base/files/file_util.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
......@@ -60,12 +62,28 @@ scoped_refptr<ProxyResolverScriptData> LoadScriptData(const char* filename) {
return ProxyResolverScriptData::FromUTF8(file_contents);
}
void InitResolver(ProxyResolverV8Tracing* resolver, const char* filename) {
scoped_ptr<ProxyResolverErrorObserver> ReturnErrorObserver(
scoped_ptr<ProxyResolverErrorObserver> error_observer) {
return error_observer;
}
scoped_ptr<ProxyResolver> CreateResolver(
NetLog* net_log,
HostResolver* host_resolver,
scoped_ptr<ProxyResolverErrorObserver> error_observer,
const char* filename) {
scoped_ptr<ProxyResolver> resolver;
ProxyResolverFactoryV8Tracing factory(
host_resolver, net_log, ProxyResolver::LoadStateChangedCallback(),
base::Bind(&ReturnErrorObserver, base::Passed(&error_observer)));
TestCompletionCallback callback;
int rv =
resolver->SetPacScript(LoadScriptData(filename), callback.callback());
scoped_ptr<ProxyResolverFactory::Request> request;
int rv = factory.CreateProxyResolver(LoadScriptData(filename), &resolver,
callback.callback(), &request);
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
EXPECT_TRUE(resolver);
return resolver.Pass();
}
class MockErrorObserver : public ProxyResolverErrorObserver {
......@@ -102,16 +120,16 @@ TEST_F(ProxyResolverV8TracingTest, Simple) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
InitResolver(&resolver, "simple.js");
scoped_ptr<ProxyResolver> resolver = CreateResolver(
&log, &host_resolver, make_scoped_ptr(error_observer), "simple.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
int rv = resolver.GetProxyForURL(
GURL("http://foo/"), &proxy_info, callback.callback(),
NULL, request_log.bound());
int rv =
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
......@@ -133,16 +151,16 @@ TEST_F(ProxyResolverV8TracingTest, JavascriptError) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
InitResolver(&resolver, "error.js");
scoped_ptr<ProxyResolver> resolver = CreateResolver(
&log, &host_resolver, make_scoped_ptr(error_observer), "error.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
int rv = resolver.GetProxyForURL(
GURL("http://throw-an-error/"), &proxy_info, callback.callback(), NULL,
request_log.bound());
int rv =
resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info,
callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult());
......@@ -179,19 +197,17 @@ TEST_F(ProxyResolverV8TracingTest, TooManyAlerts) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
InitResolver(&resolver, "too_many_alerts.js");
scoped_ptr<ProxyResolver> resolver =
CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
"too_many_alerts.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
int rv = resolver.GetProxyForURL(
GURL("http://foo/"),
&proxy_info,
callback.callback(),
NULL,
request_log.bound());
int rv =
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
......@@ -230,19 +246,17 @@ TEST_F(ProxyResolverV8TracingTest, TooManyEmptyAlerts) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
InitResolver(&resolver, "too_many_empty_alerts.js");
scoped_ptr<ProxyResolver> resolver =
CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
"too_many_empty_alerts.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
int rv = resolver.GetProxyForURL(
GURL("http://foo/"),
&proxy_info,
callback.callback(),
NULL,
request_log.bound());
int rv =
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
......@@ -279,7 +293,6 @@ TEST_F(ProxyResolverV8TracingTest, Dns) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
host_resolver.rules()->AddRuleForAddressFamily(
"host1", ADDRESS_FAMILY_IPV4, "166.155.144.44");
......@@ -293,17 +306,15 @@ TEST_F(ProxyResolverV8TracingTest, Dns) {
"*", ADDRESS_FAMILY_IPV4, "122.133.144.155");
host_resolver.rules()->AddRule("*", "133.122.100.200");
InitResolver(&resolver, "dns.js");
scoped_ptr<ProxyResolver> resolver = CreateResolver(
&log, &host_resolver, make_scoped_ptr(error_observer), "dns.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
int rv = resolver.GetProxyForURL(
GURL("http://foo/"),
&proxy_info,
callback.callback(),
NULL,
request_log.bound());
int rv =
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
......@@ -356,23 +367,20 @@ TEST_F(ProxyResolverV8TracingTest, DnsChecksCache) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
host_resolver.rules()->AddRule("foopy", "166.155.144.11");
host_resolver.rules()->AddRule("*", "122.133.144.155");
InitResolver(&resolver, "simple_dns.js");
scoped_ptr<ProxyResolver> resolver = CreateResolver(
&log, &host_resolver, make_scoped_ptr(error_observer), "simple_dns.js");
TestCompletionCallback callback1;
TestCompletionCallback callback2;
ProxyInfo proxy_info;
int rv = resolver.GetProxyForURL(
GURL("http://foopy/req1"),
&proxy_info,
callback1.callback(),
NULL,
request_log.bound());
int rv =
resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info,
callback1.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback1.WaitForResult());
......@@ -383,12 +391,9 @@ TEST_F(ProxyResolverV8TracingTest, DnsChecksCache) {
// The first request took 2 restarts, hence on g_iteration=3.
EXPECT_EQ("166.155.144.11:3", proxy_info.proxy_server().ToURI());
rv = resolver.GetProxyForURL(
GURL("http://foopy/req2"),
&proxy_info,
callback2.callback(),
NULL,
request_log.bound());
rv =
resolver->GetProxyForURL(GURL("http://foopy/req2"), &proxy_info,
callback2.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback2.WaitForResult());
......@@ -413,20 +418,21 @@ TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous1) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
host_resolver.rules()->AddRule("host1", "166.155.144.11");
host_resolver.rules()->AddRule("crazy4", "133.199.111.4");
host_resolver.rules()->AddRule("*", "122.133.144.155");
InitResolver(&resolver, "global_sideffects1.js");
scoped_ptr<ProxyResolver> resolver =
CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
"global_sideffects1.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
int rv = resolver.GetProxyForURL(
GURL("http://foo/"), &proxy_info, callback.callback(), NULL,
request_log.bound());
int rv =
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
......@@ -465,7 +471,6 @@ TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous2) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
host_resolver.rules()->AddRule("host1", "166.155.144.11");
host_resolver.rules()->AddRule("host2", "166.155.144.22");
......@@ -473,14 +478,16 @@ TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous2) {
host_resolver.rules()->AddRule("host4", "166.155.144.44");
host_resolver.rules()->AddRule("*", "122.133.144.155");
InitResolver(&resolver, "global_sideffects2.js");
scoped_ptr<ProxyResolver> resolver =
CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
"global_sideffects2.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
int rv = resolver.GetProxyForURL(
GURL("http://foo/"), &proxy_info, callback.callback(), NULL,
request_log.bound());
int rv =
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
......@@ -505,19 +512,20 @@ TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
host_resolver.rules()->AddRule("host*", "166.155.144.11");
host_resolver.rules()->AddRule("*", "122.133.144.155");
InitResolver(&resolver, "global_sideffects3.js");
scoped_ptr<ProxyResolver> resolver =
CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
"global_sideffects3.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
int rv = resolver.GetProxyForURL(
GURL("http://foo/"), &proxy_info, callback.callback(), NULL,
request_log.bound());
int rv =
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
......@@ -548,19 +556,20 @@ TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence2) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
host_resolver.rules()->AddRule("host*", "166.155.144.11");
host_resolver.rules()->AddRule("*", "122.133.144.155");
InitResolver(&resolver, "global_sideffects4.js");
scoped_ptr<ProxyResolver> resolver =
CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
"global_sideffects4.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
int rv = resolver.GetProxyForURL(
GURL("http://foo/"), &proxy_info, callback.callback(), NULL,
request_log.bound());
int rv =
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
......@@ -582,12 +591,13 @@ void DnsDuringInitHelper(bool synchronous_host_resolver) {
MockCachingHostResolver host_resolver;
host_resolver.set_synchronous_mode(synchronous_host_resolver);
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
host_resolver.rules()->AddRule("host1", "91.13.12.1");
host_resolver.rules()->AddRule("host2", "91.13.12.2");
InitResolver(&resolver, "dns_during_init.js");
scoped_ptr<ProxyResolver> resolver =
CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
"dns_during_init.js");
// Initialization did 2 dnsResolves.
EXPECT_EQ(2u, host_resolver.num_resolve());
......@@ -601,9 +611,9 @@ void DnsDuringInitHelper(bool synchronous_host_resolver) {
TestCompletionCallback callback;
ProxyInfo proxy_info;
int rv = resolver.GetProxyForURL(
GURL("http://foo/"), &proxy_info, callback.callback(), NULL,
request_log.bound());
int rv =
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
......@@ -651,25 +661,25 @@ void CrashCallback(int) {
TEST_F(ProxyResolverV8TracingTest, CancelAll) {
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL);
host_resolver.rules()->AddSimulatedFailure("*");
InitResolver(&resolver, "dns.js");
scoped_ptr<ProxyResolver> resolver = CreateResolver(
nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js");
const size_t kNumRequests = 5;
ProxyInfo proxy_info[kNumRequests];
ProxyResolver::RequestHandle request[kNumRequests];
for (size_t i = 0; i < kNumRequests; ++i) {
int rv = resolver.GetProxyForURL(
GURL("http://foo/"), &proxy_info[i],
base::Bind(&CrashCallback), &request[i], BoundNetLog());
int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info[i],
base::Bind(&CrashCallback), &request[i],
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
}
for (size_t i = 0; i < kNumRequests; ++i) {
resolver.CancelRequest(request[i]);
resolver->CancelRequest(request[i]);
}
}
......@@ -679,11 +689,11 @@ TEST_F(ProxyResolverV8TracingTest, CancelAll) {
TEST_F(ProxyResolverV8TracingTest, CancelSome) {
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL);
host_resolver.rules()->AddSimulatedFailure("*");
InitResolver(&resolver, "dns.js");
scoped_ptr<ProxyResolver> resolver = CreateResolver(
nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js");
ProxyInfo proxy_info1;
ProxyInfo proxy_info2;
......@@ -691,17 +701,16 @@ TEST_F(ProxyResolverV8TracingTest, CancelSome) {
ProxyResolver::RequestHandle request2;
TestCompletionCallback callback;
int rv = resolver.GetProxyForURL(
GURL("http://foo/"), &proxy_info1,
base::Bind(&CrashCallback), &request1, BoundNetLog());
int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info1,
base::Bind(&CrashCallback), &request1,
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = resolver.GetProxyForURL(
GURL("http://foo/"), &proxy_info2,
callback.callback(), &request2, BoundNetLog());
rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info2,
callback.callback(), &request2, BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
resolver.CancelRequest(request1);
resolver->CancelRequest(request1);
EXPECT_EQ(OK, callback.WaitForResult());
}
......@@ -711,11 +720,11 @@ TEST_F(ProxyResolverV8TracingTest, CancelSome) {
TEST_F(ProxyResolverV8TracingTest, CancelWhilePendingCompletionTask) {
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL);
host_resolver.rules()->AddSimulatedFailure("*");
InitResolver(&resolver, "error.js");
scoped_ptr<ProxyResolver> resolver = CreateResolver(
nullptr, &host_resolver, make_scoped_ptr(error_observer), "error.js");
ProxyInfo proxy_info1;
ProxyInfo proxy_info2;
......@@ -725,14 +734,13 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhilePendingCompletionTask) {
ProxyResolver::RequestHandle request3;
TestCompletionCallback callback;
int rv = resolver.GetProxyForURL(
GURL("http://foo/"), &proxy_info1,
base::Bind(&CrashCallback), &request1, BoundNetLog());
int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info1,
base::Bind(&CrashCallback), &request1,
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
rv = resolver.GetProxyForURL(
GURL("http://throw-an-error/"), &proxy_info2,
callback.callback(), &request2, BoundNetLog());
rv = resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info2,
callback.callback(), &request2, BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
// Wait until the first request has finished running on the worker thread.
......@@ -741,14 +749,14 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhilePendingCompletionTask) {
// Cancel the first request, while it has a pending completion task on
// the origin thread.
resolver.CancelRequest(request1);
resolver->CancelRequest(request1);
EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult());
// Start another request, to make sure it is able to complete.
rv = resolver.GetProxyForURL(
GURL("http://i-have-no-idea-what-im-doing/"), &proxy_info3,
callback.callback(), &request3, BoundNetLog());
rv = resolver->GetProxyForURL(GURL("http://i-have-no-idea-what-im-doing/"),
&proxy_info3, callback.callback(), &request3,
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
......@@ -829,33 +837,33 @@ class BlockableHostResolver : public HostResolver {
TEST_F(ProxyResolverV8TracingTest, CancelWhileOutstandingNonBlockingDns) {
BlockableHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL);
InitResolver(&resolver, "dns.js");
scoped_ptr<ProxyResolver> resolver = CreateResolver(
nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js");
ProxyInfo proxy_info1;
ProxyInfo proxy_info2;
ProxyResolver::RequestHandle request1;
ProxyResolver::RequestHandle request2;
int rv = resolver.GetProxyForURL(
GURL("http://foo/req1"), &proxy_info1,
base::Bind(&CrashCallback), &request1, BoundNetLog());
int rv = resolver->GetProxyForURL(GURL("http://foo/req1"), &proxy_info1,
base::Bind(&CrashCallback), &request1,
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
host_resolver.WaitUntilRequestIsReceived();
rv = resolver.GetProxyForURL(
GURL("http://foo/req2"), &proxy_info2,
base::Bind(&CrashCallback), &request2, BoundNetLog());
rv = resolver->GetProxyForURL(GURL("http://foo/req2"), &proxy_info2,
base::Bind(&CrashCallback), &request2,
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
host_resolver.WaitUntilRequestIsReceived();
resolver.CancelRequest(request1);
resolver.CancelRequest(request2);
resolver->CancelRequest(request1);
resolver->CancelRequest(request2);
EXPECT_EQ(2, host_resolver.num_cancelled_requests());
......@@ -864,7 +872,7 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhileOutstandingNonBlockingDns) {
// should have been cancelled.
}
void CancelRequestAndPause(ProxyResolverV8Tracing* resolver,
void CancelRequestAndPause(ProxyResolver* resolver,
ProxyResolver::RequestHandle request) {
resolver->CancelRequest(request);
......@@ -880,21 +888,21 @@ void CancelRequestAndPause(ProxyResolverV8Tracing* resolver,
TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns) {
BlockableHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL);
InitResolver(&resolver, "dns.js");
scoped_ptr<ProxyResolver> resolver = CreateResolver(
nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js");
ProxyInfo proxy_info;
ProxyResolver::RequestHandle request;
int rv = resolver.GetProxyForURL(
GURL("http://foo/"), &proxy_info,
base::Bind(&CrashCallback), &request, BoundNetLog());
int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
base::Bind(&CrashCallback), &request,
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
host_resolver.SetAction(
base::Bind(CancelRequestAndPause, &resolver, request));
base::Bind(CancelRequestAndPause, resolver.get(), request));
host_resolver.WaitUntilRequestIsReceived();
......@@ -909,16 +917,16 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns) {
TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns2) {
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL);
InitResolver(&resolver, "dns.js");
scoped_ptr<ProxyResolver> resolver = CreateResolver(
nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js");
ProxyInfo proxy_info;
ProxyResolver::RequestHandle request;
int rv = resolver.GetProxyForURL(
GURL("http://foo/"), &proxy_info,
base::Bind(&CrashCallback), &request, BoundNetLog());
int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
base::Bind(&CrashCallback), &request,
BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
......@@ -926,28 +934,75 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns2) {
// work whatever the delay is here, but it is most useful if the delay
// is large enough to allow a task to be posted back.
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
resolver.CancelRequest(request);
resolver->CancelRequest(request);
EXPECT_EQ(0u, host_resolver.num_resolve());
}
TEST_F(ProxyResolverV8TracingTest, CancelSetPacWhileOutstandingBlockingDns) {
TEST_F(ProxyResolverV8TracingTest,
CancelCreateResolverWhileOutstandingBlockingDns) {
BlockableHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL);
ProxyResolverFactoryV8Tracing factory(
&host_resolver, nullptr, ProxyResolver::LoadStateChangedCallback(),
base::Bind(&ReturnErrorObserver,
base::Passed(make_scoped_ptr(error_observer))));
int rv =
resolver.SetPacScript(LoadScriptData("dns_during_init.js"),
base::Bind(&CrashCallback));
scoped_ptr<ProxyResolver> resolver;
scoped_ptr<ProxyResolverFactory::Request> request;
int rv = factory.CreateProxyResolver(LoadScriptData("dns_during_init.js"),
&resolver, base::Bind(&CrashCallback),
&request);
EXPECT_EQ(ERR_IO_PENDING, rv);
host_resolver.WaitUntilRequestIsReceived();
resolver.CancelSetPacScript();
request.reset();
EXPECT_EQ(1, host_resolver.num_cancelled_requests());
}
TEST_F(ProxyResolverV8TracingTest, DeleteFactoryWhileOutstandingBlockingDns) {
BlockableHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
scoped_ptr<ProxyResolver> resolver;
scoped_ptr<ProxyResolverFactory::Request> request;
{
ProxyResolverFactoryV8Tracing factory(
&host_resolver, nullptr, ProxyResolver::LoadStateChangedCallback(),
base::Bind(&ReturnErrorObserver,
base::Passed(make_scoped_ptr(error_observer))));
int rv = factory.CreateProxyResolver(LoadScriptData("dns_during_init.js"),
&resolver, base::Bind(&CrashCallback),
&request);
EXPECT_EQ(ERR_IO_PENDING, rv);
host_resolver.WaitUntilRequestIsReceived();
}
EXPECT_EQ(1, host_resolver.num_cancelled_requests());
}
TEST_F(ProxyResolverV8TracingTest, ErrorLoadingScript) {
BlockableHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverFactoryV8Tracing factory(
&host_resolver, nullptr, ProxyResolver::LoadStateChangedCallback(),
base::Bind(&ReturnErrorObserver,
base::Passed(make_scoped_ptr(error_observer))));
scoped_ptr<ProxyResolver> resolver;
scoped_ptr<ProxyResolverFactory::Request> request;
TestCompletionCallback callback;
int rv =
factory.CreateProxyResolver(LoadScriptData("error_on_load.js"), &resolver,
callback.callback(), &request);
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult());
EXPECT_FALSE(resolver);
}
// This tests that the execution of a PAC script is terminated when the DNS
// dependencies are missing. If the test fails, then it will hang.
TEST_F(ProxyResolverV8TracingTest, Terminate) {
......@@ -955,22 +1010,19 @@ TEST_F(ProxyResolverV8TracingTest, Terminate) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
host_resolver.rules()->AddRule("host1", "182.111.0.222");
host_resolver.rules()->AddRule("host2", "111.33.44.55");
InitResolver(&resolver, "terminate.js");
scoped_ptr<ProxyResolver> resolver = CreateResolver(
&log, &host_resolver, make_scoped_ptr(error_observer), "terminate.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
int rv = resolver.GetProxyForURL(
GURL("http://foopy/req1"),
&proxy_info,
callback.callback(),
NULL,
request_log.bound());
int rv =
resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info,
callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
......@@ -1007,39 +1059,39 @@ TEST_F(ProxyResolverV8TracingTest, MultipleResolvers) {
host_resolver0.rules()->AddRuleForAddressFamily(
"*", ADDRESS_FAMILY_IPV4, "122.133.144.155");
host_resolver0.rules()->AddRule("*", "133.122.100.200");
ProxyResolverV8Tracing resolver0(
&host_resolver0, new MockErrorObserver, NULL);
InitResolver(&resolver0, "dns.js");
scoped_ptr<ProxyResolver> resolver0 =
CreateResolver(nullptr, &host_resolver0,
make_scoped_ptr(new MockErrorObserver), "dns.js");
// ------------------------
// Setup resolver1
// ------------------------
ProxyResolverV8Tracing resolver1(
&host_resolver0, new MockErrorObserver, NULL);
InitResolver(&resolver1, "dns.js");
scoped_ptr<ProxyResolver> resolver1 =
CreateResolver(nullptr, &host_resolver0,
make_scoped_ptr(new MockErrorObserver), "dns.js");
// ------------------------
// Setup resolver2
// ------------------------
ProxyResolverV8Tracing resolver2(
&host_resolver0, new MockErrorObserver, NULL);
InitResolver(&resolver2, "simple.js");
scoped_ptr<ProxyResolver> resolver2 =
CreateResolver(nullptr, &host_resolver0,
make_scoped_ptr(new MockErrorObserver), "simple.js");
// ------------------------
// Setup resolver3
// ------------------------
MockHostResolver host_resolver3;
host_resolver3.rules()->AddRule("foo", "166.155.144.33");
ProxyResolverV8Tracing resolver3(
&host_resolver3, new MockErrorObserver, NULL);
InitResolver(&resolver3, "simple_dns.js");
scoped_ptr<ProxyResolver> resolver3 =
CreateResolver(nullptr, &host_resolver3,
make_scoped_ptr(new MockErrorObserver), "simple_dns.js");
// ------------------------
// Queue up work for each resolver (which will be running in parallel).
// ------------------------
ProxyResolverV8Tracing* resolver[] = {
&resolver0, &resolver1, &resolver2, &resolver3,
ProxyResolver* resolver[] = {
resolver0.get(), resolver1.get(), resolver2.get(), resolver3.get(),
};
const size_t kNumResolvers = arraysize(resolver);
......
......@@ -14,38 +14,6 @@
#include "net/proxy/proxy_service.h"
namespace net {
namespace {
class ProxyResolverFactoryForV8Resolver : public LegacyProxyResolverFactory {
public:
explicit ProxyResolverFactoryForV8Resolver(HostResolver* host_resolver,
NetLog* net_log,
NetworkDelegate* network_delegate)
: LegacyProxyResolverFactory(true),
host_resolver_(host_resolver),
net_log_(net_log),
network_delegate_(network_delegate) {}
// LegacyProxyResolverFactory override.
scoped_ptr<ProxyResolver> CreateProxyResolver() override {
DCHECK(thread_checker_.CalledOnValidThread());
ProxyResolverErrorObserver* error_observer =
new NetworkDelegateErrorObserver(
network_delegate_, base::ThreadTaskRunnerHandle::Get().get());
return make_scoped_ptr(
new ProxyResolverV8Tracing(host_resolver_, error_observer, net_log_));
}
private:
HostResolver* const host_resolver_;
NetLog* const net_log_;
NetworkDelegate* const network_delegate_;
base::ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(ProxyResolverFactoryForV8Resolver);
};
} // namespace
// static
ProxyService* CreateProxyServiceUsingV8ProxyResolver(
......@@ -60,11 +28,13 @@ ProxyService* CreateProxyServiceUsingV8ProxyResolver(
DCHECK(dhcp_proxy_script_fetcher);
DCHECK(host_resolver);
ProxyService* proxy_service =
new ProxyService(proxy_config_service,
make_scoped_ptr(new ProxyResolverFactoryForV8Resolver(
host_resolver, net_log, network_delegate)),
net_log);
ProxyService* proxy_service = new ProxyService(
proxy_config_service,
make_scoped_ptr(new ProxyResolverFactoryV8Tracing(
host_resolver, net_log, ProxyResolver::LoadStateChangedCallback(),
base::Bind(&NetworkDelegateErrorObserver::Create, network_delegate,
base::ThreadTaskRunnerHandle::Get()))),
net_log);
// Configure fetchers to use for PAC script downloads and auto-detect.
proxy_service->SetProxyScriptFetchers(proxy_script_fetcher,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment