Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: ui/file_manager/file_manager/background/js/drive_sync_handler.js

Issue 507293002: Enrich fileBrowserPrivate.onFileTransfersUpdated event to support displaying total number of jobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..31575c7912a45b2b6ec45b1bb97eccc2dce11bfc 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,11 @@ function DriveSyncHandler(progressCenter) {
this.progressCenter_ = progressCenter;
/**
- * Counter for progress ID.
- * @type {number}
- * @private
- */
- this.idCounter_ = 0;
-
- /**
* Map of file urls and progress center items.
hirono 2014/08/29 03:34:17 Please update the comment.
- * @type {Object.<string, ProgressCenterItem>}
+ * @type {ProgressCenterItem}
* @private
*/
- this.items_ = {};
+ this.item_ = new ProgressCenterItem();
hirono 2014/08/29 03:34:16 Assign ID with DriveSyncHandler.PROGRESS_ITEM_ID_P
/**
* Async queue.
@@ -68,10 +61,10 @@ DriveSyncHandler.prototype = {
*/
get syncing() {
// Check if this.items_ has properties or not.
- for (var url in this.items_) {
- return true;
+ if (this.item_.id === '') {
hirono 2014/08/29 03:34:17 Maybe we should check this.item_ !== null.
iseki 2014/08/29 04:21:08 Done.
+ return false;
}
- return false;
+ return true;
}
};
@@ -85,13 +78,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 +104,27 @@ DriveSyncHandler.prototype.onFileTransfersUpdated_ = function(statusList) {
*/
DriveSyncHandler.prototype.updateItem_ = function(status) {
this.queue_.run(function(callback) {
- if (this.items_[status.fileUrl]) {
+ if (!this.item_) {
hirono 2014/08/29 03:34:16 Can the item be null?
iseki 2014/08/29 04:21:08 Done.
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) {
hirono 2014/08/29 03:34:17 Maybe we should check this.item_ !== null.
iseki 2014/08/29 04:21:08 Done.
+ this.item_.id =
+ DriveSyncHandler.PROGRESS_ITEM_ID_PREFIX;
+ }
+ 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);
hirono 2014/08/29 03:34:16 Please remove the debug log.
iseki 2014/08/29 04:21:08 Done.
+ this.item_.cancelCallback = this.requestCancel_.bind(this, entry);
callback();
}.bind(this), function(error) {
console.warn('Resolving URL ' + status.fileUrl + ' is failed: ', error);
@@ -129,14 +132,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 +150,15 @@ 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_);
+ delete this.item_;
hirono 2014/08/29 03:34:17 We usually do this.item_ = null, instead of deleti
iseki 2014/08/29 04:21:08 Done.
+ this.item_ = new ProgressCenterItem();
callback();
}.bind(this));
};
@@ -177,24 +179,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) {
hirono 2014/08/29 03:34:16 Maybe we should check this.item_ !== null.
iseki 2014/08/29 04:21:08 Done.
+ this.item_.id =
+ DriveSyncHandler.PROGRESS_ITEM_ID_PREFIX;
+ }
+ 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));
};

Powered by Google App Engine
This is Rietveld 408576698