Chromium Code Reviews| Index: ui/file_manager/file_manager/background/js/drive_sync_handler.js |
| diff --git a/ui/file_manager/file_manager/background/js/drive_sync_handler.js b/ui/file_manager/file_manager/background/js/drive_sync_handler.js |
| index f655957ebecb09184905ab6f91a9134972bd7aca..5145b656e47a5cb1ceccc9fadf5618df8b2bf61b 100644 |
| --- a/ui/file_manager/file_manager/background/js/drive_sync_handler.js |
| +++ b/ui/file_manager/file_manager/background/js/drive_sync_handler.js |
| @@ -19,18 +19,18 @@ function DriveSyncHandler(progressCenter) { |
| this.progressCenter_ = progressCenter; |
| /** |
| - * Counter for progress ID. |
| - * @type {number} |
| + * Progress center item. |
| + * @type {ProgressCenterItem} |
| * @private |
| */ |
| - this.idCounter_ = 0; |
| + this.item_ = new ProgressCenterItem(); |
| + this.item_.id = 'drive-sync'; |
| - /** |
| - * Map of file urls and progress center items. |
| - * @type {Object.<string, ProgressCenterItem>} |
| - * @private |
| + /** |
|
hirono
2014/08/29 11:50:46
Please fix the indent.
iseki
2014/09/01 02:24:47
Done.
|
| + * If the property is true, this item is syncing. |
| + * @type {boolean} |
|
hirono
2014/08/29 11:50:46
@private
iseki
2014/09/01 02:24:47
Done.
|
| */ |
| - this.items_ = {}; |
| + this.syncing_ = false; |
| /** |
| * Async queue. |
| @@ -67,11 +67,7 @@ DriveSyncHandler.prototype = { |
| * @return {boolean} Whether the handler is having syncing items or not. |
| */ |
| get syncing() { |
| - // Check if this.items_ has properties or not. |
| - for (var url in this.items_) { |
| - return true; |
| - } |
| - return false; |
| + return this.syncing_; |
| } |
| }; |
| @@ -85,14 +81,16 @@ DriveSyncHandler.prototype.onFileTransfersUpdated_ = function(statusList) { |
| for (var i = 0; i < statusList.length; i++) { |
| var status = statusList[i]; |
| switch (status.transferState) { |
| + case 'added': |
| case 'in_progress': |
| case 'started': |
| this.updateItem_(status); |
| break; |
| case 'completed': |
| case 'failed': |
| - this.removeItem_(status); |
| - if (!this.syncing) |
| + if (status.num_total_jobs === 0) |
| + this.removeItem_(status); |
| + if (!this.syncing_) |
| this.dispatchEvent(new Event(DriveSyncHandler.COMPLETED_EVENT)); |
| break; |
| default: |
| @@ -109,19 +107,17 @@ DriveSyncHandler.prototype.onFileTransfersUpdated_ = function(statusList) { |
| */ |
| DriveSyncHandler.prototype.updateItem_ = function(status) { |
| this.queue_.run(function(callback) { |
| - if (this.items_[status.fileUrl]) { |
| - callback(); |
| - return; |
| - } |
| webkitResolveLocalFileSystemURL(status.fileUrl, function(entry) { |
| - var item = new ProgressCenterItem(); |
| - item.id = |
| - DriveSyncHandler.PROGRESS_ITEM_ID_PREFIX + (this.idCounter_++); |
| - item.type = ProgressItemType.SYNC; |
| - item.quiet = true; |
| - item.message = strf('SYNC_FILE_NAME', entry.name); |
| - item.cancelCallback = this.requestCancel_.bind(this, entry); |
| - this.items_[status.fileUrl] = item; |
| + if (this.item_.state !== ProgressItemState.PROGRESSING) |
| + this.item_.state = ProgressItemState.PROGRESSING; |
| + this.item_.type = ProgressItemType.SYNC; |
| + this.item_.quiet = true; |
| + this.syncing_ = true; |
| + if (status.num_total_jobs > 1) |
| + this.item_.message = strf('SYNC_FILE_NUMBER', status.num_total_jobs); |
| + else |
| + this.item_.message = strf('SYNC_FILE_NAME', entry.name); |
| + this.item_.cancelCallback = this.requestCancel_.bind(this, entry); |
| callback(); |
| }.bind(this), function(error) { |
| console.warn('Resolving URL ' + status.fileUrl + ' is failed: ', error); |
| @@ -129,14 +125,13 @@ DriveSyncHandler.prototype.updateItem_ = function(status) { |
| }); |
| }.bind(this)); |
| this.queue_.run(function(callback) { |
| - var item = this.items_[status.fileUrl]; |
| - if (!item) { |
| + if (!this.item_) { |
| callback(); |
| return; |
| } |
| - item.progressValue = status.processed || 0; |
| - item.progressMax = status.total || 1; |
| - this.progressCenter_.updateItem(item); |
| + this.item_.progressValue = status.processed || 0; |
| + this.item_.progressMax = status.total || 1; |
| + this.progressCenter_.updateItem(this.item_); |
| callback(); |
| }.bind(this)); |
| }; |
| @@ -148,15 +143,14 @@ DriveSyncHandler.prototype.updateItem_ = function(status) { |
| */ |
| DriveSyncHandler.prototype.removeItem_ = function(status) { |
| this.queue_.run(function(callback) { |
| - var item = this.items_[status.fileUrl]; |
| - if (!item) { |
| + if (!this.item_) { |
| callback(); |
| return; |
| } |
| - item.state = status.transferState === 'completed' ? |
| + this.item_.state = status.transferState === 'completed' ? |
| ProgressItemState.COMPLETED : ProgressItemState.CANCELED; |
| - this.progressCenter_.updateItem(item); |
| - delete this.items_[status.fileUrl]; |
| + this.progressCenter_.updateItem(this.item_); |
| + this.syncing_ = false; |
| callback(); |
| }.bind(this)); |
| }; |
| @@ -177,24 +171,22 @@ DriveSyncHandler.prototype.requestCancel_ = function(entry) { |
| */ |
| DriveSyncHandler.prototype.onDriveSyncError_ = function(event) { |
| webkitResolveLocalFileSystemURL(event.fileUrl, function(entry) { |
| - var item; |
| - item = new ProgressCenterItem(); |
| - item.id = DriveSyncHandler.PROGRESS_ITEM_ID_PREFIX + (this.idCounter_++); |
| - item.type = ProgressItemType.SYNC; |
| - item.quiet = true; |
| - item.state = ProgressItemState.ERROR; |
| + this.item_.type = ProgressItemType.SYNC; |
| + this.item_.quiet = true; |
| + this.syncing_ = false; |
| + this.item_.state = ProgressItemState.ERROR; |
| switch (event.type) { |
| case 'delete_without_permission': |
| - item.message = |
| + this.item_.message = |
| strf('SYNC_DELETE_WITHOUT_PERMISSION_ERROR', entry.name); |
| break; |
| case 'service_unavailable': |
| - item.message = str('SYNC_SERVICE_UNAVAILABLE_ERROR'); |
| + this.item_.message = str('SYNC_SERVICE_UNAVAILABLE_ERROR'); |
| break; |
| case 'misc': |
| - item.message = strf('SYNC_MISC_ERROR', entry.name); |
| + this.item_.message = strf('SYNC_MISC_ERROR', entry.name); |
| break; |
| } |
| - this.progressCenter_.updateItem(item); |
| + this.progressCenter_.updateItem(this.item_); |
| }.bind(this)); |
| }; |