 Chromium Code Reviews
 Chromium Code Reviews Issue 136783003:
  Files.app; Serializes event handler calls for particular URLs.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 136783003:
  Files.app; Serializes event handler calls for particular URLs.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 'use strict'; | 5 'use strict'; | 
| 6 | 6 | 
| 7 /** | 7 /** | 
| 8 * Handler of the background page for the drive sync events. | 8 * Handler of the background page for the drive sync events. | 
| 9 * @param {ProgressCenter} progressCenter Progress center to submit the | 9 * @param {ProgressCenter} progressCenter Progress center to submit the | 
| 10 * progressing items. | 10 * progressing items. | 
| 11 * @constructor | 11 * @constructor | 
| 12 */ | 12 */ | 
| 13 function DriveSyncHandler(progressCenter) { | 13 function DriveSyncHandler(progressCenter) { | 
| 14 /** | 14 /** | 
| 15 * Progress center to submit the progressng item. | 15 * Progress center to submit the progressng item. | 
| 16 * @type {ProgressCenter} | 16 * @type {ProgressCenter} | 
| 17 * @private | 17 * @private | 
| 18 */ | 18 */ | 
| 19 this.progressCenter_ = progressCenter; | 19 this.progressCenter_ = progressCenter; | 
| 20 | 20 | 
| 21 /** | 21 /** | 
| 22 * Counter for progress ID. | 22 * Counter for progress ID. | 
| 23 * @type {number} | 23 * @type {number} | 
| 24 * @private | 24 * @private | 
| 25 */ | 25 */ | 
| 26 this.idCounter_ = 0; | 26 this.idCounter_ = 0; | 
| 27 | 27 | 
| 28 /** | 28 /** | 
| 29 * Progressing file names. | 29 * Map of file urls and progress center items. | 
| 30 * @type {Object.<string, ProgressCenterItem>} Map a file URL and a progress | 30 * @type {Object.<string, ProgressCenterItem>} | 
| 31 * center item. | |
| 32 * @private | 31 * @private | 
| 33 */ | 32 */ | 
| 34 this.items_ = {}; | 33 this.items_ = {}; | 
| 35 | 34 | 
| 35 /** | |
| 36 * Async queue. | |
| 37 * @type {AsyncUtil.Queue} | |
| 38 * @private | |
| 39 */ | |
| 40 this.queue_ = new AsyncUtil.Queue(); | |
| 41 | |
| 36 // Register events. | 42 // Register events. | 
| 37 chrome.fileBrowserPrivate.onFileTransfersUpdated.addListener( | 43 chrome.fileBrowserPrivate.onFileTransfersUpdated.addListener( | 
| 38 this.onFileTransfersUpdated_.bind(this)); | 44 this.onFileTransfersUpdated_.bind(this)); | 
| 39 chrome.fileBrowserPrivate.onDriveSyncError.addListener( | 45 chrome.fileBrowserPrivate.onDriveSyncError.addListener( | 
| 40 this.onDriveSyncError_.bind(this)); | 46 this.onDriveSyncError_.bind(this)); | 
| 41 } | 47 } | 
| 42 | 48 | 
| 43 /** | 49 /** | 
| 44 * Completed event name. | 50 * Completed event name. | 
| 45 * @type {string} | 51 * @type {string} | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 } | 101 } | 
| 96 } | 102 } | 
| 97 }; | 103 }; | 
| 98 | 104 | 
| 99 /** | 105 /** | 
| 100 * Updates the item involved with the given status. | 106 * Updates the item involved with the given status. | 
| 101 * @param {FileTransferStatus} status Transfer status. | 107 * @param {FileTransferStatus} status Transfer status. | 
| 102 * @private | 108 * @private | 
| 103 */ | 109 */ | 
| 104 DriveSyncHandler.prototype.updateItem_ = function(status) { | 110 DriveSyncHandler.prototype.updateItem_ = function(status) { | 
| 105 webkitResolveLocalFileSystemURL(status.fileUrl, function(entry) { | 111 var entry; | 
| 112 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.
 | |
| 113 webkitResolveLocalFileSystemURL(status.fileUrl, function(inEntry) { | |
| 114 entry = inEntry; | |
| 115 callback(); | |
| 116 }, function(error) { | |
| 117 console.warn('Resolving URL ' + status.fileUrl + 'is failed: ', error); | |
| 118 callback(); | |
| 119 }); | |
| 120 }); | |
| 121 this.queue_.run(function(callback) { | |
| 122 if (!entry) { | |
| 123 callback(); | |
| 124 return; | |
| 125 } | |
| 106 var item; | 126 var item; | 
| 107 if (!this.items_[status.fileUrl]) { | 127 if (!this.items_[status.fileUrl]) { | 
| 108 item = new ProgressCenterItem(); | 128 item = new ProgressCenterItem(); | 
| 109 item.id = DriveSyncHandler.PROGRESS_ITEM_ID_PREFIX + (this.idCounter_++); | 129 item.id = | 
| 130 DriveSyncHandler.PROGRESS_ITEM_ID_PREFIX + (this.idCounter_++); | |
| 110 item.type = ProgressItemType.SYNC; | 131 item.type = ProgressItemType.SYNC; | 
| 111 item.quiet = true; | 132 item.quiet = true; | 
| 112 item.message = strf('SYNC_FILE_NAME', entry.name); | 133 item.message = strf('SYNC_FILE_NAME', entry.name); | 
| 113 item.cancelCallback = this.requestCancel_.bind(this, entry); | 134 item.cancelCallback = this.requestCancel_.bind(this, entry); | 
| 114 this.items_[status.fileUrl] = item; | 135 this.items_[status.fileUrl] = item; | 
| 115 } else { | 136 } else { | 
| 116 item = this.items_[status.fileUrl]; | 137 item = this.items_[status.fileUrl]; | 
| 117 } | 138 } | 
| 118 item.progressValue = status.processed || 0; | 139 item.progressValue = status.processed || 0; | 
| 119 item.progressMax = status.total || 1; | 140 item.progressMax = status.total || 1; | 
| 120 this.progressCenter_.updateItem(item); | 141 this.progressCenter_.updateItem(item); | 
| 121 }.bind(this), function() { | 142 callback(); | 
| 122 console.error('Cannot resolve the URL: ' + status.fileUrl); | 143 }.bind(this)); | 
| 123 }); | |
| 124 }; | 144 }; | 
| 125 | 145 | 
| 126 /** | 146 /** | 
| 127 * Removes the item involved with the given status. | 147 * Removes the item involved with the given status. | 
| 128 * @param {FileTransferStatus} status Transfer status. | 148 * @param {FileTransferStatus} status Transfer status. | 
| 129 * @private | 149 * @private | 
| 130 */ | 150 */ | 
| 131 DriveSyncHandler.prototype.removeItem_ = function(status) { | 151 DriveSyncHandler.prototype.removeItem_ = function(status) { | 
| 132 var item = this.items_[status.fileUrl]; | 152 this.queue_.run(function(callback) { | 
| 133 delete this.items_[status.fileUrl]; | 153 var item = this.items_[status.fileUrl]; | 
| 134 if (item) { | 154 if (!item) { | 
| 155 callback(); | |
| 156 return; | |
| 157 } | |
| 135 item.state = status.transferState === 'completed' ? | 158 item.state = status.transferState === 'completed' ? | 
| 136 ProgressItemState.COMPLETED : ProgressItemState.CANCELED; | 159 ProgressItemState.COMPLETED : ProgressItemState.CANCELED; | 
| 137 this.progressCenter_.updateItem(item); | 160 this.progressCenter_.updateItem(item); | 
| 138 } | 161 delete this.items_[status.fileUrl]; | 
| 162 callback(); | |
| 163 }.bind(this)); | |
| 139 }; | 164 }; | 
| 140 | 165 | 
| 141 /** | 166 /** | 
| 142 * Requests to cancel for the given files' drive sync. | 167 * Requests to cancel for the given files' drive sync. | 
| 143 * @param {Entry} entry Entry to be canceled. | 168 * @param {Entry} entry Entry to be canceled. | 
| 144 * @private | 169 * @private | 
| 145 */ | 170 */ | 
| 146 DriveSyncHandler.prototype.requestCancel_ = function(entry) { | 171 DriveSyncHandler.prototype.requestCancel_ = function(entry) { | 
| 147 chrome.fileBrowserPrivate.cancelFileTransfers([entry.toURL()], function() {}); | 172 chrome.fileBrowserPrivate.cancelFileTransfers([entry.toURL()], function() {}); | 
| 148 }; | 173 }; | 
| (...skipping 19 matching lines...) Expand all Loading... | |
| 168 case 'service_unavailable': | 193 case 'service_unavailable': | 
| 169 item.message = str('SYNC_SERVICE_UNAVAILABLE_ERROR'); | 194 item.message = str('SYNC_SERVICE_UNAVAILABLE_ERROR'); | 
| 170 break; | 195 break; | 
| 171 case 'misc': | 196 case 'misc': | 
| 172 item.message = strf('SYNC_MISC_ERROR', entry.name); | 197 item.message = strf('SYNC_MISC_ERROR', entry.name); | 
| 173 break; | 198 break; | 
| 174 } | 199 } | 
| 175 this.progressCenter_.updateItem(item); | 200 this.progressCenter_.updateItem(item); | 
| 176 }.bind(this)); | 201 }.bind(this)); | 
| 177 }; | 202 }; | 
| OLD | NEW |