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..4053b6fef88b79d6d7c43f1720d937b64058c014 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 |
@@ -27,10 +27,10 @@ function DriveSyncHandler(progressCenter) { |
/** |
* Map of file urls and progress center items. |
- * @type {Object.<string, ProgressCenterItem>} |
+ * @type {ProgressCenterItem} |
* @private |
*/ |
- this.items_ = {}; |
+ this.item_ = new ProgressCenterItem(); |
/** |
* Async queue. |
@@ -85,13 +85,15 @@ 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 (status.num_total_jobs === 0) |
+ this.removeItem_(status); |
if (!this.syncing) |
this.dispatchEvent(new Event(DriveSyncHandler.COMPLETED_EVENT)); |
break; |
@@ -109,19 +111,27 @@ DriveSyncHandler.prototype.onFileTransfersUpdated_ = function(statusList) { |
*/ |
DriveSyncHandler.prototype.updateItem_ = function(status) { |
this.queue_.run(function(callback) { |
- if (this.items_[status.fileUrl]) { |
+ if (!this.item_) { |
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_.id) { |
+ this.item_.id = |
+ DriveSyncHandler.PROGRESS_ITEM_ID_PREFIX + (this.idCounter_); |
+ } |
+ if (this.item_.state !== ProgressItemState.PROGRESSING) { |
+ this.item_.state = ProgressItemState.PROGRESSING; |
+ } |
+ this.item_.type = ProgressItemType.SYNC; |
+ this.item_.quiet = 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); |
+ } |
+ console.log(this.item_.message); |
+ this.item_.cancelCallback = this.requestCancel_.bind(this, entry); |
callback(); |
}.bind(this), function(error) { |
console.warn('Resolving URL ' + status.fileUrl + ' is failed: ', error); |
@@ -129,14 +139,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 +157,13 @@ 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_); |
callback(); |
}.bind(this)); |
}; |
@@ -177,24 +184,25 @@ 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; |
+ if (!this.item_.id) { |
+ this.item_.id = |
+ DriveSyncHandler.PROGRESS_ITEM_ID_PREFIX + (this.idCounter_); |
+ } |
+ this.item_.type = ProgressItemType.SYNC; |
+ this.item_.quiet = true; |
+ 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)); |
}; |