OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** | 5 /** |
6 * @constructor | 6 * @constructor |
7 * @param {DirectoryEntry} root Root directory entry. | 7 * @param {DirectoryEntry} root Root directory entry. |
8 */ | 8 */ |
9 function FileCopyManager(root) { | 9 function FileCopyManager(root) { |
10 this.copyTasks_ = []; | 10 this.copyTasks_ = []; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 var rv = { | 201 var rv = { |
202 pendingItems: 0, // Files + Directories | 202 pendingItems: 0, // Files + Directories |
203 pendingFiles: 0, | 203 pendingFiles: 0, |
204 pendingDirectories: 0, | 204 pendingDirectories: 0, |
205 pendingBytes: 0, | 205 pendingBytes: 0, |
206 | 206 |
207 completedItems: 0, // Files + Directories | 207 completedItems: 0, // Files + Directories |
208 completedFiles: 0, | 208 completedFiles: 0, |
209 completedDirectories: 0, | 209 completedDirectories: 0, |
210 completedBytes: 0, | 210 completedBytes: 0, |
211 | |
212 percentage: NaN, | |
213 pendingCopies: 0, | |
214 pendingMoves: 0, | |
215 filename: '' // In case pendingItems == 1 | |
211 }; | 216 }; |
212 | 217 |
218 var pendingFile = null; | |
219 | |
213 for (var i = 0; i < this.copyTasks_.length; i++) { | 220 for (var i = 0; i < this.copyTasks_.length; i++) { |
214 var task = this.copyTasks_[i]; | 221 var task = this.copyTasks_[i]; |
215 rv.pendingFiles += task.pendingFiles.length; | 222 var pendingFiles = task.pendingFiles.length; |
216 rv.pendingDirectories += task.pendingDirectories.length; | 223 var pendingDirectories = task.pendingDirectories.length; |
224 rv.pendingFiles += pendingFiles; | |
225 rv.pendingDirectories += pendingDirectories; | |
217 rv.pendingBytes += task.pendingBytes; | 226 rv.pendingBytes += task.pendingBytes; |
218 | 227 |
219 rv.completedFiles += task.completedFiles.length; | 228 rv.completedFiles += task.completedFiles.length; |
220 rv.completedDirectories += task.completedDirectories.length; | 229 rv.completedDirectories += task.completedDirectories.length; |
221 rv.completedBytes += task.completedBytes; | 230 rv.completedBytes += task.completedBytes; |
231 | |
232 if (task.move || task.deleteAfterCopy) { | |
233 rv.pendingMoves += pendingFiles + pendingDirectories; | |
234 } else { | |
235 rv.pendingCopies += pendingFiles + pendingDirectories; | |
236 } | |
237 | |
238 if (task.pendingFiles.length === 1) | |
239 pendingFile = task.pendingFiles[0]; | |
240 | |
241 if (task.pendingDirectories.length === 1) | |
242 pendingFile = task.pendingDirectories[0]; | |
243 | |
Vladislav Kaznacheev
2012/08/03 14:50:10
This code will not work properly if you have some
Oleg Eterevsky
2012/08/03 14:53:01
This code is supposed to work only in case there r
| |
222 } | 244 } |
223 rv.pendingItems = rv.pendingFiles + rv.pendingDirectories; | 245 rv.pendingItems = rv.pendingFiles + rv.pendingDirectories; |
224 rv.completedItems = rv.completedFiles + rv.completedDirectories; | 246 rv.completedItems = rv.completedFiles + rv.completedDirectories; |
225 | 247 |
226 rv.totalFiles = rv.pendingFiles + rv.completedFiles; | 248 rv.totalFiles = rv.pendingFiles + rv.completedFiles; |
227 rv.totalDirectories = rv.pendingDirectories + rv.completedDirectories; | 249 rv.totalDirectories = rv.pendingDirectories + rv.completedDirectories; |
228 rv.totalItems = rv.pendingItems + rv.completedItems; | 250 rv.totalItems = rv.pendingItems + rv.completedItems; |
229 rv.totalBytes = rv.pendingBytes + rv.completedBytes; | 251 rv.totalBytes = rv.pendingBytes + rv.completedBytes; |
230 | 252 |
253 rv.percentage = rv.completedBytes / rv.totalBytes; | |
254 if (rv.pendingItems === 1) | |
255 rv.filename = pendingFile.name; | |
256 | |
231 return rv; | 257 return rv; |
232 }; | 258 }; |
233 | 259 |
234 /** | 260 /** |
235 * Get the overall progress data of all queued copy tasks. | |
236 * @return {Object} An object containing the following parameters: | |
237 * percentage - The percentage (0-1) of finished items. | |
238 * pendingItems - The number of pending/unfinished items. | |
239 */ | |
240 FileCopyManager.prototype.getProgress = function() { | |
241 var status = this.getStatus(); | |
242 | |
243 var percentage = status.completedBytes / status.totalBytes; | |
244 | |
245 return { | |
246 percentage: percentage, | |
247 pendingItems: status.pendingItems | |
248 }; | |
249 }; | |
250 | |
251 /** | |
252 * Send an event to all the FileManager windows. | 261 * Send an event to all the FileManager windows. |
253 * @private | 262 * @private |
254 * @param {string} eventName Event name. | 263 * @param {string} eventName Event name. |
255 * @param {Object} eventArgs An object with arbitrary event parameters. | 264 * @param {Object} eventArgs An object with arbitrary event parameters. |
256 */ | 265 */ |
257 FileCopyManager.prototype.sendEvent_ = function(eventName, eventArgs) { | 266 FileCopyManager.prototype.sendEvent_ = function(eventName, eventArgs) { |
258 var windows = chrome.extension.getViews(); | 267 var windows = chrome.extension.getViews(); |
259 for (var i = 0; i < windows.length; i++) { | 268 for (var i = 0; i < windows.length; i++) { |
260 var w = windows[i]; | 269 var w = windows[i]; |
261 if (w.fileCopyManagerWrapper) | 270 if (w.fileCopyManagerWrapper) |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
927 | 936 |
928 writer.write(file); | 937 writer.write(file); |
929 } | 938 } |
930 | 939 |
931 targetEntry.createWriter(onWriterCreated, errorCallback); | 940 targetEntry.createWriter(onWriterCreated, errorCallback); |
932 } | 941 } |
933 | 942 |
934 sourceEntry.file(onSourceFileFound, errorCallback); | 943 sourceEntry.file(onSourceFileFound, errorCallback); |
935 }; | 944 }; |
936 | 945 |
OLD | NEW |