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

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: Reverted document.getElementById changes in keyboard_overlay.js 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..50057606c64808a44db40ec48b9c44458b188cc2 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;
@@ -95,6 +110,10 @@ State.prototype = {
}
},
+ /**
+ * Reset to initial state.
+ * @param {number} deviceCount Device count information.
+ */
gotoInitialState: function(deviceCount) {
if (deviceCount == 0) {
Dan Beam 2012/05/11 01:06:09 nit: no curlies
kmadhusu 2012/05/11 21:52:42 Done.
this.changeState(State.StatesEnum.DEVICE_NONE);
@@ -105,6 +124,10 @@ State.prototype = {
}
},
+ /**
+ * 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 ||
Dan Beam 2012/05/11 01:06:09 nit: remove ()
kmadhusu 2012/05/11 21:52:42 Done.
this.state == State.StatesEnum.DEVICE_USB ||
@@ -112,21 +135,37 @@ State.prototype = {
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 = '';
},
+ /**
+ * Returns the selected device count.
Dan Beam 2012/05/11 01:06:09 Shouldn't this say: Shows the currently selecte
kmadhusu 2012/05/11 21:52:42 Done.
+ * @return {number} Selected device count.
+ */
showDeviceSelection: function() {
if (this.deviceCount == 0) {
this.selectedDevice = undefined;
@@ -137,6 +176,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 +193,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 +232,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 +253,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 +268,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 +292,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 +304,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 +332,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 +354,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,12 +365,20 @@ 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();
},
+ /**
+ * Updates the progress information based on the signal received.
+ * @param {Object} update_signal Specifies the signal information.
Dan Beam 2012/05/11 01:06:09 nit: updateSignal
kmadhusu 2012/05/11 21:52:42 Done.
+ */
updateProgress: function(update_signal) {
if (update_signal.progressType == 'download' &&
!this.currentState.equals(State.StatesEnum.PROGRESS_DOWNLOAD)) {
@@ -313,14 +413,20 @@ BrowserBridge.prototype = {
}
},
+ /**
+ * Updates the current state to report device too small error.
+ * @param {number} device_size Received device size.
Dan Beam 2012/05/11 01:06:09 nit: deviceSize
kmadhusu 2012/05/11 21:52:42 Done.
+ */
reportDeviceTooSmall: function(device_size) {
this.currentState.changeState(State.StatesEnum.ERROR_DEVICE_TOO_SMALL);
$('warning-text').textContent =
localStrings.getStringF('warningNoSpace', device_size);
},
- // 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 +436,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);

Powered by Google App Engine
This is Rietveld 408576698