Commit e464c704 authored by ygorshenin's avatar ygorshenin Committed by Commit bot

Fixed "Relaunch and Powerwash" button on a chrome://help page.

UI state of the elements related to channel switcher should depend only on update status, current and target channels, not on the internal state which is reset each time chrome://help is reloaded.

BUG=323530
TEST=manual tests on a falco device

Review URL: https://codereview.chromium.org/565903002

Cr-Commit-Position: refs/heads/master@{#295056}
parent 6458afea
......@@ -195,7 +195,6 @@ cr.define('help', function() {
*/
updateIsEnterpriseManaged_: function(isEnterpriseManaged) {
this.isEnterpriseManaged_ = isEnterpriseManaged;
help.HelpPage.updateChannelChangePageContainerVisibility();
},
/**
......@@ -209,7 +208,6 @@ cr.define('help', function() {
return;
this.currentChannel_ = channel;
this.selectOption_(channel);
help.HelpPage.updateChannelChangePageContainerVisibility();
},
/**
......@@ -223,7 +221,6 @@ cr.define('help', function() {
if (this.channelList_.indexOf(channel) < 0)
return;
this.targetChannel_ = channel;
help.HelpPage.updateChannelChangePageContainerVisibility();
},
/**
......
......@@ -22,13 +22,8 @@ cr.define('help', function() {
__proto__: Page.prototype,
/**
* True if after update powerwash button should be displayed.
* @private
*/
powerwashAfterUpdate_: false,
/**
* List of the channel names.
* List of the channel names. Should be ordered in increasing level of
* stability.
* @private
*/
channelList_: ['dev-channel', 'beta-channel', 'stable-channel'],
......@@ -45,6 +40,18 @@ cr.define('help', function() {
*/
targetChannel_: null,
/**
* Last status received from the version updater.
* @private
*/
status_: null,
/**
* Last message received from the version updater.
* @private
*/
message_: null,
/** @override */
initializePage: function() {
Page.prototype.initializePage.call(this);
......@@ -223,12 +230,53 @@ cr.define('help', function() {
return (current != null && target != null && current != target);
},
/**
* @return {boolean} True if target channel is more stable than the current
* one, and false otherwise.
* @private
*/
targetChannelIsMoreStable_: function() {
var current = this.currentChannel_;
var target = this.targetChannel_;
if (current == null || target == null)
return false;
var currentIndex = this.channelList_.indexOf(current);
var targetIndex = this.channelList_.indexOf(target);
if (currentIndex < 0 || targetIndex < 0)
return false;
return currentIndex < targetIndex;
},
/**
* @param {string} status The status of the update.
* @param {string} message Failure message to display.
* @private
*/
setUpdateStatus_: function(status, message) {
this.status_ = status;
this.message_ = message;
this.updateUI_();
},
/**
* Updates UI elements on the page according to current state.
* @private
*/
updateUI_: function() {
var status = this.status_;
var message = this.message_;
var channel = this.targetChannel_;
if (this.channelList_.indexOf(channel) >= 0) {
$('current-channel').textContent = loadTimeData.getStringF(
'currentChannel', this.channelTable_[channel].label);
this.updateChannelChangePageContainerVisibility_();
}
if (status == null)
return;
if (cr.isMac &&
$('update-status-message') &&
$('update-status-message').hidden) {
......@@ -238,7 +286,6 @@ cr.define('help', function() {
return;
}
var channel = this.targetChannel_;
if (status == 'checking') {
this.setUpdateImage_('working');
$('update-status-message').innerHTML =
......@@ -279,7 +326,7 @@ cr.define('help', function() {
// when user explicitly decides to update to a more stable
// channel.
relaunchAndPowerwashHidden =
!this.powerwashAfterUpdate_ || status != 'nearly_updated';
!this.targetChannelIsMoreStable_() || status != 'nearly_updated';
$('relaunch-and-powerwash').hidden = relaunchAndPowerwashHidden;
}
......@@ -406,6 +453,17 @@ cr.define('help', function() {
$('firmware').textContent = firmware;
},
/**
* Updates page UI according to device owhership policy.
* @param {boolean} isEnterpriseManaged True if the device is
* enterprise managed.
* @private
*/
updateIsEnterpriseManaged_: function(isEnterpriseManaged) {
help.ChannelChangePage.updateIsEnterpriseManaged(isEnterpriseManaged);
this.updateUI_();
},
/**
* Updates name of the current channel, i.e. the name of the
* channel the device is currently on.
......@@ -415,10 +473,23 @@ cr.define('help', function() {
updateCurrentChannel_: function(channel) {
if (this.channelList_.indexOf(channel) < 0)
return;
$('current-channel').textContent = loadTimeData.getStringF(
'currentChannel', this.channelTable_[channel].label);
this.currentChannel_ = channel;
help.ChannelChangePage.updateCurrentChannel(channel);
this.updateUI_();
},
/**
* Updates name of the target channel, i.e. the name of the
* channel the device is supposed to be.
* @param {string} channel The name of the target channel.
* @private
*/
updateTargetChannel_: function(channel) {
if (this.channelList_.indexOf(channel) < 0)
return;
this.targetChannel_ = channel;
help.ChannelChangePage.updateTargetChannel(channel);
this.updateUI_();
},
/**
......@@ -438,12 +509,11 @@ cr.define('help', function() {
* @private
*/
setChannel_: function(channel, isPowerwashAllowed) {
this.powerwashAfterUpdate_ = isPowerwashAllowed;
this.targetChannel_ = channel;
chrome.send('setChannel', [channel, isPowerwashAllowed]);
$('channel-change-confirmation').hidden = false;
$('channel-change-confirmation').textContent = loadTimeData.getStringF(
'channel-changed', this.channelTable_[channel].name);
this.updateTargetChannel_(channel);
},
/**
......@@ -526,7 +596,7 @@ cr.define('help', function() {
HelpPage.updateIsEnterpriseManaged = function(isEnterpriseManaged) {
if (!cr.isChromeOS)
return;
help.ChannelChangePage.updateIsEnterpriseManaged(isEnterpriseManaged);
HelpPage.getInstance().updateIsEnterpriseManaged_(isEnterpriseManaged);
};
HelpPage.updateCurrentChannel = function(channel) {
......@@ -538,7 +608,7 @@ cr.define('help', function() {
HelpPage.updateTargetChannel = function(channel) {
if (!cr.isChromeOS)
return;
help.ChannelChangePage.updateTargetChannel(channel);
HelpPage.getInstance().updateTargetChannel_(channel);
};
HelpPage.updateEnableReleaseChannel = function(enabled) {
......@@ -553,10 +623,6 @@ cr.define('help', function() {
HelpPage.getInstance().setBuildDate_(buildDate);
};
HelpPage.updateChannelChangePageContainerVisibility = function() {
HelpPage.getInstance().updateChannelChangePageContainerVisibility_();
};
// Export
return {
HelpPage: HelpPage
......
......@@ -396,6 +396,11 @@ class UpdateEngineClientImpl : public UpdateEngineClient {
// The UpdateEngineClient implementation used on Linux desktop,
// which does nothing.
class UpdateEngineClientStubImpl : public UpdateEngineClient {
public:
UpdateEngineClientStubImpl()
: current_channel_(kReleaseChannelBeta),
target_channel_(kReleaseChannelBeta) {}
// UpdateEngineClient implementation:
virtual void Init(dbus::Bus* bus) OVERRIDE {}
virtual void AddObserver(Observer* observer) OVERRIDE {}
......@@ -418,13 +423,20 @@ class UpdateEngineClientStubImpl : public UpdateEngineClient {
VLOG(1) << "Requesting to set channel: "
<< "target_channel=" << target_channel << ", "
<< "is_powerwash_allowed=" << is_powerwash_allowed;
target_channel_ = target_channel;
}
virtual void GetChannel(bool get_current_channel,
const GetChannelCallback& callback) OVERRIDE {
VLOG(1) << "Requesting to get channel, get_current_channel="
<< get_current_channel;
callback.Run(kReleaseChannelBeta);
if (get_current_channel)
callback.Run(current_channel_);
else
callback.Run(target_channel_);
}
std::string current_channel_;
std::string target_channel_;
};
// The UpdateEngineClient implementation used on Linux desktop, which
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment