Skip to content

Commit

Permalink
Add new text for indicating we are resolving hosts during proxy resol…
Browse files Browse the repository at this point in the history
…ution.

Required adding a new GetLoadStateThreadSafe() virtual method to the ProxyResolver interface. ProxyResolverV8 uses this.

BUG=59308
TEST=none


Review URL: http://codereview.chromium.org/8373014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108950 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
willchan@chromium.org committed Nov 8, 2011
1 parent eb191d6 commit f2c971f
Show file tree
Hide file tree
Showing 21 changed files with 233 additions and 6 deletions.
3 changes: 3 additions & 0 deletions chrome/app/generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -6490,6 +6490,9 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL">
Resolving proxy...
</message>
<message name="IDS_LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT">
Resolving host in proxy script...
</message>
<message name="IDS_LOAD_STATE_RESOLVING_HOST">
Resolving host...
</message>
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/ui/tab_contents/tab_contents_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,9 @@ string16 TabContentsWrapper::GetStatusText() const {
l10n_util::GetStringUTF16(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
case net::LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT:
return l10n_util::GetStringUTF16(
IDS_LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT);
case net::LOAD_STATE_RESOLVING_HOST:
return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_HOST);
case net::LOAD_STATE_CONNECTING:
Expand Down
9 changes: 6 additions & 3 deletions net/base/load_states.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ enum LoadState {
LOAD_STATE_WAITING_FOR_APPCACHE,

// This state corresponds to a resource load that is blocked waiting for a
// proxy autoconfig script to return a proxy server to use. This state may
// take a while if the proxy script needs to resolve the IP address of the
// host before deciding what proxy to use.
// proxy autoconfig script to return a proxy server to use.
LOAD_STATE_RESOLVING_PROXY_FOR_URL,

// This state corresponds to a resource load that is blocked waiting for a
// proxy autoconfig script to return a proxy server to use, but that proxy
// script is busy resolving the IP address of a host.
LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT,

// This state indicates that we're in the process of establishing a tunnel
// through the proxy server.
LOAD_STATE_ESTABLISHING_PROXY_TUNNEL,
Expand Down
11 changes: 11 additions & 0 deletions net/http/http_network_transaction_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7124,6 +7124,17 @@ class CapturingProxyResolver : public ProxyResolver {
NOTREACHED();
}

virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE {
NOTREACHED();
return LOAD_STATE_IDLE;
}

virtual LoadState GetLoadStateThreadSafe(
RequestHandle request) const OVERRIDE {
NOTREACHED();
return LOAD_STATE_IDLE;
}

virtual void CancelSetPacScript() {
NOTREACHED();
}
Expand Down
2 changes: 1 addition & 1 deletion net/http/http_stream_factory_impl_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ int HttpStreamFactoryImpl::Job::RestartTunnelWithProxyAuth(
LoadState HttpStreamFactoryImpl::Job::GetLoadState() const {
switch (next_state_) {
case STATE_RESOLVE_PROXY_COMPLETE:
return LOAD_STATE_RESOLVING_PROXY_FOR_URL;
return session_->proxy_service()->GetLoadState(pac_request_);
case STATE_CREATE_STREAM_COMPLETE:
return connection_->GetLoadState();
case STATE_INIT_CONNECTION_COMPLETE:
Expand Down
11 changes: 11 additions & 0 deletions net/proxy/init_proxy_resolver_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ class RuleBasedProxyResolver : public ProxyResolver {
NOTREACHED();
}

virtual LoadState GetLoadState(RequestHandle request_handle) const {
NOTREACHED();
return LOAD_STATE_IDLE;
}

virtual LoadState GetLoadStateThreadSafe(
RequestHandle request) const OVERRIDE {
NOTREACHED();
return LOAD_STATE_IDLE;
}

virtual void CancelSetPacScript() {
NOTREACHED();
}
Expand Down
12 changes: 12 additions & 0 deletions net/proxy/mock_proxy_resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ void MockAsyncProxyResolverBase::CancelRequest(RequestHandle request_handle) {
RemovePendingRequest(request);
}

LoadState MockAsyncProxyResolverBase::GetLoadState(
RequestHandle request_handle) const {
NOTREACHED();
return LOAD_STATE_IDLE;
}

LoadState MockAsyncProxyResolverBase::GetLoadStateThreadSafe(
RequestHandle request_handle) const {
NOTREACHED();
return LOAD_STATE_IDLE;
}

int MockAsyncProxyResolverBase::SetPacScript(
const scoped_refptr<ProxyResolverScriptData>& script_data,
OldCompletionCallback* callback) {
Expand Down
3 changes: 3 additions & 0 deletions net/proxy/mock_proxy_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class MockAsyncProxyResolverBase : public ProxyResolver {
RequestHandle* request_handle,
const BoundNetLog& /*net_log*/) OVERRIDE;
virtual void CancelRequest(RequestHandle request_handle) OVERRIDE;
virtual LoadState GetLoadState(RequestHandle request_handle) const OVERRIDE;
virtual LoadState GetLoadStateThreadSafe(
RequestHandle request_handle) const OVERRIDE;
virtual int SetPacScript(
const scoped_refptr<ProxyResolverScriptData>& script_data,
OldCompletionCallback* callback) OVERRIDE;
Expand Down
16 changes: 16 additions & 0 deletions net/proxy/multi_threaded_proxy_resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,22 @@ void MultiThreadedProxyResolver::CancelRequest(RequestHandle req) {
}
}

LoadState MultiThreadedProxyResolver::GetLoadState(RequestHandle req) const {
DCHECK(CalledOnValidThread());
DCHECK(req);

Job* job = reinterpret_cast<Job*>(req);
if (job->executor())
return job->executor()->resolver()->GetLoadStateThreadSafe(NULL);
return LOAD_STATE_RESOLVING_PROXY_FOR_URL;
}

LoadState MultiThreadedProxyResolver::GetLoadStateThreadSafe(
RequestHandle req) const {
NOTIMPLEMENTED();
return LOAD_STATE_IDLE;
}

void MultiThreadedProxyResolver::CancelSetPacScript() {
DCHECK(CalledOnValidThread());
DCHECK_EQ(0u, pending_jobs_.size());
Expand Down
3 changes: 3 additions & 0 deletions net/proxy/multi_threaded_proxy_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ class NET_EXPORT_PRIVATE MultiThreadedProxyResolver
RequestHandle* request,
const BoundNetLog& net_log) OVERRIDE;
virtual void CancelRequest(RequestHandle request) OVERRIDE;
virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE;
virtual LoadState GetLoadStateThreadSafe(
RequestHandle request) const OVERRIDE;
virtual void CancelSetPacScript() OVERRIDE;
virtual void PurgeMemory() OVERRIDE;
virtual int SetPacScript(
Expand Down
22 changes: 22 additions & 0 deletions net/proxy/multi_threaded_proxy_resolver_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ class MockProxyResolver : public ProxyResolver {
NOTREACHED();
}

virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE {
NOTREACHED();
return LOAD_STATE_IDLE;
}

virtual LoadState GetLoadStateThreadSafe(
RequestHandle request) const OVERRIDE {
NOTREACHED();
return LOAD_STATE_IDLE;
}

virtual void CancelSetPacScript() OVERRIDE {
NOTREACHED();
}
Expand Down Expand Up @@ -175,6 +186,17 @@ class ForwardingProxyResolver : public ProxyResolver {
impl_->CancelRequest(request);
}

virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE {
NOTREACHED();
return LOAD_STATE_IDLE;
}

virtual LoadState GetLoadStateThreadSafe(
RequestHandle request) const OVERRIDE {
NOTREACHED();
return LOAD_STATE_IDLE;
}

virtual void CancelSetPacScript() OVERRIDE {
impl_->CancelSetPacScript();
}
Expand Down
7 changes: 7 additions & 0 deletions net/proxy/proxy_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/string16.h"
#include "googleurl/src/gurl.h"
#include "net/base/completion_callback.h"
#include "net/base/load_states.h"
#include "net/base/net_export.h"
#include "net/proxy/proxy_resolver_script_data.h"

Expand Down Expand Up @@ -49,6 +50,12 @@ class NET_EXPORT_PRIVATE ProxyResolver {
// Cancels |request|.
virtual void CancelRequest(RequestHandle request) = 0;

// Gets the LoadState for |request|.
virtual LoadState GetLoadState(RequestHandle request) const = 0;

// Gets the LoadState for |request|. May be called from another thread.
virtual LoadState GetLoadStateThreadSafe(RequestHandle request) const = 0;

// The PAC script backend can be specified to the ProxyResolver either via
// URL, or via the javascript text itself. If |expects_pac_bytes| is true,
// then the ProxyResolverScriptData passed to SetPacScript() should
Expand Down
10 changes: 10 additions & 0 deletions net/proxy/proxy_resolver_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ void ProxyResolverMac::CancelRequest(RequestHandle request) {
NOTREACHED();
}

LoadState ProxyResolverMac::GetLoadState(RequestHandle request) const {
NOTREACHED();
return LOAD_STATE_IDLE;
}

LoadState ProxyResolverMac::GetLoadStateThreadSafe(
RequestHandle request) const {
return LOAD_STATE_IDLE;
}

void ProxyResolverMac::CancelSetPacScript() {
NOTREACHED();
}
Expand Down
5 changes: 5 additions & 0 deletions net/proxy/proxy_resolver_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class NET_EXPORT ProxyResolverMac : public ProxyResolver {

virtual void CancelRequest(RequestHandle request) OVERRIDE;

virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE;

virtual LoadState GetLoadStateThreadSafe(
RequestHandle request) const OVERRIDE;

virtual void CancelSetPacScript() OVERRIDE;

virtual int SetPacScript(
Expand Down
54 changes: 53 additions & 1 deletion net/proxy/proxy_resolver_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "base/logging.h"
#include "base/string_tokenizer.h"
#include "base/string_util.h"
#include "base/synchronization/lock.h"
#include "base/utf_string_conversions.h"
#include "googleurl/src/gurl.h"
#include "googleurl/src/url_canon.h"
Expand Down Expand Up @@ -335,7 +336,8 @@ bool IsInNetEx(const std::string& ip_address, const std::string& ip_prefix) {
class ProxyResolverV8::Context {
public:
explicit Context(ProxyResolverJSBindings* js_bindings)
: js_bindings_(js_bindings) {
: is_resolving_host_(false),
js_bindings_(js_bindings) {
DCHECK(js_bindings != NULL);
}

Expand Down Expand Up @@ -495,7 +497,40 @@ class ProxyResolverV8::Context {
;
}

bool is_resolving_host() const {
base::AutoLock auto_lock(lock_);
return is_resolving_host_;
}

private:
class ScopedHostResolve {
public:
explicit ScopedHostResolve(Context* context)
: context_(context) {
context_->BeginHostResolve();
}

~ScopedHostResolve() {
context_->EndHostResolve();
}

private:
Context* const context_;
DISALLOW_COPY_AND_ASSIGN(ScopedHostResolve);
};

void BeginHostResolve() {
base::AutoLock auto_lock(lock_);
DCHECK(!is_resolving_host_);
is_resolving_host_ = true;
}

void EndHostResolve() {
base::AutoLock auto_lock(lock_);
DCHECK(is_resolving_host_);
is_resolving_host_ = false;
}

bool GetFindProxyForURL(v8::Local<v8::Value>* function) {
*function = v8_context_->Global()->Get(
ASCIILiteralToV8String("FindProxyForURL"));
Expand Down Expand Up @@ -566,6 +601,7 @@ class ProxyResolverV8::Context {

{
v8::Unlocker unlocker;
ScopedHostResolve scoped_host_resolve(context);

// We shouldn't be called with any arguments, but will not complain if
// we are.
Expand All @@ -588,6 +624,7 @@ class ProxyResolverV8::Context {

{
v8::Unlocker unlocker;
ScopedHostResolve scoped_host_resolve(context);

// We shouldn't be called with any arguments, but will not complain if
// we are.
Expand All @@ -614,6 +651,7 @@ class ProxyResolverV8::Context {

{
v8::Unlocker unlocker;
ScopedHostResolve scoped_host_resolve(context);
success = context->js_bindings_->DnsResolve(hostname, &ip_address);
}

Expand All @@ -635,6 +673,7 @@ class ProxyResolverV8::Context {

{
v8::Unlocker unlocker;
ScopedHostResolve scoped_host_resolve(context);
success = context->js_bindings_->DnsResolveEx(hostname, &ip_address_list);
}

Expand Down Expand Up @@ -677,6 +716,8 @@ class ProxyResolverV8::Context {
return IsInNetEx(ip_address, ip_prefix) ? v8::True() : v8::False();
}

mutable base::Lock lock_;
bool is_resolving_host_;
ProxyResolverJSBindings* js_bindings_;
v8::Persistent<v8::External> v8_this_;
v8::Persistent<v8::Context> v8_context_;
Expand Down Expand Up @@ -728,6 +769,17 @@ void ProxyResolverV8::CancelRequest(RequestHandle request) {
NOTREACHED();
}

LoadState ProxyResolverV8::GetLoadState(RequestHandle request) const {
NOTREACHED();
return LOAD_STATE_IDLE;
}

LoadState ProxyResolverV8::GetLoadStateThreadSafe(RequestHandle request) const {
if (context_->is_resolving_host())
return LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT;
return LOAD_STATE_RESOLVING_PROXY_FOR_URL;
}

void ProxyResolverV8::CancelSetPacScript() {
NOTREACHED();
}
Expand Down
3 changes: 3 additions & 0 deletions net/proxy/proxy_resolver_v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class NET_EXPORT_PRIVATE ProxyResolverV8 : public ProxyResolver {
RequestHandle* /*request*/,
const BoundNetLog& net_log) OVERRIDE;
virtual void CancelRequest(RequestHandle request) OVERRIDE;
virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE;
virtual LoadState GetLoadStateThreadSafe(
RequestHandle request) const OVERRIDE;
virtual void CancelSetPacScript() OVERRIDE;
virtual void PurgeMemory() OVERRIDE;
virtual void Shutdown() OVERRIDE;
Expand Down
12 changes: 11 additions & 1 deletion net/proxy/proxy_resolver_winhttp.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 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.

Expand Down Expand Up @@ -124,6 +124,16 @@ void ProxyResolverWinHttp::CancelRequest(RequestHandle request) {
NOTREACHED();
}

LoadState ProxyResolverWinHttp::GetLoadState(RequestHandle request) const {
NOTREACHED();
return LOAD_STATE_IDLE;
}

LoadState ProxyResolverWinHttp::GetLoadStateThreadSafe(
RequestHandle request) const {
return LOAD_STATE_IDLE;
}

void ProxyResolverWinHttp::CancelSetPacScript() {
NOTREACHED();
}
Expand Down
5 changes: 5 additions & 0 deletions net/proxy/proxy_resolver_winhttp.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class NET_EXPORT_PRIVATE ProxyResolverWinHttp : public ProxyResolver {
const BoundNetLog& /*net_log*/) OVERRIDE;
virtual void CancelRequest(RequestHandle request) OVERRIDE;

virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE;

virtual LoadState GetLoadStateThreadSafe(
RequestHandle request) const OVERRIDE;

virtual void CancelSetPacScript() OVERRIDE;

virtual int SetPacScript(
Expand Down
Loading

0 comments on commit f2c971f

Please sign in to comment.