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

Side by Side Diff: ui/file_manager/file_manager/foreground/js/file_transfer_controller.js

Issue 2843683002: Reuse File objects in FileTransferController. (Closed)
Patch Set: Move file object deletion to the throttled. Created 3 years, 7 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
« 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 (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 * Global (placed in the window object) variable name to hold internal 6 * Global (placed in the window object) variable name to hold internal
7 * file dragging information. Needed to show visual feedback while dragging 7 * file dragging information. Needed to show visual feedback while dragging
8 * since DataTransfer object is in protected state. Reachable from other 8 * since DataTransfer object is in protected state. Reachable from other
9 * file manager instances. 9 * file manager instances.
10 */ 10 */
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 doc.addEventListener(command, handler); 1254 doc.addEventListener(command, handler);
1255 doc.execCommand(command); 1255 doc.execCommand(command);
1256 doc.removeEventListener(command, handler); 1256 doc.removeEventListener(command, handler);
1257 }; 1257 };
1258 1258
1259 /** 1259 /**
1260 * @private 1260 * @private
1261 */ 1261 */
1262 FileTransferController.prototype.onFileSelectionChanged_ = function() { 1262 FileTransferController.prototype.onFileSelectionChanged_ = function() {
1263 this.preloadedThumbnailImagePromise_ = null; 1263 this.preloadedThumbnailImagePromise_ = null;
1264 this.selectedAsyncData_ = {};
1265 }; 1264 };
1266 1265
1267 /** 1266 /**
1268 * @private 1267 * @private
1269 */ 1268 */
1270 FileTransferController.prototype.onFileSelectionChangedThrottled_ = function() { 1269 FileTransferController.prototype.onFileSelectionChangedThrottled_ = function() {
1270 // Remove file objects that are no longer in the selection.
1271 var asyncData = {};
1271 var entries = this.selectionHandler_.selection.entries; 1272 var entries = this.selectionHandler_.selection.entries;
1272 var asyncData = this.selectedAsyncData_; 1273 for (var i = 0; i < entries.length; i++) {
1274 var entryUrl = entries[i].toURL();
1275 if (entryUrl in this.selectedAsyncData_) {
1276 asyncData[entryUrl] = this.selectedAsyncData_[entryUrl];
1277 }
1278 }
1279 this.selectedAsyncData_ = asyncData;
1280
1273 var fileEntries = []; 1281 var fileEntries = [];
1274 for (var i = 0; i < entries.length; i++) { 1282 for (var i = 0; i < entries.length; i++) {
1275 if (entries[i].isFile) 1283 if (entries[i].isFile)
1276 fileEntries.push(entries[i]); 1284 fileEntries.push(entries[i]);
1277 asyncData[entries[i].toURL()] = {externalFileUrl: '', file: null}; 1285 if (!(entries[i].toURL() in asyncData)) {
1286 asyncData[entries[i].toURL()] = {externalFileUrl: '', file: null};
1287 }
1278 } 1288 }
1279 var containsDirectory = this.selectionHandler_.selection.directoryCount > 0; 1289 var containsDirectory = this.selectionHandler_.selection.directoryCount > 0;
1280 1290
1281 // File object must be prepeared in advance for clipboard operations 1291 // File object must be prepeared in advance for clipboard operations
1282 // (copy, paste and drag). DataTransfer object closes for write after 1292 // (copy, paste and drag). DataTransfer object closes for write after
1283 // returning control from that handlers so they may not have 1293 // returning control from that handlers so they may not have
1284 // asynchronous operations. 1294 // asynchronous operations.
1285 if (!containsDirectory) { 1295 if (!containsDirectory) {
1286 for (var i = 0; i < fileEntries.length; i++) { 1296 for (var i = 0; i < fileEntries.length; i++) {
1287 (function(fileEntry) { 1297 (function(fileEntry) {
1288 fileEntry.file(function(file) { 1298 if (!(asyncData[fileEntry.toURL()].file)) {
1289 asyncData[fileEntry.toURL()].file = file; 1299 fileEntry.file(function(file) {
1290 }); 1300 asyncData[fileEntry.toURL()].file = file;
1301 });
1302 }
1291 })(fileEntries[i]); 1303 })(fileEntries[i]);
1292 } 1304 }
1293 } 1305 }
1294 1306
1295 if (entries.length === 1) { 1307 if (entries.length === 1) {
1296 // For single selection, the dragged element is created in advance, 1308 // For single selection, the dragged element is created in advance,
1297 // otherwise an image may not be loaded at the time the 'dragstart' event 1309 // otherwise an image may not be loaded at the time the 'dragstart' event
1298 // comes. 1310 // comes.
1299 this.preloadThumbnailImage_(entries[0]); 1311 this.preloadThumbnailImage_(entries[0]);
1300 } 1312 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 listItems.push(listItem); 1398 listItems.push(listItem);
1387 } 1399 }
1388 } 1400 }
1389 1401
1390 setTimeout(function() { 1402 setTimeout(function() {
1391 for (var i = 0; i < listItems.length; i++) { 1403 for (var i = 0; i < listItems.length; i++) {
1392 listItems[i].classList.remove('blink'); 1404 listItems[i].classList.remove('blink');
1393 } 1405 }
1394 }, 100); 1406 }, 100);
1395 }; 1407 };
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