| 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   this.queue_.run(function(callback) { | 
| 106     var item; |  | 
| 107     if (!this.items_[status.fileUrl]) { | 112     if (!this.items_[status.fileUrl]) { | 
| 108       item = new ProgressCenterItem(); | 113       webkitResolveLocalFileSystemURL(status.fileUrl, function(entry) { | 
| 109       item.id = DriveSyncHandler.PROGRESS_ITEM_ID_PREFIX + (this.idCounter_++); | 114         var item = new ProgressCenterItem(); | 
| 110       item.type = ProgressItemType.SYNC; | 115         item.id = | 
| 111       item.quiet = true; | 116             DriveSyncHandler.PROGRESS_ITEM_ID_PREFIX + (this.idCounter_++); | 
| 112       item.message = strf('SYNC_FILE_NAME', entry.name); | 117         item.type = ProgressItemType.SYNC; | 
| 113       item.cancelCallback = this.requestCancel_.bind(this, entry); | 118         item.quiet = true; | 
| 114       this.items_[status.fileUrl] = item; | 119         item.message = strf('SYNC_FILE_NAME', entry.name); | 
| 115     } else { | 120         item.cancelCallback = this.requestCancel_.bind(this, entry); | 
| 116       item = this.items_[status.fileUrl]; | 121         this.items_[status.fileUrl] = item; | 
|  | 122         callback(); | 
|  | 123       }.bind(this), function(error) { | 
|  | 124         console.warn('Resolving URL ' + status.fileUrl + ' is failed: ', error); | 
|  | 125         callback(); | 
|  | 126       }); | 
|  | 127     } | 
|  | 128   }.bind(this)); | 
|  | 129   this.queue_.run(function(callback) { | 
|  | 130     var item = this.items_[status.fileUrl]; | 
|  | 131     if (!item) { | 
|  | 132       callback(); | 
|  | 133       return; | 
| 117     } | 134     } | 
| 118     item.progressValue = status.processed || 0; | 135     item.progressValue = status.processed || 0; | 
| 119     item.progressMax = status.total || 1; | 136     item.progressMax = status.total || 1; | 
| 120     this.progressCenter_.updateItem(item); | 137     this.progressCenter_.updateItem(item); | 
| 121   }.bind(this), function() { | 138     callback(); | 
| 122     console.error('Cannot resolve the URL: ' + status.fileUrl); | 139   }.bind(this)); | 
| 123   }); |  | 
| 124 }; | 140 }; | 
| 125 | 141 | 
| 126 /** | 142 /** | 
| 127  * Removes the item involved with the given status. | 143  * Removes the item involved with the given status. | 
| 128  * @param {FileTransferStatus} status Transfer status. | 144  * @param {FileTransferStatus} status Transfer status. | 
| 129  * @private | 145  * @private | 
| 130  */ | 146  */ | 
| 131 DriveSyncHandler.prototype.removeItem_ = function(status) { | 147 DriveSyncHandler.prototype.removeItem_ = function(status) { | 
| 132   var item = this.items_[status.fileUrl]; | 148   this.queue_.run(function(callback) { | 
| 133   delete this.items_[status.fileUrl]; | 149     var item = this.items_[status.fileUrl]; | 
| 134   if (item) { | 150     if (!item) { | 
|  | 151       callback(); | 
|  | 152       return; | 
|  | 153     } | 
| 135     item.state = status.transferState === 'completed' ? | 154     item.state = status.transferState === 'completed' ? | 
| 136         ProgressItemState.COMPLETED : ProgressItemState.CANCELED; | 155         ProgressItemState.COMPLETED : ProgressItemState.CANCELED; | 
| 137     this.progressCenter_.updateItem(item); | 156     this.progressCenter_.updateItem(item); | 
| 138   } | 157     delete this.items_[status.fileUrl]; | 
|  | 158     callback(); | 
|  | 159   }.bind(this)); | 
| 139 }; | 160 }; | 
| 140 | 161 | 
| 141 /** | 162 /** | 
| 142  * Requests to cancel for the given files' drive sync. | 163  * Requests to cancel for the given files' drive sync. | 
| 143  * @param {Entry} entry Entry to be canceled. | 164  * @param {Entry} entry Entry to be canceled. | 
| 144  * @private | 165  * @private | 
| 145  */ | 166  */ | 
| 146 DriveSyncHandler.prototype.requestCancel_ = function(entry) { | 167 DriveSyncHandler.prototype.requestCancel_ = function(entry) { | 
| 147   chrome.fileBrowserPrivate.cancelFileTransfers([entry.toURL()], function() {}); | 168   chrome.fileBrowserPrivate.cancelFileTransfers([entry.toURL()], function() {}); | 
| 148 }; | 169 }; | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 168       case 'service_unavailable': | 189       case 'service_unavailable': | 
| 169         item.message = str('SYNC_SERVICE_UNAVAILABLE_ERROR'); | 190         item.message = str('SYNC_SERVICE_UNAVAILABLE_ERROR'); | 
| 170         break; | 191         break; | 
| 171       case 'misc': | 192       case 'misc': | 
| 172         item.message = strf('SYNC_MISC_ERROR', entry.name); | 193         item.message = strf('SYNC_MISC_ERROR', entry.name); | 
| 173         break; | 194         break; | 
| 174     } | 195     } | 
| 175     this.progressCenter_.updateItem(item); | 196     this.progressCenter_.updateItem(item); | 
| 176   }.bind(this)); | 197   }.bind(this)); | 
| 177 }; | 198 }; | 
| OLD | NEW | 
|---|