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

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..96266b5baa3827eb6f9c459a64e7ec914f86114f 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,11 +108,26 @@ DriveSyncHandler.prototype.onFileTransfersUpdated_ = function(statusList) {
* @private
*/
DriveSyncHandler.prototype.updateItem_ = function(status) {
- webkitResolveLocalFileSystemURL(status.fileUrl, function(entry) {
+ var entry;
+ this.queue_.run(function(callback) {
mtomasz 2014/01/30 05:11:13 nit: We need to resolve the entry only when creati
hirono 2014/01/30 06:36:13 Done.
+ webkitResolveLocalFileSystemURL(status.fileUrl, function(inEntry) {
+ entry = inEntry;
+ callback();
+ }, function(error) {
+ console.warn('Resolving URL ' + status.fileUrl + 'is failed: ', error);
+ callback();
+ });
+ });
+ this.queue_.run(function(callback) {
+ if (!entry) {
+ callback();
+ return;
+ }
var item;
if (!this.items_[status.fileUrl]) {
item = new ProgressCenterItem();
- item.id = DriveSyncHandler.PROGRESS_ITEM_ID_PREFIX + (this.idCounter_++);
+ item.id =
+ DriveSyncHandler.PROGRESS_ITEM_ID_PREFIX + (this.idCounter_++);
item.type = ProgressItemType.SYNC;
item.quiet = true;
item.message = strf('SYNC_FILE_NAME', entry.name);
@@ -118,9 +139,8 @@ DriveSyncHandler.prototype.updateItem_ = function(status) {
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 +149,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