diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-08 19:12:47 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-08 19:12:47 +0000 |
commit | c4ff495718e7b190229e863e3387c4e5f99475a9 (patch) | |
tree | 3d2aef85fe5590905f80e71687154c664b9c42c0 /net/base | |
parent | 8348cb325bebf4d3516bd94949f5a4eb7c4056a9 (diff) | |
download | chromium_src-c4ff495718e7b190229e863e3387c4e5f99475a9.zip chromium_src-c4ff495718e7b190229e863e3387c4e5f99475a9.tar.gz chromium_src-c4ff495718e7b190229e863e3387c4e5f99475a9.tar.bz2 |
Add autodetection of "intranet" redirection, for ISPs etc. that send typos and nonexistent addresses to custom pages, and plumb it to the code that puts up infobars when users type in a search that appears to be an intranet address, so we don't show these for erroneous cases.
BUG=31556
TEST=none
Review URL: http://codereview.chromium.org/525079
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35807 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r-- | net/base/host_resolver_proc.cc | 28 | ||||
-rw-r--r-- | net/base/host_resolver_proc.h | 18 | ||||
-rw-r--r-- | net/base/mock_host_resolver.cc | 11 | ||||
-rw-r--r-- | net/base/mock_host_resolver.h | 12 |
4 files changed, 49 insertions, 20 deletions
diff --git a/net/base/host_resolver_proc.cc b/net/base/host_resolver_proc.cc index 87478eb..bd0ba2b 100644 --- a/net/base/host_resolver_proc.cc +++ b/net/base/host_resolver_proc.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -26,11 +26,33 @@ namespace net { HostResolverProc* HostResolverProc::default_proc_ = NULL; HostResolverProc::HostResolverProc(HostResolverProc* previous) { - set_previous_proc(previous); + SetPreviousProc(previous); // Implicitly fall-back to the global default procedure. if (!previous) - set_previous_proc(default_proc_); + SetPreviousProc(default_proc_); +} + +void HostResolverProc::SetPreviousProc(HostResolverProc* proc) { + HostResolverProc* current_previous = previous_proc_; + previous_proc_ = NULL; + // Now that we've guaranteed |this| is the last proc in a chain, we can + // detect potential cycles using GetLastProc(). + previous_proc_ = (GetLastProc(proc) == this) ? current_previous : proc; +} + +void HostResolverProc::SetLastProc(HostResolverProc* proc) { + GetLastProc(this)->SetPreviousProc(proc); +} + +// static +HostResolverProc* HostResolverProc::GetLastProc(HostResolverProc* proc) { + if (proc == NULL) + return NULL; + HostResolverProc* last_proc = proc; + while (last_proc->previous_proc_ != NULL) + last_proc = last_proc->previous_proc_; + return last_proc; } // static diff --git a/net/base/host_resolver_proc.h b/net/base/host_resolver_proc.h index f2bff25..ca0c55d 100644 --- a/net/base/host_resolver_proc.h +++ b/net/base/host_resolver_proc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -47,10 +47,17 @@ class HostResolverProc : public base::RefCountedThreadSafe<HostResolverProc> { friend class MockHostResolverBase; friend class ScopedDefaultHostResolverProc; - // Sets the previous procedure in the chain. - void set_previous_proc(HostResolverProc* proc) { - previous_proc_ = proc; - } + // Sets the previous procedure in the chain. Aborts if this would result in a + // cycle. + void SetPreviousProc(HostResolverProc* proc); + + // Sets the last procedure in the chain, i.e. appends |proc| to the end of the + // current chain. Aborts if this would result in a cycle. + void SetLastProc(HostResolverProc* proc); + + // Returns the last procedure in the chain starting at |proc|. Will return + // NULL iff |proc| is NULL. + static HostResolverProc* GetLastProc(HostResolverProc* proc); // Sets the default host resolver procedure that is used by HostResolverImpl. // This can be used through ScopedDefaultHostResolverProc to set a catch-all @@ -59,7 +66,6 @@ class HostResolverProc : public base::RefCountedThreadSafe<HostResolverProc> { static HostResolverProc* SetDefault(HostResolverProc* proc); static HostResolverProc* GetDefault(); - private: scoped_refptr<HostResolverProc> previous_proc_; static HostResolverProc* default_proc_; diff --git a/net/base/mock_host_resolver.cc b/net/base/mock_host_resolver.cc index b983724..cf38490 100644 --- a/net/base/mock_host_resolver.cc +++ b/net/base/mock_host_resolver.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -89,7 +89,7 @@ void MockHostResolverBase::Reset(HostResolverProc* interceptor) { // Lastly add the provided interceptor to the front of the chain. if (interceptor) { - interceptor->set_previous_proc(proc); + interceptor->SetPreviousProc(proc); proc = interceptor; } @@ -225,9 +225,8 @@ int RuleBasedHostResolverProc::Resolve(const std::string& host, //----------------------------------------------------------------------------- ScopedDefaultHostResolverProc::ScopedDefaultHostResolverProc( - HostResolverProc* proc) : current_proc_(proc) { - previous_proc_ = HostResolverProc::SetDefault(current_proc_); - current_proc_->set_previous_proc(previous_proc_); + HostResolverProc* proc) { + Init(proc); } ScopedDefaultHostResolverProc::~ScopedDefaultHostResolverProc() { @@ -239,7 +238,7 @@ ScopedDefaultHostResolverProc::~ScopedDefaultHostResolverProc() { void ScopedDefaultHostResolverProc::Init(HostResolverProc* proc) { current_proc_ = proc; previous_proc_ = HostResolverProc::SetDefault(current_proc_); - current_proc_->set_previous_proc(previous_proc_); + current_proc_->SetLastProc(previous_proc_); } } // namespace net diff --git a/net/base/mock_host_resolver.h b/net/base/mock_host_resolver.h index 72f10b4..523935a 100644 --- a/net/base/mock_host_resolver.h +++ b/net/base/mock_host_resolver.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -166,10 +166,12 @@ class WaitingHostResolverProc : public HostResolverProc { base::WaitableEvent event_; }; -// This class sets the HostResolverProc for a particular scope. If there are -// multiple ScopedDefaultHostResolverProc in existence, then the last one -// allocated will be used. However, if it does not provide a matching rule, -// then it should delegate to the previously set HostResolverProc. +// This class sets the default HostResolverProc for a particular scope. The +// chain of resolver procs starting at |proc| is placed in front of any existing +// default resolver proc(s). This means that if multiple +// ScopedDefaultHostResolverProcs are declared, then resolving will start with +// the procs given to the last-allocated one, then fall back to the procs given +// to the previously-allocated one, and so forth. // // NOTE: Only use this as a catch-all safety net. Individual tests should use // MockHostResolver. |