Commit bc9ca87d authored by fukino's avatar fukino Committed by Commit bot

Correct cache-size calculation of MetadataCache.

- Make sure that the DirectoryContent.dispose() is called when necessary.
- Defer dispose() temporarily when we need to replace directory contents.

BUG=408893
TEST=watched the cache size manually, and ran browser_tests

Review URL: https://codereview.chromium.org/520553002

Cr-Commit-Position: refs/heads/master@{#292593}
parent 3ed758c9
......@@ -566,6 +566,9 @@ DirectoryContents.prototype.clone = function() {
*/
DirectoryContents.prototype.dispose = function() {
this.context_.metadataCache.resizeBy(-this.lastSpaceInMetadataCache_);
// Though the lastSpaceInMetadataCache_ is not supposed to be referred after
// dispose(), keep it synced with requested cache size just in case.
this.lastSpaceInMetadataCache_ = 0;
};
/**
......
......@@ -385,6 +385,7 @@ DirectoryModel.prototype.clearAndScan_ = function(newDirContents,
callback) {
if (this.currentDirContents_.isScanning())
this.currentDirContents_.cancelScan();
this.currentDirContents_.dispose();
this.currentDirContents_ = newDirContents;
this.clearRescanTimeout_();
......@@ -597,10 +598,13 @@ DirectoryModel.prototype.scan_ = function(
};
/**
* @param {DirectoryContents} dirContents DirectoryContents instance.
* @param {DirectoryContents} dirContents DirectoryContents instance. This must
* be a different instance from this.currentDirContents_.
* @private
*/
DirectoryModel.prototype.replaceDirectoryContents_ = function(dirContents) {
console.assert(this.currentDirContents_ !== dirContents,
'Give directory contents instance must be different from current one.');
cr.dispatchSimpleEvent(this, 'begin-update-files');
this.updateSelectionAndPublishEvent_(this.fileListSelection_, function() {
var selectedEntries = this.getSelectedEntries_();
......@@ -610,9 +614,10 @@ DirectoryModel.prototype.replaceDirectoryContents_ = function(dirContents) {
var leadIndex = this.fileListSelection_.leadIndex;
var leadEntry = this.getLeadEntry_();
this.currentDirContents_.dispose();
var previousDirContents = this.currentDirContents_;
this.currentDirContents_ = dirContents;
dirContents.replaceContextFileList();
this.currentDirContents_.replaceContextFileList();
previousDirContents.dispose();
this.setSelectedEntries_(selectedEntries);
this.fileListSelection_.leadIndex = leadIndex;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment