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

Unified Diff: chrome/browser/resources/file_manager/background/js/drive_sync_handler.js

Issue 136783003: Files.app; Serializes event handler calls for particular URLs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/file_manager/background/js/drive_sync_handler.js
diff --git a/chrome/browser/resources/file_manager/background/js/drive_sync_handler.js b/chrome/browser/resources/file_manager/background/js/drive_sync_handler.js
index 2ba9672fe47fbc2617defb2261ebed1a5b0fd885..c9c4f3a47266aae20dc7ec12aa9b996edc642252 100644
--- a/chrome/browser/resources/file_manager/background/js/drive_sync_handler.js
+++ b/chrome/browser/resources/file_manager/background/js/drive_sync_handler.js
@@ -26,13 +26,19 @@ function DriveSyncHandler(progressCenter) {
this.idCounter_ = 0;
/**
- * Progressing file names.
- * @type {Object.<string, ProgressCenterItem>} Map a file URL and a progress
- * center item.
+ * Map of file urls and progress center items.
+ * @type {Object.<string, ProgressCenterItem>}
* @private
*/
this.items_ = {};
+ /**
+ * Async queue.
+ * @type {AsyncUtil.Queue}
+ * @private
+ */
+ this.queue_ = new AsyncUtil.Queue();
+
// Register events.
chrome.fileBrowserPrivate.onFileTransfersUpdated.addListener(
this.onFileTransfersUpdated_.bind(this));
@@ -102,25 +108,35 @@ DriveSyncHandler.prototype.onFileTransfersUpdated_ = function(statusList) {
* @private
*/
DriveSyncHandler.prototype.updateItem_ = function(status) {
- webkitResolveLocalFileSystemURL(status.fileUrl, function(entry) {
- var item;
+ this.queue_.run(function(callback) {
if (!this.items_[status.fileUrl]) {
- 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;
- } else {
- item = this.items_[status.fileUrl];
+ 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;
+ callback();
+ }.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.progressMax = status.total || 1;
this.progressCenter_.updateItem(item);
- }.bind(this), function() {
- console.error('Cannot resolve the URL: ' + status.fileUrl);
- });
+ callback();
+ }.bind(this));
};
/**
@@ -129,13 +145,18 @@ DriveSyncHandler.prototype.updateItem_ = function(status) {
* @private
*/
DriveSyncHandler.prototype.removeItem_ = function(status) {
- var item = this.items_[status.fileUrl];
- delete this.items_[status.fileUrl];
- if (item) {
+ this.queue_.run(function(callback) {
+ var item = this.items_[status.fileUrl];
+ if (!item) {
+ callback();
+ return;
+ }
item.state = status.transferState === 'completed' ?
ProgressItemState.COMPLETED : ProgressItemState.CANCELED;
this.progressCenter_.updateItem(item);
- }
+ delete this.items_[status.fileUrl];
+ callback();
+ }.bind(this));
};
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698