Commit 761e2f97 authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

Make ProgressCenter externs file an @interface

 - change ProgressCenter externs file to be an @interface class
 - rename background page ProgressCenter to ProgressCenterImpl,
   and make it @implement the {ProgressCenter} interface
 - use ProgressCenterImpl as the implementation for Files App.
 - make MockProgressCenter @implement ProgressCenter for tests
 - add missing ProgressCenter methods to MockProgressCenter to
   make it Closure compile.
 - BUILD rules for progress_center, and mock_progress_center,
   were added in CL:1349139, and CL:1349147, respectively.

No change in test behavior, no new tests.

Bug: 908379
Change-Id: I087b72abce9221d464761724e3fcf2ccdb2dfad5
Reviewed-on: https://chromium-review.googlesource.com/c/1350563Reviewed-by: default avatarStuart Langley <slangley@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Noel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611005}
parent c76a0243
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
/** /**
* Progress center at the background page. * Progress center at the background page.
* @constructor *
* @struct * @interface
*/ */
var ProgressCenter = function() {}; var ProgressCenter = function() {};
......
...@@ -16,7 +16,7 @@ function FileBrowserBackgroundImpl() { ...@@ -16,7 +16,7 @@ function FileBrowserBackgroundImpl() {
* Progress center of the background page. * Progress center of the background page.
* @type {!ProgressCenter} * @type {!ProgressCenter}
*/ */
this.progressCenter = new ProgressCenter(); this.progressCenter = new ProgressCenterImpl();
/** /**
* File operation manager. * File operation manager.
......
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
'use strict'; 'use strict';
/** /**
* Mock of Progress Center. * Mock implementation of {ProgressCenter} for tests.
*
* @constructor * @constructor
* @struct * @struct
* @implements {ProgressCenter}
*/ */
function MockProgressCenter() { function MockProgressCenter() {
/** /**
...@@ -31,3 +33,9 @@ MockProgressCenter.prototype.updateItem = function(item) { ...@@ -31,3 +33,9 @@ MockProgressCenter.prototype.updateItem = function(item) {
MockProgressCenter.prototype.getItemById = function(id) { MockProgressCenter.prototype.getItemById = function(id) {
return this.items[id]; return this.items[id];
}; };
MockProgressCenter.prototype.requestCancel = function() {};
MockProgressCenter.prototype.addPanel = function() {};
MockProgressCenter.prototype.removePanel = function() {};
...@@ -3,15 +3,13 @@ ...@@ -3,15 +3,13 @@
// found in the LICENSE file. // found in the LICENSE file.
/** /**
* Progress center at the background page. * Implementation of {ProgressCenter} at the background page.
* Silence closure complaint about re-definition of the ProgressCenter here
* found when we began compiling ProgessCenter.
* *
* @suppress {checkTypes}
* @constructor * @constructor
* @struct * @struct
* @implements {ProgressCenter}
*/ */
var ProgressCenter = function() { var ProgressCenterImpl = function() {
/** /**
* Current items managed by the progress center. * Current items managed by the progress center.
* @type {Array<!ProgressCenterItem>} * @type {Array<!ProgressCenterItem>}
...@@ -24,9 +22,8 @@ var ProgressCenter = function() { ...@@ -24,9 +22,8 @@ var ProgressCenter = function() {
* @type {Object<string>} * @type {Object<string>}
* @private * @private
*/ */
this.notifications_ = new ProgressCenter.Notifications_( this.notifications_ = new ProgressCenterImpl.Notifications_(
this.requestCancel.bind(this), this.requestCancel.bind(this), this.onNotificationDismissed_.bind(this));
this.onNotificationDismissed_.bind(this));
/** /**
* List of panel UI managed by the progress center. * List of panel UI managed by the progress center.
...@@ -46,10 +43,10 @@ var ProgressCenter = function() { ...@@ -46,10 +43,10 @@ var ProgressCenter = function() {
* @struct * @struct
* @private * @private
*/ */
ProgressCenter.Notifications_ = function(cancelCallback, dismissCallback) { ProgressCenterImpl.Notifications_ = function(cancelCallback, dismissCallback) {
/** /**
* ID set of notifications that is progressing now. * ID set of notifications that is progressing now.
* @type {Object<ProgressCenter.Notifications_.NotificationState_>} * @type {Object<ProgressCenterImpl.Notifications_.NotificationState_>}
* @private * @private
*/ */
this.ids_ = {}; this.ids_ = {};
...@@ -85,7 +82,7 @@ ProgressCenter.Notifications_ = function(cancelCallback, dismissCallback) { ...@@ -85,7 +82,7 @@ ProgressCenter.Notifications_ = function(cancelCallback, dismissCallback) {
* @const * @const
* @private * @private
*/ */
ProgressCenter.Notifications_.NotificationState_ = { ProgressCenterImpl.Notifications_.NotificationState_ = {
VISIBLE: 'visible', VISIBLE: 'visible',
DISMISSED: 'dismissed' DISMISSED: 'dismissed'
}; };
...@@ -95,9 +92,9 @@ ProgressCenter.Notifications_.NotificationState_ = { ...@@ -95,9 +92,9 @@ ProgressCenter.Notifications_.NotificationState_ = {
* @param {ProgressCenterItem} item Item to contain new information. * @param {ProgressCenterItem} item Item to contain new information.
* @param {boolean} newItemAcceptable Whether to accept new item or not. * @param {boolean} newItemAcceptable Whether to accept new item or not.
*/ */
ProgressCenter.Notifications_.prototype.updateItem = function( ProgressCenterImpl.Notifications_.prototype.updateItem = function(
item, newItemAcceptable) { item, newItemAcceptable) {
var NotificationState = ProgressCenter.Notifications_.NotificationState_; var NotificationState = ProgressCenterImpl.Notifications_.NotificationState_;
var newlyAdded = !(item.id in this.ids_); var newlyAdded = !(item.id in this.ids_);
// If new item is not acceptable, just return. // If new item is not acceptable, just return.
...@@ -151,7 +148,7 @@ ProgressCenter.Notifications_.prototype.updateItem = function( ...@@ -151,7 +148,7 @@ ProgressCenter.Notifications_.prototype.updateItem = function(
* Dismisses error item. * Dismisses error item.
* @param {string} id Item ID. * @param {string} id Item ID.
*/ */
ProgressCenter.Notifications_.prototype.dismissErrorItem = function(id) { ProgressCenterImpl.Notifications_.prototype.dismissErrorItem = function(id) {
if (!this.ids_[id]) if (!this.ids_[id])
return; return;
...@@ -167,7 +164,7 @@ ProgressCenter.Notifications_.prototype.dismissErrorItem = function(id) { ...@@ -167,7 +164,7 @@ ProgressCenter.Notifications_.prototype.dismissErrorItem = function(id) {
* @param {string} id Item ID. * @param {string} id Item ID.
* @private * @private
*/ */
ProgressCenter.Notifications_.prototype.onButtonClicked_ = function(id) { ProgressCenterImpl.Notifications_.prototype.onButtonClicked_ = function(id) {
if (id in this.ids_) if (id in this.ids_)
this.cancelCallback_(id); this.cancelCallback_(id);
}; };
...@@ -177,9 +174,10 @@ ProgressCenter.Notifications_.prototype.onButtonClicked_ = function(id) { ...@@ -177,9 +174,10 @@ ProgressCenter.Notifications_.prototype.onButtonClicked_ = function(id) {
* @param {string} id Item ID. * @param {string} id Item ID.
* @private * @private
*/ */
ProgressCenter.Notifications_.prototype.onClosed_ = function(id) { ProgressCenterImpl.Notifications_.prototype.onClosed_ = function(id) {
if (id in this.ids_) { if (id in this.ids_) {
this.ids_[id] = ProgressCenter.Notifications_.NotificationState_.DISMISSED; this.ids_[id] =
ProgressCenterImpl.Notifications_.NotificationState_.DISMISSED;
this.dismissCallback_(id); this.dismissCallback_(id);
} }
}; };
...@@ -190,7 +188,7 @@ ProgressCenter.Notifications_.prototype.onClosed_ = function(id) { ...@@ -190,7 +188,7 @@ ProgressCenter.Notifications_.prototype.onClosed_ = function(id) {
* *
* @param {ProgressCenterItem} item Updated item. * @param {ProgressCenterItem} item Updated item.
*/ */
ProgressCenter.prototype.updateItem = function(item) { ProgressCenterImpl.prototype.updateItem = function(item) {
// Update item. // Update item.
var index = this.getItemIndex_(item.id); var index = this.getItemIndex_(item.id);
if (item.state === ProgressItemState.PROGRESSING) { if (item.state === ProgressItemState.PROGRESSING) {
...@@ -217,7 +215,7 @@ ProgressCenter.prototype.updateItem = function(item) { ...@@ -217,7 +215,7 @@ ProgressCenter.prototype.updateItem = function(item) {
* Requests to cancel the progress item. * Requests to cancel the progress item.
* @param {string} id Progress ID to be requested to cancel. * @param {string} id Progress ID to be requested to cancel.
*/ */
ProgressCenter.prototype.requestCancel = function(id) { ProgressCenterImpl.prototype.requestCancel = function(id) {
var item = this.getItemById(id); var item = this.getItemById(id);
if (item && item.cancelCallback) if (item && item.cancelCallback)
item.cancelCallback(); item.cancelCallback();
...@@ -228,7 +226,7 @@ ProgressCenter.prototype.requestCancel = function(id) { ...@@ -228,7 +226,7 @@ ProgressCenter.prototype.requestCancel = function(id) {
* @param {string} id Item id. * @param {string} id Item id.
* @private * @private
*/ */
ProgressCenter.prototype.onNotificationDismissed_ = function(id) { ProgressCenterImpl.prototype.onNotificationDismissed_ = function(id) {
var item = this.getItemById(id); var item = this.getItemById(id);
if (item && item.state === ProgressItemState.ERROR) if (item && item.state === ProgressItemState.ERROR)
this.dismissErrorItem_(id); this.dismissErrorItem_(id);
...@@ -238,7 +236,7 @@ ProgressCenter.prototype.onNotificationDismissed_ = function(id) { ...@@ -238,7 +236,7 @@ ProgressCenter.prototype.onNotificationDismissed_ = function(id) {
* Adds a panel UI to the notification center. * Adds a panel UI to the notification center.
* @param {ProgressCenterPanel} panel Panel UI. * @param {ProgressCenterPanel} panel Panel UI.
*/ */
ProgressCenter.prototype.addPanel = function(panel) { ProgressCenterImpl.prototype.addPanel = function(panel) {
if (this.panels_.indexOf(panel) !== -1) if (this.panels_.indexOf(panel) !== -1)
return; return;
...@@ -260,7 +258,7 @@ ProgressCenter.prototype.addPanel = function(panel) { ...@@ -260,7 +258,7 @@ ProgressCenter.prototype.addPanel = function(panel) {
* Removes a panel UI from the notification center. * Removes a panel UI from the notification center.
* @param {ProgressCenterPanel} panel Panel UI. * @param {ProgressCenterPanel} panel Panel UI.
*/ */
ProgressCenter.prototype.removePanel = function(panel) { ProgressCenterImpl.prototype.removePanel = function(panel) {
var index = this.panels_.indexOf(panel); var index = this.panels_.indexOf(panel);
if (index === -1) if (index === -1)
return; return;
...@@ -281,7 +279,7 @@ ProgressCenter.prototype.removePanel = function(panel) { ...@@ -281,7 +279,7 @@ ProgressCenter.prototype.removePanel = function(panel) {
* @return {ProgressCenterItem} Progress center item having the specified * @return {ProgressCenterItem} Progress center item having the specified
* ID. Null if the item is not found. * ID. Null if the item is not found.
*/ */
ProgressCenter.prototype.getItemById = function(id) { ProgressCenterImpl.prototype.getItemById = function(id) {
return this.items_[this.getItemIndex_(id)]; return this.items_[this.getItemIndex_(id)];
}; };
...@@ -291,7 +289,7 @@ ProgressCenter.prototype.getItemById = function(id) { ...@@ -291,7 +289,7 @@ ProgressCenter.prototype.getItemById = function(id) {
* @return {number} Item index. Returns -1 If the item is not found. * @return {number} Item index. Returns -1 If the item is not found.
* @private * @private
*/ */
ProgressCenter.prototype.getItemIndex_ = function(id) { ProgressCenterImpl.prototype.getItemIndex_ = function(id) {
for (var i = 0; i < this.items_.length; i++) { for (var i = 0; i < this.items_.length; i++) {
if (this.items_[i].id === id) if (this.items_[i].id === id)
return i; return i;
...@@ -304,7 +302,7 @@ ProgressCenter.prototype.getItemIndex_ = function(id) { ...@@ -304,7 +302,7 @@ ProgressCenter.prototype.getItemIndex_ = function(id) {
* @param {string} id Item ID. * @param {string} id Item ID.
* @private * @private
*/ */
ProgressCenter.prototype.dismissErrorItem_ = function(id) { ProgressCenterImpl.prototype.dismissErrorItem_ = function(id) {
var index = this.getItemIndex_(id); var index = this.getItemIndex_(id);
if (index > -1) if (index > -1)
this.items_.splice(index, 1); this.items_.splice(index, 1);
......
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