summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-09 05:16:20 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-09 05:16:20 +0000
commit8358895f3fe356feedde85de227e4cf15cf95607 (patch)
treefa613ce3d31d9bee0d0bab74fc98cf3c429883f7 /chrome/browser
parent3259aa9cdf3e25c815b7e74da1e836920a544318 (diff)
downloadchromium_src-8358895f3fe356feedde85de227e4cf15cf95607.zip
chromium_src-8358895f3fe356feedde85de227e4cf15cf95607.tar.gz
chromium_src-8358895f3fe356feedde85de227e4cf15cf95607.tar.bz2
Rerun intranet check on network changes.
BUG=35524 TEST=Open chromium while on a "normal" network. Switch to a network that does dns hijacking. Type a single-word query into omnibox and hit return. No "Did you mean to go to http://query" infobar should open. Review URL: http://codereview.chromium.org/2910001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51934 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/intranet_redirect_detector.cc32
-rw-r--r--chrome/browser/intranet_redirect_detector.h16
2 files changed, 38 insertions, 10 deletions
diff --git a/chrome/browser/intranet_redirect_detector.cc b/chrome/browser/intranet_redirect_detector.cc
index 2d706ce..16c72de 100644
--- a/chrome/browser/intranet_redirect_detector.cc
+++ b/chrome/browser/intranet_redirect_detector.cc
@@ -23,8 +23,8 @@ IntranetRedirectDetector::IntranetRedirectDetector()
: redirect_origin_(g_browser_process->local_state()->GetString(
prefs::kLastKnownIntranetRedirectOrigin)),
ALLOW_THIS_IN_INITIALIZER_LIST(fetcher_factory_(this)),
- in_startup_sleep_(true),
- request_context_available_(!!Profile::GetDefaultRequestContext()) {
+ in_sleep_(true),
+ request_context_available_(Profile::GetDefaultRequestContext() != NULL) {
registrar_.Add(this, NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
NotificationService::AllSources());
@@ -39,9 +39,12 @@ IntranetRedirectDetector::IntranetRedirectDetector()
fetcher_factory_.NewRunnableMethod(
&IntranetRedirectDetector::FinishSleep),
kStartFetchDelayMS);
+
+ net::NetworkChangeNotifier::AddObserver(this);
}
IntranetRedirectDetector::~IntranetRedirectDetector() {
+ net::NetworkChangeNotifier::RemoveObserver(this);
STLDeleteElements(&fetchers_);
}
@@ -59,7 +62,12 @@ void IntranetRedirectDetector::RegisterPrefs(PrefService* prefs) {
}
void IntranetRedirectDetector::FinishSleep() {
- in_startup_sleep_ = false;
+ in_sleep_ = false;
+
+ // If another fetch operation is still running, cancel it.
+ STLDeleteElements(&fetchers_);
+ resulting_origins_.clear();
+
StartFetchesIfPossible();
}
@@ -67,10 +75,9 @@ void IntranetRedirectDetector::StartFetchesIfPossible() {
// Bail if a fetch isn't appropriate right now. This function will be called
// again each time one of the preconditions changes, so we'll fetch
// immediately once all of them are met.
- if (in_startup_sleep_ || !request_context_available_)
+ if (in_sleep_ || !request_context_available_)
return;
- // We shouldn't somehow run twice.
DCHECK(fetchers_.empty() && resulting_origins_.empty());
// Start three fetchers on random hostnames.
@@ -151,6 +158,21 @@ void IntranetRedirectDetector::Observe(NotificationType type,
StartFetchesIfPossible();
}
+void IntranetRedirectDetector::OnIPAddressChanged() {
+ // If a request is already scheduled, do not scheduled yet another one.
+ if (in_sleep_)
+ return;
+
+ // Since presumably many programs open connections after network changes,
+ // delay this a little bit.
+ in_sleep_ = true;
+ static const int kNetworkSwitchDelayMS = 1000;
+ MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ fetcher_factory_.NewRunnableMethod(
+ &IntranetRedirectDetector::FinishSleep),
+ kNetworkSwitchDelayMS);
+}
+
IntranetRedirectHostResolverProc::IntranetRedirectHostResolverProc(
net::HostResolverProc* previous)
: net::HostResolverProc(previous) {
diff --git a/chrome/browser/intranet_redirect_detector.h b/chrome/browser/intranet_redirect_detector.h
index e939eae5..cb10265 100644
--- a/chrome/browser/intranet_redirect_detector.h
+++ b/chrome/browser/intranet_redirect_detector.h
@@ -13,6 +13,7 @@
#include "chrome/common/notification_registrar.h"
#include "googleurl/src/gurl.h"
#include "net/base/host_resolver_proc.h"
+#include "net/base/network_change_notifier.h"
class PrefService;
@@ -33,7 +34,8 @@ class PrefService;
// return a value at all times (even during startup or in unittest mode). If no
// redirection is in place, the returned GURL will be empty.
class IntranetRedirectDetector : public URLFetcher::Delegate,
- public NotificationObserver {
+ public NotificationObserver,
+ public net::NetworkChangeNotifier::Observer {
public:
// Only the main browser process loop should call this, when setting up
// g_browser_process->intranet_redirect_detector_. No code other than the
@@ -57,8 +59,8 @@ class IntranetRedirectDetector : public URLFetcher::Delegate,
private:
typedef std::set<URLFetcher*> Fetchers;
- // Called when the five second startup sleep has finished. Runs any pending
- // fetch.
+ // Called when the seven second startup sleep or the one second network
+ // switch sleep has finished. Runs any pending fetch.
void FinishSleep();
// Starts the fetches to determine the redirect URL if we can currently do so.
@@ -77,13 +79,17 @@ class IntranetRedirectDetector : public URLFetcher::Delegate,
const NotificationSource& source,
const NotificationDetails& details);
+ // NetworkChangeNotifier::Observer
+ virtual void OnIPAddressChanged();
+
NotificationRegistrar registrar_;
GURL redirect_origin_;
ScopedRunnableMethodFactory<IntranetRedirectDetector> fetcher_factory_;
Fetchers fetchers_;
std::vector<GURL> resulting_origins_;
- bool in_startup_sleep_; // True if we're in the seven-second "no fetching"
- // period that begins at browser start.
+ bool in_sleep_; // True if we're in the seven-second "no fetching" period
+ // that begins at browser start, or the one-second "no
+ // fetching" period that begins after network switches.
bool request_context_available_;
// True when the profile has been loaded and the
// default request context created, so we can