Skip to content

Commit

Permalink
[ChromeOS] Auto reload auth extension.
Browse files Browse the repository at this point in the history
Auto reload auth extension when we hit frame error and we are online. Retry three times with 5s, 10s and 20s delays.

Also add more logs to find out whether the offline/portal message is being shown.

BUG=chromium-os:20323
TEST=Verify fix for chromium-os:20323.


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103057 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
xiyuan@chromium.org committed Sep 28, 2011
1 parent 534303c commit 6ccd0de
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 5 deletions.
48 changes: 48 additions & 0 deletions chrome/browser/resources/chromeos/login/screen_gaia_signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ cr.define('login', function() {
// Authentication extension's start page URL.
extension_url_: null,

// Number of times that we reload extension frame.
retryCount_: 0,

// Timer id of pending retry.
retryTimer_: undefined,

/** @inheritDoc */
decorate: function() {
$('createAccount').innerHTML = localStrings.getStringF(
Expand Down Expand Up @@ -126,6 +132,7 @@ cr.define('login', function() {
Oobe.getInstance().headerHidden = false;

this.loading = true;
this.clearRetry_();
},

/**
Expand Down Expand Up @@ -153,6 +160,7 @@ cr.define('login', function() {
} else if (msg.method == 'loginUILoaded' && this.isAuthExtMessage_(e)) {
$('offline-message').update();
this.loading = false;
this.clearRetry_();
chrome.send('loginWebuiReady');
}
},
Expand All @@ -165,6 +173,46 @@ cr.define('login', function() {
// Reload and show the sign-in UI if needed.
if (takeFocus)
Oobe.showSigninUI();
},

/**
* Clears retry data.
* @private
*/
clearRetry_: function() {
this.retryCount_ = 0;
if (this.retryTimer_) {
window.clearTimeout(this.retryTimer_);
this.retryTimer_ = undefined;
}
},

/**
* Reloads extension frame.
* @private
*/
doReload_: function() {
console.log('Reload auth extension frame.');
$('signin-frame').src = this.extension_url_;
this.retryTimer_ = undefined;
},

/**
* Schedules extension frame reload.
*/
schdeduleRetry: function() {
if (this.retryCount_ >= 3 || this.retryTimer_)
return;

const MAX_DELAY = 7200; // 7200 seconds (i.e. 2 hours)
const MIN_DELAY = 1; // 1 second

var delay = Math.pow(2, this.retryCount_) * 5;
delay = Math.max(MIN_DELAY, Math.min(MAX_DELAY, delay)) * 1000;

++this.retryCount_;
this.retryTimer_ = window.setTimeout(this.doReload_.bind(this), delay);
console.log('GaiaSigninScreen schdeduleRetry in ' + delay + 'ms.');
}
};

Expand Down
47 changes: 42 additions & 5 deletions chrome/browser/resources/chromeos/login/screen_offline_message.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@

cr.define('login', function() {
// Screens that should have offline message overlay.
const MANAGED_SCREENS = ['gaia-signin', 'signin'];
const MANAGED_SCREENS = ['gaia-signin'];

// Network state constants.
const NET_STATE = {
OFFLINE: 0,
ONLINE: 1,
PORTAL: 2
};

/**
* Creates a new offline message screen div.
Expand Down Expand Up @@ -61,11 +68,13 @@ cr.define('login', function() {
updateState: function(state) {
var currentScreen = Oobe.getInstance().currentScreen;
var offlineMessage = this;
var isOnline = state == 1;
var isUnderCaptivePortal = state == 2;
var isOnline = (state == NET_STATE.ONLINE);
var isUnderCaptivePortal = (state == NET_STATE.PORTAL);
var shouldOverlay = MANAGED_SCREENS.indexOf(currentScreen.id) != -1;

if (!isOnline && shouldOverlay) {
console.log('Show offline message, state=' + state +
',isUnderCaptivePortal=' + isUnderCaptivePortal);
offlineMessage.onBeforeShow();

$('offline-message-text').hidden = isUnderCaptivePortal;
Expand All @@ -85,6 +94,7 @@ cr.define('login', function() {
}
} else {
if (!offlineMessage.classList.contains('faded')) {
console.log('Hide offline message.');
offlineMessage.onBeforeHide();

offlineMessage.classList.add('faded');
Expand Down Expand Up @@ -117,11 +127,38 @@ cr.define('login', function() {
* @param {number} error Error code.
*/
OfflineMessageScreen.onFrameError = function(error) {
console.log('Gaia frame error = ' + error);

// Offline and simple captive portal cases are handled by the
// NetworkStateInformer, so only the case when browser is online is
// valuable.
if (window.navigator.onLine)
this.updateState(2);
if (window.navigator.onLine) {
this.updateState(NET_STATE.PORTAL);

// Check current network state if currentScreen is a managed one.
var currentScreen = Oobe.getInstance().currentScreen;
if (MANAGED_SCREENS.indexOf(currentScreen.id) != -1) {
chrome.send('loginRequestNetworkState',
['login.OfflineMessageScreen.maybeRetry']);
}
}
};

/**
* Network state callback where we decide whether to schdule a retry.
*/
OfflineMessageScreen.maybeRetry = function(state) {
console.log('OfflineMessageScreen.maybeRetry, state=' + state);

// No retry if we are not online.
if (state != NET_STATE.ONLINE)
return;

var currentScreen = Oobe.getInstance().currentScreen;
if (MANAGED_SCREENS.indexOf(currentScreen.id) != -1) {
// Schedules a retry.
currentScreen.schdeduleRetry();
}
};

return {
Expand Down

0 comments on commit 6ccd0de

Please sign in to comment.