OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 * Utilities for FileOperationManager. | 8 * Utilities for FileOperationManager. |
9 */ | 9 */ |
10 var fileOperationUtil = {}; | 10 var fileOperationUtil = {}; |
(...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1177 }; | 1177 }; |
1178 | 1178 |
1179 /** | 1179 /** |
1180 * Kick off pasting. | 1180 * Kick off pasting. |
1181 * | 1181 * |
1182 * @param {Array.<Entry>} sourceEntries Entries of the source files. | 1182 * @param {Array.<Entry>} sourceEntries Entries of the source files. |
1183 * @param {DirectoryEntry} targetEntry The destination entry of the target | 1183 * @param {DirectoryEntry} targetEntry The destination entry of the target |
1184 * directory. | 1184 * directory. |
1185 * @param {boolean} isMove True if the operation is "move", otherwise (i.e. | 1185 * @param {boolean} isMove True if the operation is "move", otherwise (i.e. |
1186 * if the operation is "copy") false. | 1186 * if the operation is "copy") false. |
1187 * @param {string} optTaskId If the corresponding item has already created | |
1188 * at another places, we need to specify the ID of the item. If the | |
1189 * item is not created, FileOperationManager generates new ID. | |
1187 */ | 1190 */ |
1188 FileOperationManager.prototype.paste = function( | 1191 FileOperationManager.prototype.paste = function( |
1189 sourceEntries, targetEntry, isMove) { | 1192 sourceEntries, targetEntry, isMove, optTaskId) { |
hirono
2014/09/17 03:33:20
nit: The type name should be string= since it is o
iseki
2014/09/17 04:08:47
Done.
| |
1190 // Do nothing if sourceEntries is empty. | 1193 // Do nothing if sourceEntries is empty. |
1191 if (sourceEntries.length === 0) | 1194 if (sourceEntries.length === 0) |
1192 return; | 1195 return; |
1193 | 1196 |
1194 var filteredEntries = []; | 1197 var filteredEntries = []; |
1195 var resolveGroup = new AsyncUtil.Queue(); | 1198 var resolveGroup = new AsyncUtil.Queue(); |
1196 | 1199 |
1197 if (isMove) { | 1200 if (isMove) { |
1198 for (var index = 0; index < sourceEntries.length; index++) { | 1201 for (var index = 0; index < sourceEntries.length; index++) { |
1199 resolveGroup.run(function(sourceEntry, callback) { | 1202 resolveGroup.run(function(sourceEntry, callback) { |
(...skipping 13 matching lines...) Expand all Loading... | |
1213 } else { | 1216 } else { |
1214 // Always copy all of the files. | 1217 // Always copy all of the files. |
1215 filteredEntries = sourceEntries; | 1218 filteredEntries = sourceEntries; |
1216 } | 1219 } |
1217 | 1220 |
1218 resolveGroup.run(function(callback) { | 1221 resolveGroup.run(function(callback) { |
1219 // Do nothing, if we have no entries to be pasted. | 1222 // Do nothing, if we have no entries to be pasted. |
1220 if (filteredEntries.length === 0) | 1223 if (filteredEntries.length === 0) |
1221 return; | 1224 return; |
1222 | 1225 |
1223 this.queueCopy_(targetEntry, filteredEntries, isMove); | 1226 this.queueCopy_(targetEntry, filteredEntries, isMove, optTaskId); |
1224 }.bind(this)); | 1227 }.bind(this)); |
1225 }; | 1228 }; |
1226 | 1229 |
1227 /** | 1230 /** |
1228 * Initiate a file copy. When copying files, null can be specified as source | 1231 * Initiate a file copy. When copying files, null can be specified as source |
1229 * directory. | 1232 * directory. |
1230 * | 1233 * |
1231 * @param {DirectoryEntry} targetDirEntry Target directory. | 1234 * @param {DirectoryEntry} targetDirEntry Target directory. |
1232 * @param {Array.<Entry>} entries Entries to copy. | 1235 * @param {Array.<Entry>} entries Entries to copy. |
1233 * @param {boolean} isMove In case of move. | 1236 * @param {boolean} isMove In case of move. |
1237 * @param {string} optTaskId If the corresponding item has already created | |
1238 * at another places, we need to specify the ID of the item. If the | |
1239 * item is not created, FileOperationManager generates new ID. | |
1234 * @private | 1240 * @private |
1235 */ | 1241 */ |
1236 FileOperationManager.prototype.queueCopy_ = function( | 1242 FileOperationManager.prototype.queueCopy_ = function( |
1237 targetDirEntry, entries, isMove) { | 1243 targetDirEntry, entries, isMove, optTaskId) { |
1238 var task; | 1244 var task; |
1239 if (isMove) { | 1245 if (isMove) { |
1240 // When moving between different volumes, moving is implemented as a copy | 1246 // When moving between different volumes, moving is implemented as a copy |
1241 // and delete. This is because moving between volumes is slow, and moveTo() | 1247 // and delete. This is because moving between volumes is slow, and moveTo() |
1242 // is not cancellable nor provides progress feedback. | 1248 // is not cancellable nor provides progress feedback. |
1243 if (util.isSameFileSystem(entries[0].filesystem, | 1249 if (util.isSameFileSystem(entries[0].filesystem, |
1244 targetDirEntry.filesystem)) { | 1250 targetDirEntry.filesystem)) { |
1245 task = new FileOperationManager.MoveTask(entries, targetDirEntry); | 1251 task = new FileOperationManager.MoveTask(entries, targetDirEntry); |
1246 } else { | 1252 } else { |
1247 task = new FileOperationManager.CopyTask(entries, targetDirEntry, true); | 1253 task = new FileOperationManager.CopyTask(entries, targetDirEntry, true); |
1248 } | 1254 } |
1249 } else { | 1255 } else { |
1250 task = new FileOperationManager.CopyTask(entries, targetDirEntry, false); | 1256 task = new FileOperationManager.CopyTask(entries, targetDirEntry, false); |
1251 } | 1257 } |
1252 | 1258 |
1253 task.taskId = this.generateTaskId_(); | 1259 task.taskId = optTaskId || this.generateTaskId_(); |
1254 this.eventRouter_.sendProgressEvent('BEGIN', task.getStatus(), task.taskId); | 1260 this.eventRouter_.sendProgressEvent('BEGIN', task.getStatus(), task.taskId); |
1255 task.initialize(function() { | 1261 task.initialize(function() { |
1256 this.copyTasks_.push(task); | 1262 this.copyTasks_.push(task); |
1257 if (this.copyTasks_.length === 1) | 1263 if (this.copyTasks_.length === 1) |
1258 this.serviceAllTasks_(); | 1264 this.serviceAllTasks_(); |
1259 }.bind(this)); | 1265 }.bind(this)); |
1260 }; | 1266 }; |
1261 | 1267 |
1262 /** | 1268 /** |
1263 * Service all pending tasks, as well as any that might appear during the | 1269 * Service all pending tasks, as well as any that might appear during the |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1452 | 1458 |
1453 /** | 1459 /** |
1454 * Generates new task ID. | 1460 * Generates new task ID. |
1455 * | 1461 * |
1456 * @return {string} New task ID. | 1462 * @return {string} New task ID. |
1457 * @private | 1463 * @private |
1458 */ | 1464 */ |
1459 FileOperationManager.prototype.generateTaskId_ = function() { | 1465 FileOperationManager.prototype.generateTaskId_ = function() { |
1460 return 'file-operation-' + this.taskIdCounter_++; | 1466 return 'file-operation-' + this.taskIdCounter_++; |
1461 }; | 1467 }; |
OLD | NEW |