1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 * Event of the ProgressCenter class.
12 var ProgressCenterEvent = Object.freeze({
14 * Background page notifies item update to application windows.
16 ITEM_UPDATED: 'itemUpdated',
19 * Background page notifies all the items are cleared.
25 * State of progress items.
29 var ProgressItemState = Object.freeze({
30 PROGRESSING: 'progressing',
31 COMPLETED: 'completed',
37 * Type of progress items.
41 var ProgressItemType = Object.freeze({
42 // The item is file copy operation.
44 // The item is file move operation.
46 // The item is file delete operation.
48 // The item is file zip operation.
50 // The item is drive sync operation.
52 // The item is general file transfer operation.
53 // This is used for the mixed operation of summarized item.
58 * Item of the progress center.
61 var ProgressCenterItem = function() {
70 * State of the progress item.
71 * @type {ProgressItemState}
73 this.state = ProgressItemState.PROGRESSING;
76 * Message of the progress item.
82 * Max value of the progress.
88 * Current value of the progress.
91 this.progressValue = 0;
94 * Type of progress item.
95 * @type {ProgressItemType}
100 * Whether the item represents a single item or not.
106 * If the property is true, only the message of item shown in the progress
107 * center and the notification of the item is created as priority = -1.
113 * Callback function to cancel the item.
116 this.cancelCallback = null;
118 // This object is instantiated many time. Object.seal use more memory
119 // than Object.preventExtensions (crbug.com/412307)
120 Object.preventExtensions(this);
123 ProgressCenterItem.prototype = {
126 * @param {string} value New value of ID.
132 console.error('The ID is already set. (current ID: ' + this.id_ + ')');
137 * @return {string} Item ID.
144 * Gets progress rate in percent.
146 * If the current state is canceled or completed, it always returns 0 or 100
149 * @return {number} Progress rate in percent.
151 get progressRateInPercent() {
152 switch (this.state) {
153 case ProgressItemState.CANCELED: return 0;
154 case ProgressItemState.COMPLETED: return 100;
155 default: return ~~(100 * this.progressValue / this.progressMax);
160 * Whether the item can be canceled or not.
161 * @return {boolean} True if the item can be canceled.
164 return !!(this.state == ProgressItemState.PROGRESSING &&
165 this.cancelCallback &&
172 * @return {ProgressCenterItem} New item having the same properties with this.
174 ProgressCenterItem.prototype.clone = function() {
175 var newItem = new ProgressCenterItem();
176 newItem.id = this.id;
177 newItem.state = this.state;
178 newItem.message = this.message;
179 newItem.progressMax = this.progressMax;
180 newItem.progressValue = this.progressValue;
181 newItem.type = this.type;
182 newItem.single = this.single;
183 newItem.quiet = this.quiet;
184 newItem.cancelCallback = this.cancelCallback;