diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-22 20:08:05 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-22 20:08:05 +0000 |
commit | 354b8491e74c82b2c19c0e7f10ea9be2a71c6799 (patch) | |
tree | b880d9df79017a2baaac287b0d064e70cb06dc64 | |
parent | dafb7a0a867fbe26a4cff631d0b64bf5af43671e (diff) | |
download | chromium_src-354b8491e74c82b2c19c0e7f10ea9be2a71c6799.zip chromium_src-354b8491e74c82b2c19c0e7f10ea9be2a71c6799.tar.gz chromium_src-354b8491e74c82b2c19c0e7f10ea9be2a71c6799.tar.bz2 |
Add delay when resuming load when network connection is restured.
Without delay, chrome silently fails to load the page.
This is a wordaround and should be remoevd once the root cause is fixed.
* Different delays for secure and non secure connection as
secure connection needs longer delay.
* I simply shortened proxy resolution as this may hit the same
issue, and short enough that the page load happens after
proxy resolution.
BUG=chromium-os:8285
TEST=see the bug description for repro steps.
Review URL: http://codereview.chromium.org/5156007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66990 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 50 insertions, 7 deletions
diff --git a/chrome/browser/chromeos/offline/offline_load_page.cc b/chrome/browser/chromeos/offline/offline_load_page.cc index 94893a1..236a992 100644 --- a/chrome/browser/chromeos/offline/offline_load_page.cc +++ b/chrome/browser/chromeos/offline/offline_load_page.cc @@ -33,6 +33,14 @@ namespace { // Maximum time to show a blank page. const int kMaxBlankPeriod = 3000; +// This is a workaround for crosbug.com/8285. +// Chrome sometimes fails to load the page silently +// when the load is requested right after network is +// restored. This happens more often in HTTPS than HTTP. +// This should be removed once the root cause is fixed. +const int kSecureDelayMs = 1000; +const int kDefaultDelayMs = 300; + // A utility function to set the dictionary's value given by |resource_id|. void SetString(DictionaryValue* strings, const char* name, int resource_id) { strings->SetString(name, l10n_util::GetStringUTF16(resource_id)); @@ -61,7 +69,10 @@ OfflineLoadPage::OfflineLoadPage(TabContents* tab_contents, const GURL& url, Delegate* delegate) : InterstitialPage(tab_contents, true, url), - delegate_(delegate) { + delegate_(delegate), + proceeded_(false), + ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), + in_test_(false) { registrar_.Add(this, NotificationType::NETWORK_STATE_CHANGED, NotificationService::AllSources()); } @@ -174,11 +185,26 @@ void OfflineLoadPage::CommandReceived(const std::string& cmd) { } void OfflineLoadPage::Proceed() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + int delay = url().SchemeIsSecure() ? kSecureDelayMs : kDefaultDelayMs; + if (in_test_) + delay = 0; + proceeded_ = true; + BrowserThread::PostDelayedTask( + BrowserThread::UI, FROM_HERE, + method_factory_.NewRunnableMethod(&OfflineLoadPage::DoProceed), + delay); +} + +void OfflineLoadPage::DoProceed() { delegate_->OnBlockingPageComplete(true); InterstitialPage::Proceed(); } void OfflineLoadPage::DontProceed() { + // Inogre if it's already proceeded. + if (proceeded_) + return; delegate_->OnBlockingPageComplete(false); InterstitialPage::DontProceed(); } diff --git a/chrome/browser/chromeos/offline/offline_load_page.h b/chrome/browser/chromeos/offline/offline_load_page.h index fc8c528..2708167 100644 --- a/chrome/browser/chromeos/offline/offline_load_page.h +++ b/chrome/browser/chromeos/offline/offline_load_page.h @@ -8,6 +8,7 @@ #include <string> +#include "base/task.h" #include "chrome/browser/chromeos/network_state_notifier.h" #include "chrome/browser/tab_contents/interstitial_page.h" #include "chrome/common/notification_observer.h" @@ -49,6 +50,11 @@ class OfflineLoadPage : public InterstitialPage { Delegate* delegate); virtual ~OfflineLoadPage() {} + // Only for testing. + void EnableTest() { + in_test_ = true; + } + private: // InterstitialPage implementation. virtual std::string GetHTMLContents(); @@ -69,9 +75,18 @@ class OfflineLoadPage : public InterstitialPage { void GetNormalOfflineStrings(const string16& faield_url, DictionaryValue* strings) const; + // Really proceed with loading. + void DoProceed(); + Delegate* delegate_; NotificationRegistrar registrar_; + // True if the proceed is chosen. + bool proceeded_; + ScopedRunnableMethodFactory<OfflineLoadPage> method_factory_; + + bool in_test_; + DISALLOW_COPY_AND_ASSIGN(OfflineLoadPage); }; diff --git a/chrome/browser/chromeos/offline/offline_load_page_unittest.cc b/chrome/browser/chromeos/offline/offline_load_page_unittest.cc index d679355..16b63fe 100644 --- a/chrome/browser/chromeos/offline/offline_load_page_unittest.cc +++ b/chrome/browser/chromeos/offline/offline_load_page_unittest.cc @@ -23,6 +23,7 @@ class TestOfflineLoadPage : public chromeos::OfflineLoadPage { const GURL& url, Delegate* delegate) : chromeos::OfflineLoadPage(tab_contents, url, delegate) { + EnableTest(); } // Overriden from InterstitialPage. Don't create a view. @@ -103,13 +104,14 @@ TEST_F(OfflineLoadPageTest, OfflinePaeProceed) { // Simulate the user clicking "proceed". interstitial->Proceed(); + MessageLoop::current()->RunAllPending(); EXPECT_EQ(OK, user_response()); // The URL remains to be URL2. EXPECT_EQ(kURL2, contents()->GetURL().spec()); - // Ccommit navigation and the interstitial page is gone. + // Commit navigation and the interstitial page is gone. Navigate(kURL2, 2); EXPECT_FALSE(GetOfflineLoadPage()); } diff --git a/net/base/network_change_notifier_linux.cc b/net/base/network_change_notifier_linux.cc index 95f230d..1db4bd1 100644 --- a/net/base/network_change_notifier_linux.cc +++ b/net/base/network_change_notifier_linux.cc @@ -102,11 +102,11 @@ void NetworkChangeNotifierLinux::Thread::ListenForNotifications() { if (HandleNetlinkMessage(buf, rv)) { VLOG(1) << "Detected IP address changes."; #if defined(OS_CHROMEOS) - // TODO(zelidrag): chromium-os:3996 - introduced artificial delay to - // work around the issue of proxy initialization before name resolving - // is functional in ChromeOS. This should be removed once this bug - // is properly fixed. - const int kObserverNotificationDelayMS = 500; + // TODO(oshima): chromium-os:8285 - introduced artificial delay to + // work around the issue of network load issue after connection + // restored. See the bug for more details. + // This should be removed once this bug is properly fixed. + const int kObserverNotificationDelayMS = 200; message_loop()->PostDelayedTask( FROM_HERE, method_factory_.NewRunnableMethod( |