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