Commit c419d483 authored by hirono@chromium.org's avatar hirono@chromium.org

Files.app; Serializes event handler calls for particular URLs.

Previously DriveSyncHandler#updateItem_ is called for 'in_progress' events and
DriveSyncHandler#removeItem_ is called for 'completed' events.

We should do updateItem_ and removeItem_ in this order but sometimes removeItem_
calls before updateItem_ is done becuase updateItem_ needs asynchronous
opeartion.

This CL serializes function calls of updateItem_ and removeItem_ by using
Promise.

BUG=339046
TEST=manually

Review URL: https://codereview.chromium.org/136783003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@247946 0039d316-1c4b-4281-b951-d872f2087c98
parent 1af5cb16
...@@ -26,13 +26,19 @@ function DriveSyncHandler(progressCenter) { ...@@ -26,13 +26,19 @@ function DriveSyncHandler(progressCenter) {
this.idCounter_ = 0; this.idCounter_ = 0;
/** /**
* Progressing file names. * Map of file urls and progress center items.
* @type {Object.<string, ProgressCenterItem>} Map a file URL and a progress * @type {Object.<string, ProgressCenterItem>}
* center item.
* @private * @private
*/ */
this.items_ = {}; this.items_ = {};
/**
* Async queue.
* @type {AsyncUtil.Queue}
* @private
*/
this.queue_ = new AsyncUtil.Queue();
// Register events. // Register events.
chrome.fileBrowserPrivate.onFileTransfersUpdated.addListener( chrome.fileBrowserPrivate.onFileTransfersUpdated.addListener(
this.onFileTransfersUpdated_.bind(this)); this.onFileTransfersUpdated_.bind(this));
...@@ -102,25 +108,35 @@ DriveSyncHandler.prototype.onFileTransfersUpdated_ = function(statusList) { ...@@ -102,25 +108,35 @@ DriveSyncHandler.prototype.onFileTransfersUpdated_ = function(statusList) {
* @private * @private
*/ */
DriveSyncHandler.prototype.updateItem_ = function(status) { DriveSyncHandler.prototype.updateItem_ = function(status) {
webkitResolveLocalFileSystemURL(status.fileUrl, function(entry) { this.queue_.run(function(callback) {
var item;
if (!this.items_[status.fileUrl]) { if (!this.items_[status.fileUrl]) {
item = new ProgressCenterItem(); webkitResolveLocalFileSystemURL(status.fileUrl, function(entry) {
item.id = DriveSyncHandler.PROGRESS_ITEM_ID_PREFIX + (this.idCounter_++); var item = new ProgressCenterItem();
item.id =
DriveSyncHandler.PROGRESS_ITEM_ID_PREFIX + (this.idCounter_++);
item.type = ProgressItemType.SYNC; item.type = ProgressItemType.SYNC;
item.quiet = true; item.quiet = true;
item.message = strf('SYNC_FILE_NAME', entry.name); item.message = strf('SYNC_FILE_NAME', entry.name);
item.cancelCallback = this.requestCancel_.bind(this, entry); item.cancelCallback = this.requestCancel_.bind(this, entry);
this.items_[status.fileUrl] = item; this.items_[status.fileUrl] = item;
} else { callback();
item = this.items_[status.fileUrl]; }.bind(this), function(error) {
console.warn('Resolving URL ' + status.fileUrl + ' is failed: ', error);
callback();
});
}
}.bind(this));
this.queue_.run(function(callback) {
var item = this.items_[status.fileUrl];
if (!item) {
callback();
return;
} }
item.progressValue = status.processed || 0; item.progressValue = status.processed || 0;
item.progressMax = status.total || 1; item.progressMax = status.total || 1;
this.progressCenter_.updateItem(item); this.progressCenter_.updateItem(item);
}.bind(this), function() { callback();
console.error('Cannot resolve the URL: ' + status.fileUrl); }.bind(this));
});
}; };
/** /**
...@@ -129,13 +145,18 @@ DriveSyncHandler.prototype.updateItem_ = function(status) { ...@@ -129,13 +145,18 @@ DriveSyncHandler.prototype.updateItem_ = function(status) {
* @private * @private
*/ */
DriveSyncHandler.prototype.removeItem_ = function(status) { DriveSyncHandler.prototype.removeItem_ = function(status) {
this.queue_.run(function(callback) {
var item = this.items_[status.fileUrl]; var item = this.items_[status.fileUrl];
delete this.items_[status.fileUrl]; if (!item) {
if (item) { callback();
return;
}
item.state = status.transferState === 'completed' ? item.state = status.transferState === 'completed' ?
ProgressItemState.COMPLETED : ProgressItemState.CANCELED; ProgressItemState.COMPLETED : ProgressItemState.CANCELED;
this.progressCenter_.updateItem(item); this.progressCenter_.updateItem(item);
} delete this.items_[status.fileUrl];
callback();
}.bind(this));
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment