Commit 14295058 authored by hirono's avatar hirono Committed by Commit bot

Files.app: Move ContentMetadataProvider from ThumbnailModel to FileSystemMetadata.

Audio player refers 'media.title' and 'media.artist' properties that are fetched
by ContentMetadataProvider. Because these properties are not related with
thumbnail, the CL moves ContentMetadataProvider to FileSystemMetadata for
preparing to use new metadata class in Audio player.

BUG=410766
TEST=FileManagerJsTest.FileSystemMetadata

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

Cr-Commit-Position: refs/heads/master@{#317015}
parent 91ffd8b5
......@@ -695,14 +695,10 @@ FileManager.prototype = /** @struct */ {
// Create the metadata cache.
assert(this.volumeManager_);
this.fileSystemMetadata_ = new FileSystemMetadata(
this.fileSystemMetadata_ = FileSystemMetadata.create(
this.metadataProviderCache_,
new FileSystemMetadataProvider(this.metadataProviderCache_),
new ExternalMetadataProvider(this.metadataProviderCache_),
this.volumeManager_);
this.thumbnailModel_ = new ThumbnailModel(
this.fileSystemMetadata_,
new ContentMetadataProvider(this.metadataProviderCache_));
this.thumbnailModel_ = new ThumbnailModel(this.fileSystemMetadata_);
// Create the root view of FileManager.
assert(this.dialogDom_);
......
......@@ -89,7 +89,6 @@
//<include src="ui/file_manager_dialog_base.js">
//<include src="metadata/metadata_cache_set.js">
//<include src="metadata/new_metadata_provider.js">
//<include src="metadata/thumbnail_model.js">
//
//<include src="app_installer.js">
//<include src="app_state_controller.js">
......@@ -115,6 +114,7 @@
//<include src="metadata/metadata_cache.js">
//<include src="metadata/metadata_cache_item.js">
//<include src="metadata/metadata_item.js">
//<include src="metadata/thumbnail_model.js">
//<include src="metadata_update_controller.js">
//<include src="naming_controller.js">
//<include src="navigation_list_model.js">
......
......@@ -6,6 +6,7 @@
* @param {!MetadataProviderCache} cache
* @param {!FileSystemMetadataProvider} fileSystemMetadataProvider
* @param {!ExternalMetadataProvider} externalMetadataProvider
* @param {!ContentMetadataProvider} contentMetadataProvider
* @param {!VolumeManagerWrapper} volumeManager
* @constructor
* @struct
......@@ -14,6 +15,7 @@ function FileSystemMetadata(
cache,
fileSystemMetadataProvider,
externalMetadataProvider,
contentMetadataProvider,
volumeManager) {
/**
* @private {!MetadataProviderCache}
......@@ -33,6 +35,12 @@ function FileSystemMetadata(
*/
this.externalMetadataProvider_ = externalMetadataProvider;
/**
* @private {!ContentMetadataProvider}
* @const
*/
this.contentMetadataProvider_ = contentMetadataProvider;
/**
* @private {!VolumeManagerWrapper}
* @const
......@@ -40,6 +48,20 @@ function FileSystemMetadata(
this.volumeManager_ = volumeManager;
}
/**
* @param {!MetadataProviderCache} cache
* @param {!VolumeManagerWrapper} volumeManager
* @return {!FileSystemMetadata}
*/
FileSystemMetadata.create = function(cache, volumeManager) {
return new FileSystemMetadata(
cache,
new FileSystemMetadataProvider(cache),
new ExternalMetadataProvider(cache),
new ContentMetadataProvider(cache),
volumeManager);
};
/**
* Obtains metadata for entries.
* @param {!Array<!Entry>} entries Entries.
......@@ -48,41 +70,57 @@ function FileSystemMetadata(
*/
FileSystemMetadata.prototype.get = function(entries, names) {
var localEntries = [];
var localEntryIndexes = [];
var externalEntries = [];
var externalEntryIndexes = [];
for (var i = 0; i < entries.length; i++) {
var volumeInfo = this.volumeManager_.getVolumeInfo(entries[i]);
if (volumeInfo &&
(volumeInfo.volumeType === VolumeManagerCommon.VolumeType.DRIVE ||
volumeInfo.volumeType === VolumeManagerCommon.VolumeType.PROVIDED)) {
externalEntries.push(entries[i]);
externalEntryIndexes.push(i);
} else {
localEntries.push(entries[i]);
localEntryIndexes.push(i);
}
}
// Correct property names that are valid for fileSystemMetadataProvider.
var fileSystemPropertyNames = names.filter(function(name) {
return FileSystemMetadataProvider.PROPERTY_NAMES.indexOf(name) !== -1;
});
var fileSystemPropertyNames = [];
var externalPropertyNames = [];
var contentPropertyNames = [];
for (var i = 0; i < names.length; i++) {
var validName = false;
if (FileSystemMetadataProvider.PROPERTY_NAMES.indexOf(names[i]) !== -1) {
fileSystemPropertyNames.push(names[i]);
validName = true;
}
if (ExternalMetadataProvider.PROPERTY_NAMES.indexOf(names[i]) !== -1) {
externalPropertyNames.push(names[i]);
validName = true;
}
if (ContentMetadataProvider.PROPERTY_NAMES.indexOf(names[i]) !== -1) {
assert(!validName);
contentPropertyNames.push(names[i]);
validName = true;
}
assert(validName);
}
return Promise.all([
this.fileSystemMetadataProvider_.get(localEntries, fileSystemPropertyNames),
this.externalMetadataProvider_.get(externalEntries, names)
this.externalMetadataProvider_.get(externalEntries, externalPropertyNames),
this.contentMetadataProvider_.get(entries, contentPropertyNames)
]).then(function(results) {
var integratedResults = [];
var localResults = results[0];
for (var i = 0; i < localResults.length; i++) {
integratedResults[localEntryIndexes[i]] = localResults[i];
}
var externalResults = results[1];
for (var i = 0; i < externalResults.length; i++) {
integratedResults[externalEntryIndexes[i]] = externalResults[i];
var integratedResults = {};
for (var i = 0; i < 3; i++) {
var entryList = [localEntries, externalEntries, entries][i];
for (var j = 0; j < entryList.length; j++) {
var url = entryList[j].toURL();
integratedResults[url] = integratedResults[url] || new MetadataItem();
for (var name in results[i][j]) {
integratedResults[url][name] = results[i][j][name];
}
}
}
return integratedResults;
return entries.map(function(entry) {
return integratedResults[entry.toURL()];
});
});
};
......
......@@ -16,22 +16,34 @@ function testFileSystemMetadataBasic(callback) {
cache,
// Mocking FileSystemMetadataProvider.
{
get: function(urls) {
assertEquals(1, urls.length);
assertEquals('filesystem://A', urls[0].toURL());
get: function(entries) {
assertEquals(1, entries.length);
assertEquals('filesystem://A', entries[0].toURL());
return Promise.resolve(
[{modificationTime: new Date(2015, 0, 1), size: 1024}]);
}
},
// Mocking ExternalMetadataProvider.
{
get: function(urls) {
assertEquals(1, urls.length);
assertEquals('filesystem://B', urls[0].toURL());
get: function(entries) {
assertEquals(1, entries.length);
assertEquals('filesystem://B', entries[0].toURL());
return Promise.resolve(
[{modificationTime: new Date(2015, 1, 2), size: 2048}]);
}
},
// Mocking ContentMetadataProvider.
{
get: function(entries) {
assertEquals(2, entries.length);
assertEquals('filesystem://A', entries[0].toURL());
assertEquals('filesystem://B', entries[1].toURL());
return Promise.resolve([
{contentThumbnailUrl: 'THUMBNAIL_URL_A'},
{contentThumbnailUrl: 'THUMBNAIL_URL_B'}
]);
}
},
// Mocking VolumeManagerWrapper.
{
getVolumeInfo: function(entry) {
......@@ -48,16 +60,20 @@ function testFileSystemMetadataBasic(callback) {
}
});
reportPromise(
model.get([entryA, entryB], ['size', 'modificationTime']).then(
model.get(
[entryA, entryB],
['size', 'modificationTime', 'contentThumbnailUrl']).then(
function(results) {
assertEquals(2, results.length);
assertEquals(
new Date(2015, 0, 1).toString(),
results[0].modificationTime.toString());
assertEquals(1024, results[0].size);
assertEquals('THUMBNAIL_URL_A', results[0].contentThumbnailUrl);
assertEquals(
new Date(2015, 1, 2).toString(),
results[1].modificationTime.toString());
assertEquals(2048, results[1].size);
assertEquals('THUMBNAIL_URL_B', results[1].contentThumbnailUrl);
}), callback);
}
......@@ -4,24 +4,15 @@
/**
* @param {!FileSystemMetadata} fileSystemMetadata
* @param {!ContentMetadataProvider} contentMetadataProvider
* @struct
* @constructor
*/
function ThumbnailModel(
fileSystemMetadata,
contentMetadataProvider) {
function ThumbnailModel(fileSystemMetadata) {
/**
* @private {!FileSystemMetadata}
* @const
*/
this.fileSystemMetadata_ = fileSystemMetadata;
/**
* @private {!ContentMetadataProvider}
* @const
*/
this.contentMetadataProvider_ = contentMetadataProvider;
}
/**
......@@ -62,7 +53,7 @@ ThumbnailModel.prototype.get = function(entries) {
contentRequestEntries.push(entries[i]);
}
if (contentRequestEntries.length) {
return this.contentMetadataProvider_.get(
return this.fileSystemMetadata_.get(
contentRequestEntries,
[
'contentThumbnailUrl',
......
......@@ -12,26 +12,30 @@ var nonImageEntry = {
toURL: function() { return 'filesystem://B'; }
};
var fileSystemMetadata;
var metadata;
var contentMetadata;
var thumbnailModel;
function setUp() {
fileSystemMetadata = {
modificationTime: new Date(2015, 0, 1),
present: true,
dirty: false,
thumbnailUrl: 'EXTERNAL_THUMBNAIL_URL',
customIconUrl: 'CUSTOM_ICON_URL'
};
contentMetadata = {
contentThumbnailUrl: 'CONTENT_THUMBNAIL_URL',
contentThumbnailTransform: 'CONTENT_THUMBNAIL_TRANSFORM',
contentImageTransform: 'CONTENT_IMAGE_TRANSFORM'
};
thumbnailModel = new ThumbnailModel(
{get: function() { return Promise.resolve([fileSystemMetadata]); }},
{get: function() { return Promise.resolve([contentMetadata]); }});
metadata = new MetadataItem();
metadata.modificationTime = new Date(2015, 0, 1);
metadata.present = true;
metadata.dirty = false;
metadata.thumbnailUrl = 'EXTERNAL_THUMBNAIL_URL';
metadata.customIconUrl = 'CUSTOM_ICON_URL';
metadata.contentThumbnailUrl = 'CONTENT_THUMBNAIL_URL';
metadata.contentThumbnailTransform = 'CONTENT_THUMBNAIL_TRANSFORM';
metadata.contentImageTransform = 'CONTENT_IMAGE_TRANSFORM';
thumbnailModel = new ThumbnailModel({
get: function(entries, names) {
var result = new MetadataItem();
for (var i = 0; i < names.length; i++) {
var name = names[i];
result[name] = metadata[name];
}
return Promise.resolve([result]);
}});
}
function testThumbnailModelGetBasic(callback) {
......@@ -50,7 +54,7 @@ function testThumbnailModelGetBasic(callback) {
}
function testThumbnailModelGetNotPresent(callback) {
fileSystemMetadata.present = false;
metadata.present = false;
reportPromise(thumbnailModel.get([imageEntry]).then(function(results) {
assertEquals(1, results.length);
assertEquals(
......
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