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

Side by Side Diff: chrome/browser/resources/file_manager/background/js/file_operation_manager.js

Issue 137743002: Fix moving by dragging and CTRL-X CTRL-V. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rewritten again. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 }); 291 });
292 }; 292 };
293 293
294 /** 294 /**
295 * @constructor 295 * @constructor
296 */ 296 */
297 function FileOperationManager() { 297 function FileOperationManager() {
298 this.copyTasks_ = []; 298 this.copyTasks_ = [];
299 this.deleteTasks_ = []; 299 this.deleteTasks_ = [];
300 this.taskIdCounter_ = 0; 300 this.taskIdCounter_ = 0;
301
302 this.eventRouter_ = new FileOperationManager.EventRouter(); 301 this.eventRouter_ = new FileOperationManager.EventRouter();
303 302
304 Object.seal(this); 303 Object.seal(this);
305 } 304 }
306 305
307 /** 306 /**
308 * Get FileOperationManager instance. In case is hasn't been initialized, a new 307 * Get FileOperationManager instance. In case is hasn't been initialized, a new
309 * instance is created. 308 * instance is created.
310 * 309 *
311 * @return {FileOperationManager} A FileOperationManager instance. 310 * @return {FileOperationManager} A FileOperationManager instance.
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 // Do nothing, if we have no entries to be pasted. 1157 // Do nothing, if we have no entries to be pasted.
1159 if (filteredEntries.length === 0) 1158 if (filteredEntries.length === 0)
1160 return; 1159 return;
1161 1160
1162 this.queueCopy_(targetEntry, filteredEntries, isMove); 1161 this.queueCopy_(targetEntry, filteredEntries, isMove);
1163 }.bind(this)); 1162 }.bind(this));
1164 }; 1163 };
1165 1164
1166 /** 1165 /**
1167 * Checks if the move operation is available between the given two locations. 1166 * Checks if the move operation is available between the given two locations.
1167 * This method uses the volume manager, which is lazily created, therefore the
1168 * result is returned asynchronously.
1168 * 1169 *
1169 * @param {DirectoryEntry} sourceEntry An entry from the source. 1170 * @param {DirectoryEntry} sourceEntry An entry from the source.
1170 * @param {DirectoryEntry} targetDirEntry Directory entry for the target. 1171 * @param {DirectoryEntry} targetDirEntry Directory entry for the target.
1171 * @return {boolean} Whether we can move from the source to the target. 1172 * @param {function(boolean)} callback Callback with result whether the entries
1173 * can be directly moved.
1174 * @private
1172 */ 1175 */
1173 FileOperationManager.prototype.isMovable = function( 1176 FileOperationManager.prototype.isMovable_ = function(
1174 sourceEntry, targetDirEntry) { 1177 sourceEntry, targetDirEntry, callback) {
1175 var sourceLocationInfo = this.volumeManager_.getLocationInfo(sourceEntry); 1178 VolumeManager.getInstance(function(volumeManager) {
1176 var targetDirLocationInfo = this.volumeManager_.getLocationInfo( 1179 var sourceLocationInfo = volumeManager.getLocationInfo(sourceEntry);
1177 targetDirEntry); 1180 var targetDirLocationInfo = volumeManager.getLocationInfo(targetDirEntry);
1178 1181 callback(
1179 return sourceLocationInfo && targetDirLocationInfo && 1182 sourceLocationInfo && targetDirLocationInfo &&
1180 sourceLocationInfo.volumeInfo === targetDirLocationInfo.volumeInfo; 1183 sourceLocationInfo.volumeInfo === targetDirLocationInfo.volumeInfo);
1184 });
1181 }; 1185 };
1182 1186
1183 /** 1187 /**
1184 * Initiate a file copy. 1188 * Initiate a file copy. When copying files, null can be specified as source
1189 * directory.
1185 * 1190 *
1186 * @param {DirectoryEntry} targetDirEntry Target directory. 1191 * @param {DirectoryEntry} targetDirEntry Target directory.
1187 * @param {Array.<Entry>} entries Entries to copy. 1192 * @param {Array.<Entry>} entries Entries to copy.
1188 * @param {boolean} isMove In case of move. 1193 * @param {boolean} isMove In case of move.
1189 * @return {FileOperationManager.Task} Copy task.
1190 * @private 1194 * @private
1191 */ 1195 */
1192 FileOperationManager.prototype.queueCopy_ = function( 1196 FileOperationManager.prototype.queueCopy_ = function(
1193 targetDirEntry, entries, isMove) { 1197 targetDirEntry, entries, isMove) {
1194 // When copying files, null can be specified as source directory. 1198 var createTask = function(task) {
1199 task.taskId = this.generateTaskId_();
1200 task.initialize(function() {
1201 this.copyTasks_.push(task);
1202 this.eventRouter_.sendProgressEvent(
hirono 2014/01/15 02:29:41 Can we send the event before the async call? It sh
mtomasz 2014/01/15 08:01:03 It seems that it is not safe. If we emit an event
1203 'BEGIN', task.getStatus(), task.taskId);
1204 if (this.copyTasks_.length == 1)
hirono 2014/01/15 02:29:41 nit: ===
1205 this.serviceAllTasks_();
1206 }.bind(this));
1207 }.bind(this);
1208
1195 var task; 1209 var task;
1196 if (isMove) { 1210 if (isMove) {
1197 if (this.isMovable(entries[0], targetDirEntry)) { 1211 // When moving between different volumes, moving is implemented as a copy
1198 task = new FileOperationManager.MoveTask(entries, targetDirEntry); 1212 // and delete. This is because moving between volumes is slow, and moveTo()
1199 } else { 1213 // is not cancellable nor provides progress feedback.
1200 task = new FileOperationManager.CopyTask(entries, targetDirEntry); 1214 this.isMovable_(entries[0], targetDirEntry, function(isMovable) {
1201 task.deleteAfterCopy = true; 1215 if (isMovable) {
1202 } 1216 createTask(new FileOperationManager.MoveTask(entries, targetDirEntry));
1217 } else {
1218 var task = new FileOperationManager.CopyTask(entries, targetDirEntry);
1219 task.deleteAfterCopy = true;
1220 createTask(task);
1221 }
1222 });
1203 } else { 1223 } else {
1204 task = new FileOperationManager.CopyTask(entries, targetDirEntry); 1224 createTask(new FileOperationManager.CopyTask(entries, targetDirEntry));
1205 } 1225 }
1206
1207 task.taskId = this.generateTaskId_();
1208 task.initialize(function() {
1209 this.copyTasks_.push(task);
1210 this.eventRouter_.sendProgressEvent('BEGIN', task.getStatus(), task.taskId);
1211 if (this.copyTasks_.length == 1)
1212 this.serviceAllTasks_();
1213 }.bind(this));
1214
1215 return task;
1216 }; 1226 };
1217 1227
1218 /** 1228 /**
1219 * Service all pending tasks, as well as any that might appear during the 1229 * Service all pending tasks, as well as any that might appear during the
1220 * copy. 1230 * copy.
1221 * 1231 *
1222 * @private 1232 * @private
1223 */ 1233 */
1224 FileOperationManager.prototype.serviceAllTasks_ = function() { 1234 FileOperationManager.prototype.serviceAllTasks_ = function() {
1225 if (!this.copyTasks_.length) { 1235 if (!this.copyTasks_.length) {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 1417
1408 /** 1418 /**
1409 * Generates new task ID. 1419 * Generates new task ID.
1410 * 1420 *
1411 * @return {string} New task ID. 1421 * @return {string} New task ID.
1412 * @private 1422 * @private
1413 */ 1423 */
1414 FileOperationManager.prototype.generateTaskId_ = function() { 1424 FileOperationManager.prototype.generateTaskId_ = function() {
1415 return 'file-operation-' + this.taskIdCounter_++; 1425 return 'file-operation-' + this.taskIdCounter_++;
1416 }; 1426 };
OLDNEW
« 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