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

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..6a1560a5b80ea1bb59a0faa362c2513266568cbb 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,26 @@ 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
- */
- this.items_ = {};
+ /**
+ * If the property is true, this item is syncing.
+ * @type {boolean}
+ * @private
+ */
+ this.syncing_ = false;
+
+ /**
+ * If the property is true, this item is syncing.
+ * @type {boolean}
+ * @private
+ */
+ this.successWebkitResolveLocalFileSystemURL = false;
/**
* Async queue.
@@ -67,11 +75,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,15 +89,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 (!this.syncing)
- this.dispatchEvent(new Event(DriveSyncHandler.COMPLETED_EVENT));
+ if (status.num_total_jobs === 0)
+ this.removeItem_(status);
break;
default:
throw new Error(
@@ -108,20 +112,19 @@ DriveSyncHandler.prototype.onFileTransfersUpdated_ = function(statusList) {
* @private
*/
DriveSyncHandler.prototype.updateItem_ = function(status) {
+ this.successWebkitResolveLocalFileSystemURL = false;
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;
+ 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);
+ this.successWebkitResolveLocalFileSystemURL = true;
callback();
}.bind(this), function(error) {
console.warn('Resolving URL ' + status.fileUrl + ' is failed: ', error);
@@ -129,14 +132,15 @@ DriveSyncHandler.prototype.updateItem_ = function(status) {
});
}.bind(this));
this.queue_.run(function(callback) {
- var item = this.items_[status.fileUrl];
- if (!item) {
+ if (!this.successWebkitResolveLocalFileSystemURL) {
hirono 2014/09/01 07:29:02 There is a race. 1. Call updateItem_ (successWebk
iseki 2014/09/01 09:26:40 Done.
callback();
return;
}
- item.progressValue = status.processed || 0;
- item.progressMax = status.total || 1;
- this.progressCenter_.updateItem(item);
+ // status.processed does not show the process of whole of sync.
+ this.item_.progressValue = 0;
+ // status.total does not show the total of whole of sync.
+ this.item_.progressMax = 1;
+ this.progressCenter_.updateItem(this.item_);
callback();
}.bind(this));
};
@@ -148,15 +152,11 @@ DriveSyncHandler.prototype.updateItem_ = function(status) {
*/
DriveSyncHandler.prototype.removeItem_ = function(status) {
this.queue_.run(function(callback) {
- var item = this.items_[status.fileUrl];
- if (!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;
+ this.dispatchEvent(new Event(DriveSyncHandler.COMPLETED_EVENT));
callback();
}.bind(this));
};
@@ -177,24 +177,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.ERROR;
+ 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));
};

Powered by Google App Engine
This is Rietveld 408576698