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

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

Issue 8774008: Preventing files from being resorted after load. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reverting debugging code. Created 9 years 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // Setting the src of an img to an empty string can crash the browser, so we 5 // Setting the src of an img to an empty string can crash the browser, so we
6 // use an empty 1x1 gif instead. 6 // use an empty 1x1 gif instead.
7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' 7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,'
8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; 8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D';
9 9
10 var g_slideshow_data = null; 10 var g_slideshow_data = null;
(...skipping 1466 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 this.dialogDom_.querySelector('.dialog-title').textContent = dialogTitle; 1477 this.dialogDom_.querySelector('.dialog-title').textContent = dialogTitle;
1478 }; 1478 };
1479 1479
1480 /** 1480 /**
1481 * Cache necessary data before a sort happens. 1481 * Cache necessary data before a sort happens.
1482 * 1482 *
1483 * This is called by the table code before a sort happens, so that we can 1483 * This is called by the table code before a sort happens, so that we can
1484 * go fetch data for the sort field that we may not have yet. 1484 * go fetch data for the sort field that we may not have yet.
1485 */ 1485 */
1486 FileManager.prototype.prepareSort_ = function(field, callback) { 1486 FileManager.prototype.prepareSort_ = function(field, callback) {
1487 this.prepareSortEntries_(this.dataModel_.slice(), field, callback);
1488 };
1489
1490 FileManager.prototype.prepareSortEntries_ = function(entries, field,
1491 callback) {
1487 var cacheFunction; 1492 var cacheFunction;
1488 1493
1489 if (field == 'name' || field == 'cachedMtime_') { 1494 if (field == 'name' || field == 'cachedMtime_') {
dgozman 2011/12/02 09:33:41 We do not have two files with the same name. Let's
SeRya 2011/12/02 12:32:22 I'm not sure it need to be fixed. At least not in
1490 // Mtime is the tie-breaker for a name sort, so we need to resolve 1495 // Mtime is the tie-breaker for a name sort, so we need to resolve
1491 // it for both mtime and name sorts. 1496 // it for both mtime and name sorts.
1492 cacheFunction = cacheEntryDate; 1497 cacheFunction = cacheEntryDate;
1493 } else if (field == 'cachedSize_') { 1498 } else if (field == 'cachedSize_') {
1494 cacheFunction = cacheEntrySize; 1499 cacheFunction = cacheEntrySize;
1495 } else if (field == 'type') { 1500 } else if (field == 'type') {
1496 cacheFunction = this.cacheEntryFileType.bind(this); 1501 cacheFunction = this.cacheEntryFileType.bind(this);
1497 } else if (field == 'cachedIconType_') { 1502 } else if (field == 'cachedIconType_') {
1498 cacheFunction = this.cacheEntryIconType.bind(this); 1503 cacheFunction = this.cacheEntryIconType.bind(this);
1499 } else { 1504 } else {
1500 setTimeout(callback, 0); 1505 setTimeout(callback, 0);
1501 return; 1506 return;
1502 } 1507 }
1503 1508
1504 function checkCount() { 1509 function checkCount() {
1505 if (uncachedCount == 0) { 1510 if (uncachedCount == 0) {
1506 // Callback via a setTimeout so the sync/async semantics don't change 1511 // Callback via a setTimeout so the sync/async semantics don't change
1507 // based on whether or not the value is cached. 1512 // based on whether or not the value is cached.
1508 setTimeout(callback, 0); 1513 setTimeout(callback, 0);
1509 } 1514 }
1510 } 1515 }
1511 1516
1512 var dataModel = this.dataModel_; 1517 var uncachedCount = entries.length;
1513 var uncachedCount = dataModel.length;
1514 1518
1515 for (var i = uncachedCount - 1; i >= 0 ; i--) { 1519 for (var i = uncachedCount - 1; i >= 0 ; i--) {
1516 var entry = dataModel.item(i); 1520 var entry = entries[i];
1517 if (field in entry) { 1521 if (field in entry) {
1518 uncachedCount--; 1522 uncachedCount--;
1519 } else { 1523 } else {
1520 cacheFunction(entry, function() { 1524 cacheFunction(entry, function() {
1521 uncachedCount--; 1525 uncachedCount--;
1522 checkCount(); 1526 checkCount();
1523 }); 1527 });
1524 } 1528 }
1525 } 1529 }
1526 1530
(...skipping 1682 matching lines...) Expand 10 before | Expand all | Expand 10 after
3209 3213
3210 // Hide files that start with a dot ('.'). 3214 // Hide files that start with a dot ('.').
3211 // TODO(rginda): User should be able to override this. Support for other 3215 // TODO(rginda): User should be able to override this. Support for other
3212 // commonly hidden patterns might be nice too. 3216 // commonly hidden patterns might be nice too.
3213 if (self.filterFiles_) { 3217 if (self.filterFiles_) {
3214 spliceArgs = spliceArgs.filter(function(e) { 3218 spliceArgs = spliceArgs.filter(function(e) {
3215 return e.name.substr(0, 1) != '.'; 3219 return e.name.substr(0, 1) != '.';
3216 }); 3220 });
3217 } 3221 }
3218 3222
3219 spliceArgs.unshift(0, 0); // index, deleteCount 3223 self.prefetchCacheForSorting_(entries, function() {
dgozman 2011/12/02 09:33:41 entries -> spliceArgs
SeRya 2011/12/02 12:32:22 Done.
3220 self.dataModel_.splice.apply(self.dataModel_, spliceArgs); 3224 spliceArgs.unshift(0, 0); // index, deleteCount
3225 self.dataModel_.splice.apply(self.dataModel_, spliceArgs);
3221 3226
3222 // Keep reading until entries.length is 0. 3227 // Keep reading until entries.length is 0.
3223 reader.readEntries(onReadSome, onError); 3228 reader.readEntries(onReadSome, onError);
3229 });
3224 }; 3230 };
3225 3231
3226 metrics.startInterval('DirectoryScan'); 3232 metrics.startInterval('DirectoryScan');
3227 3233
3228 // If not the root directory, just read the contents. 3234 // If not the root directory, just read the contents.
3229 reader = this.currentDirEntry_.createReader(); 3235 reader = this.currentDirEntry_.createReader();
3230 reader.readEntries(onReadSome, onError); 3236 reader.readEntries(onReadSome, onError);
3231 return; 3237 return;
3232 } 3238 }
3233 3239
3234 // Otherwise, use the provided list of root subdirectories, since the 3240 // Otherwise, use the provided list of root subdirectories, since the
3235 // real local filesystem root directory (the one we use outside the 3241 // real local filesystem root directory (the one we use outside the
3236 // harness) can't be enumerated yet. 3242 // harness) can't be enumerated yet.
3237 var spliceArgs = [].slice.call(this.rootEntries_); 3243 var spliceArgs = [].slice.call(this.rootEntries_);
3238 spliceArgs.unshift(0, 0); // index, deleteCount 3244 spliceArgs.unshift(0, 0); // index, deleteCount
3239 this.dataModel_.splice.apply(this.dataModel_, spliceArgs); 3245 this.dataModel_.splice.apply(this.dataModel_, spliceArgs);
3240 3246
3241 if (opt_callback) 3247 if (opt_callback)
3242 opt_callback(); 3248 opt_callback();
3243 }; 3249 };
3244 3250
3251 FileManager.prototype.prefetchCacheForSorting_ = function(entries, callback) {
3252 var field = this.dataModel_.sortStatus.field;
3253 if (field) {
3254 this.prepareSortEntries_(entries, field, callback);
3255 } else {
3256 callback();
3257 return;
3258 }
3259 };
3260
3245 FileManager.prototype.findListItem_ = function(event) { 3261 FileManager.prototype.findListItem_ = function(event) {
3246 var node = event.srcElement; 3262 var node = event.srcElement;
3247 while (node) { 3263 while (node) {
3248 if (node.tagName == 'LI') 3264 if (node.tagName == 'LI')
3249 break; 3265 break;
3250 node = node.parentNode; 3266 node = node.parentNode;
3251 } 3267 }
3252 3268
3253 return node; 3269 return node;
3254 }; 3270 };
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
3960 }); 3976 });
3961 }, onError); 3977 }, onError);
3962 3978
3963 function onError(err) { 3979 function onError(err) {
3964 console.log('Error while checking free space: ' + err); 3980 console.log('Error while checking free space: ' + err);
3965 setTimeout(doCheck, 1000 * 60); 3981 setTimeout(doCheck, 1000 * 60);
3966 } 3982 }
3967 } 3983 }
3968 } 3984 }
3969 })(); 3985 })();
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