Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2034)

Unified Diff: chrome/browser/resources/chromeos/image_burner.js

Issue 10356042: Fix presubmit js style nits. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/chromeos/image_burner.js
diff --git a/chrome/browser/resources/chromeos/image_burner.js b/chrome/browser/resources/chromeos/image_burner.js
index b81f5784ad1cb76a3f116049683f7cb7c46ccb7f..0a48abe13dc9255710a7ad4bcfe5868d1e716352 100644
--- a/chrome/browser/resources/chromeos/image_burner.js
+++ b/chrome/browser/resources/chromeos/image_burner.js
@@ -1,53 +1,64 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
var localStrings;
var browserBridge;
-// Class that keeps track of current burn process state.
+/**
+ * Class that keeps track of current burn process state.
+ * @param {Object} strings Localized state strings.
+ * @constructor
+ */
function State(strings) {
this.setStrings(strings);
this.changeState(State.StatesEnum.DEVICE_NONE);
}
+/**
+ * State Enum object.
+ */
State.StatesEnum = {
- DEVICE_NONE : {
- cssState : "device-detected-none",
+ DEVICE_NONE: {
+ cssState: 'device-detected-none',
},
- DEVICE_USB : {
- cssState : "device-detected-usb warning",
+ DEVICE_USB: {
+ cssState: 'device-detected-usb warning',
},
- DEVICE_SD : {
- cssState : "device-detected-sd warning",
+ DEVICE_SD: {
+ cssState: 'device-detected-sd warning',
},
- DEVICE_MUL : {
- cssState: "device-detected-mul warning",
+ DEVICE_MUL: {
+ cssState: 'device-detected-mul warning',
},
- ERROR_NO_NETWORK : {
- cssState : "warning-no-conf",
+ ERROR_NO_NETWORK: {
+ cssState: 'warning-no-conf',
},
- ERROR_DEVICE_TOO_SMALL : {
- cssState : "warning-no-conf",
+ ERROR_DEVICE_TOO_SMALL: {
+ cssState: 'warning-no-conf',
},
- PROGRESS_DOWNLOAD : {
- cssState : "progress progress-canceble",
+ PROGRESS_DOWNLOAD: {
+ cssState: 'progress progress-canceble',
},
- PROGRESS_UNZIP : {
- cssState : "progress progress-canceble",
+ PROGRESS_UNZIP: {
+ cssState: 'progress progress-canceble',
},
- PROGRESS_BURN : {
- cssState : "progress",
+ PROGRESS_BURN: {
+ cssState: 'progress',
},
- FAIL : {
- cssState : "error",
+ FAIL: {
+ cssState: 'error',
},
- SUCCESS : {
- cssState : "success",
+ SUCCESS: {
+ cssState: 'success',
},
};
State.prototype = {
+ /**
+ * Sets the state strings.
+ * @param {Object} strings Localized state strings.
+ */
setStrings: function(strings) {
State.StatesEnum.DEVICE_NONE.statusText =
strings.getString('statusDevicesNone');
@@ -74,6 +85,10 @@ State.prototype = {
State.StatesEnum.SUCCESS.warningText = strings.getString('warningSuccess');
},
+ /**
+ * Changes the current state to new state.
+ * @param {Object} newState Specifies the new state object.
+ */
changeState: function(newState) {
if (newState == this.state)
return;
@@ -83,9 +98,8 @@ State.prototype = {
$('status-text').textContent = this.state.statusText;
- if (newState.warningText) {
+ if (newState.warningText)
$('warning-text').textContent = this.state.warningText;
- }
if (this.isInitialState() && this.state != State.StatesEnum.DEVICE_NONE) {
$('warning-button').textContent = localStrings.getString('confirmButton');
@@ -95,38 +109,61 @@ State.prototype = {
}
},
+ /**
+ * Reset to initial state.
+ * @param {number} deviceCount Device count information.
+ */
gotoInitialState: function(deviceCount) {
- if (deviceCount == 0) {
+ if (deviceCount == 0)
this.changeState(State.StatesEnum.DEVICE_NONE);
- } else if (deviceCount == 1) {
+ else if (deviceCount == 1)
this.changeState(State.StatesEnum.DEVICE_USB);
- } else {
+ else
this.changeState(State.StatesEnum.DEVICE_MUL);
- }
},
+ /**
+ * Returns true if the device is in initial state.
+ * @return {boolean} True if the device is in initial state else false.
+ */
isInitialState: function() {
- return (this.state == State.StatesEnum.DEVICE_NONE ||
- this.state == State.StatesEnum.DEVICE_USB ||
- this.state == State.StatesEnum.DEVICE_SD ||
- this.state == State.StatesEnum.DEVICE_MUL);
+ return this.state == State.StatesEnum.DEVICE_NONE ||
+ this.state == State.StatesEnum.DEVICE_USB ||
+ this.state == State.StatesEnum.DEVICE_SD ||
+ this.state == State.StatesEnum.DEVICE_MUL;
},
+ /**
+ * Returns true if device state matches the given state name.
+ * @param {string} stateName Given state name.
+ * @return {boolean} True if the device state matches the given state name.
+ */
equals: function(stateName) {
return this.state == stateName;
}
};
-// Class that keeps track of available devices.
+/**
+ * Class that keeps track of available devices.
+ * @constructor
+ */
function DeviceSelection() {
this.deviceCount = 0;
-};
+}
DeviceSelection.prototype = {
+ /**
+ * Clears the given selection list.
+ * @param {Array} list Device selection list.
+ */
clearSelectList: function(list) {
list.innerHtml = '';
},
+ /**
+ * Shows the currently selected device.
+ * @return {number} Selected device count.
+ */
showDeviceSelection: function() {
if (this.deviceCount == 0) {
this.selectedDevice = undefined;
@@ -137,6 +174,12 @@ DeviceSelection.prototype = {
return this.deviceCount;
},
+ /**
+ * Handles device selected event.
+ * @param {string} label Device label.
+ * @param {string} filePath File path.
+ * @param {string} devicePath Selected device path.
+ */
onDeviceSelected: function(label, filePath, devicePath) {
$('warning-button').onclick =
browserBridge.sendBurnImageMessage.bind(browserBridge, filePath,
@@ -148,12 +191,21 @@ DeviceSelection.prototype = {
localStrings.getStringF('warningDevices', label);
},
+ /**
+ * Selects the specified device based on the specified path.
+ * @param {string} path Device path.
+ */
selectDevice: function(path) {
var element = $('radio ' + path);
element.checked = true;
element.onclick.apply(element);
},
+ /**
+ * Creates a new device element.
+ * @param {Object} device Specifies new device information.
+ * @return {HTMLLIElement} New device element.
+ */
createNewDeviceElement: function(device) {
var element = document.createElement('li');
var radioButton = document.createElement('input');
@@ -178,6 +230,11 @@ DeviceSelection.prototype = {
return element;
},
+ /**
+ * Updates the list of selected devices.
+ * @param {Array} devices List of devices.
+ * @return {number} Device count.
+ */
getDevicesCallback: function(devices) {
var selectListDOM = $('device-selection');
this.clearSelectList(selectListDOM);
@@ -194,6 +251,12 @@ DeviceSelection.prototype = {
return this.deviceCount;
},
+ /**
+ * Handles device added event.
+ * @param {Object} device Device information.
+ * @param {boolean} allowSelect True to update the selected device info.
+ * @return {number} Device count.
+ */
deviceAdded: function(device, allowSelect) {
var selectListDOM = $('device-selection');
selectListDOM.appendChild(this.createNewDeviceElement(device));
@@ -203,6 +266,12 @@ DeviceSelection.prototype = {
return this.deviceCount;
},
+ /**
+ * Handles device removed event.
+ * @param {string} devicePath Selected device path.
+ * @param {boolean} allowSelect True to update the selected device info.
+ * @return {number} Device count.
+ */
deviceRemoved: function(devicePath, allowSelect) {
var deviceSelectElement = $('select ' + devicePath);
deviceSelectElement.parentNode.removeChild(deviceSelectElement);
@@ -221,7 +290,10 @@ DeviceSelection.prototype = {
}
};
-// Class that handles communication with chrome.
+/**
+ * Class that handles communication with chrome.
+ * @constructor
+ */
function BrowserBridge() {
this.currentState = new State(localStrings);
this.devices = new DeviceSelection();
@@ -230,21 +302,26 @@ function BrowserBridge() {
this.progressElement = $('progress-div');
this.progressText = $('progress-text');
this.progressTimeLeftText = $('pending-time');
-};
+}
BrowserBridge.prototype = {
sendCancelMessage: function() {
- chrome.send("cancelBurnImage");
+ chrome.send('cancelBurnImage');
},
sendGetDevicesMessage: function() {
- chrome.send("getDevices");
+ chrome.send('getDevices');
},
sendWebuiInitializedMessage: function() {
- chrome.send("webuiInitialized");
+ chrome.send('webuiInitialized');
},
+ /**
+ * Sends the burn image message to c++ code.
+ * @param {string} filePath Specifies the file path.
+ * @param {string} devicePath Specifies the device path.
+ */
sendBurnImageMessage: function(filePath, devicePath) {
chrome.send('burnImage', [devicePath, filePath]);
},
@@ -253,12 +330,21 @@ BrowserBridge.prototype = {
this.currentState.changeState(State.StatesEnum.SUCCESS);
},
+ /**
+ * Update the device state to report a failure and display an error message to
+ * the user.
+ * @param {string} errorMessage Specifies the warning text message.
+ */
reportFail: function(errorMessage) {
this.currentState.changeState(State.StatesEnum.FAIL);
$('warning-text').textContent = errorMessage;
$('warning-button').onclick = this.onBurnRetry.bind(this);
},
+ /**
+ * Handles device added event.
+ * @param {Object} device Device information.
+ */
deviceAdded: function(device) {
var inInitialState = this.currentState.isInitialState();
var deviceCount = this.devices.deviceAdded(device, inInitialState);
@@ -266,6 +352,10 @@ BrowserBridge.prototype = {
this.currentState.gotoInitialState(deviceCount);
},
+ /**
+ * Handles device removed event.
+ * @param {Object} device Device information.
+ */
deviceRemoved: function(device) {
var inInitialState = this.currentState.isInitialState();
var deviceCount = this.devices.deviceRemoved(device, inInitialState);
@@ -273,33 +363,41 @@ BrowserBridge.prototype = {
this.currentState.gotoInitialState(deviceCount);
},
+ /**
+ * Gets device callbacks and update the current state.
+ * @param {Array} devices List of devices.
+ */
getDevicesCallback: function(devices) {
var deviceCount = this.devices.getDevicesCallback(devices);
this.currentState.gotoInitialState(deviceCount);
this.sendWebuiInitializedMessage();
},
- updateProgress: function(update_signal) {
- if (update_signal.progressType == 'download' &&
+ /**
+ * Updates the progress information based on the signal received.
+ * @param {Object} updateSignal Specifies the signal information.
+ */
+ updateProgress: function(updateSignal) {
+ if (updateSignal.progressType == 'download' &&
!this.currentState.equals(State.StatesEnum.PROGRESS_DOWNLOAD)) {
this.currentState.changeState(State.StatesEnum.PROGRESS_DOWNLOAD);
- } else if (update_signal.progressType == 'unzip' &&
+ } else if (updateSignal.progressType == 'unzip' &&
!this.currentState.equals(State.StatesEnum.PROGRESS_UNZIP)) {
this.currentState.changeState(State.StatesEnum.PROGRESS_UNZIP);
- } else if (update_signal.progressType == 'burn' &&
+ } else if (updateSignal.progressType == 'burn' &&
!this.currentState.equals(State.StatesEnum.PROGRESS_BURN)) {
this.currentState.changeState(State.StatesEnum.PROGRESS_BURN);
}
- if (!(update_signal.amountTotal > 0)) {
+ if (!(updateSignal.amountTotal > 0)) {
this.progressElement.removeAttribute('value');
} else {
- this.progressElement.value = update_signal.amountFinished;
- this.progressElement.max = update_signal.amountTotal;
+ this.progressElement.value = updateSignal.amountFinished;
+ this.progressElement.max = updateSignal.amountTotal;
}
- this.progressText.textContent = update_signal.progressText;
- this.progressTimeLeftText.textContent = update_signal.timeLeftText;
+ this.progressText.textContent = updateSignal.progressText;
+ this.progressTimeLeftText.textContent = updateSignal.timeLeftText;
},
reportNoNetwork: function() {
@@ -313,14 +411,20 @@ BrowserBridge.prototype = {
}
},
- reportDeviceTooSmall: function(device_size) {
+ /**
+ * Updates the current state to report device too small error.
+ * @param {number} deviceSize Received device size.
+ */
+ reportDeviceTooSmall: function(deviceSize) {
this.currentState.changeState(State.StatesEnum.ERROR_DEVICE_TOO_SMALL);
$('warning-text').textContent =
- localStrings.getStringF('warningNoSpace', device_size);
+ localStrings.getStringF('warningNoSpace', deviceSize);
},
- // Processes click on "Retry" button in FAIL state.
- onBurnRetry: function () {
+ /**
+ * Processes click on 'Retry' button in FAIL state.
+ */
+ onBurnRetry: function() {
var deviceCount = this.devices.showDeviceSelection();
this.currentState.gotoInitialState(deviceCount);
}
@@ -330,7 +434,7 @@ document.addEventListener('DOMContentLoaded', function() {
localStrings = new LocalStrings();
browserBridge = new BrowserBridge();
- jstProcess(new JsEvalContext(templateData), $("more-info-link"));
+ jstProcess(new JsEvalContext(templateData), $('more-info-link'));
$('cancel-button').onclick =
browserBridge.sendCancelMessage.bind(browserBridge);
« no previous file with comments | « chrome/browser/resources/chromeos/choose_mobile_network.js ('k') | chrome/browser/resources/chromeos/keyboard_overlay.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698