Commit b60ce45e authored by dgozman@chromium.org's avatar dgozman@chromium.org

[filemanager] Content metadata moved to the cache.

Metadata usage in gallery is not touched yet.
This change includes metadata eviction.
Also localized one metadata string value.

BUG=129347
TEST=Nothing changed for user.
Review URL: https://chromiumcodereview.appspot.com/10384155

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138465 0039d316-1c4b-4281-b951-d872f2087c98
parent 6fcee33d
...@@ -11023,6 +11023,9 @@ Some features may be unavailable. Please check that the profile exists and you ...@@ -11023,6 +11023,9 @@ Some features may be unavailable. Please check that the profile exists and you
<message name="IDS_FILE_BROWSER_AUDIO_PLAYER_TITLE" desc="Title of the Audio Player window."> <message name="IDS_FILE_BROWSER_AUDIO_PLAYER_TITLE" desc="Title of the Audio Player window.">
Audio Player Audio Player
</message> </message>
<message name="IDS_FILE_BROWSER_AUDIO_PLAYER_DEFAULT_ARTIST" desc="In the Audio Player window, default artist name used when artist name is unknown.">
Unknown Artist
</message>
<message name="IDS_FILE_BROWSER_FILE_ERROR_GENERIC" desc="In the File Manager, the error message when the file operation failed."> <message name="IDS_FILE_BROWSER_FILE_ERROR_GENERIC" desc="In the File Manager, the error message when the file operation failed.">
An error occurred (code: <ph name="ERROR_CODE">$1<ex>ABORT</ex></ph>). An error occurred (code: <ph name="ERROR_CODE">$1<ex>ABORT</ex></ph>).
......
...@@ -1503,6 +1503,7 @@ bool FileDialogStringsFunction::RunImpl() { ...@@ -1503,6 +1503,7 @@ bool FileDialogStringsFunction::RunImpl() {
SET_STRING(IDS_FILE_BROWSER, GDATA_RETRY); SET_STRING(IDS_FILE_BROWSER, GDATA_RETRY);
SET_STRING(IDS_FILE_BROWSER, AUDIO_PLAYER_TITLE); SET_STRING(IDS_FILE_BROWSER, AUDIO_PLAYER_TITLE);
SET_STRING(IDS_FILE_BROWSER, AUDIO_PLAYER_DEFAULT_ARTIST);
SET_STRING(IDS_FILE_BROWSER, FILE_ERROR_GENERIC); SET_STRING(IDS_FILE_BROWSER, FILE_ERROR_GENERIC);
SET_STRING(IDS_FILE_BROWSER, FILE_ERROR_NOT_FOUND); SET_STRING(IDS_FILE_BROWSER, FILE_ERROR_NOT_FOUND);
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
<script src="js/image_editor/image_encoder.js"></script> <script src="js/image_editor/image_encoder.js"></script>
<script src="js/image_editor/exif_encoder.js"></script> <script src="js/image_editor/exif_encoder.js"></script>
<script src="js/media/media_controls.js"></script> <script src="js/media/media_controls.js"></script>
<script src="js/metadata/metadata_provider.js"></script>
</if> </if>
</head> </head>
<body> <body>
......
...@@ -239,14 +239,12 @@ FileType.MAX_PREVIEW_FILE_SIZE = 1 << 20; // 1 Mb ...@@ -239,14 +239,12 @@ FileType.MAX_PREVIEW_FILE_SIZE = 1 << 20; // 1 Mb
* the image itself as a thumbnail. If the image is too large it hurts * the image itself as a thumbnail. If the image is too large it hurts
* the performance very much so we allow it only for moderately sized files. * the performance very much so we allow it only for moderately sized files.
* *
* @param {Object} metadata From MetadataProvider. * @param {number} width Image width.
* @param {number} opt_size The file size to be used if the metadata does not * @param {number} height Image height.
* contain fileSize. * @param {number} fileSize The file size.
* @return {boolean} Whether it is OK to use the image url for a preview. * @return {boolean} Whether it is OK to use the image url for a preview.
*/ */
FileType.canUseImageUrlForPreview = function(metadata, opt_size) { FileType.canUseImageUrlForPreview = function(width, height, fileSize) {
var fileSize = metadata.fileSize || opt_size; return (fileSize && fileSize <= FileType.MAX_PREVIEW_FILE_SIZE) ||
return ((fileSize && fileSize <= FileType.MAX_PREVIEW_FILE_SIZE) || (width && height && width * height <= FileType.MAX_PREVIEW_PIXEL_COUNT);
(metadata.width && metadata.height &&
(metadata.width * metadata.height <= FileType.MAX_PREVIEW_PIXEL_COUNT)));
}; };
...@@ -23,7 +23,7 @@ RibbonClient.prototype.closeImage = function(item) {}; ...@@ -23,7 +23,7 @@ RibbonClient.prototype.closeImage = function(item) {};
* {function(string)} onNameChange Called every time a selected * {function(string)} onNameChange Called every time a selected
* item name changes (on rename and on selection change). * item name changes (on rename and on selection change).
* {function} onClose * {function} onClose
* {MetadataProvider} metadataProvider * {string} rootUrl
* {Array.<Object>} shareActions * {Array.<Object>} shareActions
* {string} readonlyDirName Directory name for readonly warning or null. * {string} readonlyDirName Directory name for readonly warning or null.
* {DirEntry} saveDirEntry Directory to save to. * {DirEntry} saveDirEntry Directory to save to.
...@@ -33,6 +33,7 @@ function Gallery(container, context) { ...@@ -33,6 +33,7 @@ function Gallery(container, context) {
this.container_ = container; this.container_ = container;
this.document_ = container.ownerDocument; this.document_ = container.ownerDocument;
this.context_ = context; this.context_ = context;
this.context_.metadataProvider = new MetadataProvider(this.context_.rootUrl);
var strf = context.displayStringFunction; var strf = context.displayStringFunction;
this.displayStringFunction_ = function(id, formatArgs) { this.displayStringFunction_ = function(id, formatArgs) {
...@@ -1307,7 +1308,7 @@ Ribbon.Item.prototype.setThumbnail = function(metadata) { ...@@ -1307,7 +1308,7 @@ Ribbon.Item.prototype.setThumbnail = function(metadata) {
url = metadata.thumbnailURL; url = metadata.thumbnailURL;
transform = metadata.thumbnailTransform; transform = metadata.thumbnailTransform;
} else if (mediaType == 'image' && } else if (mediaType == 'image' &&
FileType.canUseImageUrlForPreview(metadata)) { FileType.canUseImageUrlForPreview(metadata.width, metadata.height, 0)) {
url = this.url_; url = this.url_;
transform = metadata.imageTransform; transform = metadata.imageTransform;
} else { } else {
......
...@@ -21,3 +21,4 @@ ...@@ -21,3 +21,4 @@
//<include src="image_encoder.js"/> //<include src="image_encoder.js"/>
//<include src="exif_encoder.js"/> //<include src="exif_encoder.js"/>
//<include src="../media/media_controls.js"/> //<include src="../media/media_controls.js"/>
//<include src="../metadata/metadata_provider.js"/>
...@@ -57,7 +57,6 @@ ...@@ -57,7 +57,6 @@
//<include src="file_manager_pyauto.js"/> //<include src="file_manager_pyauto.js"/>
//<include src="file_type.js"/> //<include src="file_type.js"/>
//<include src="file_transfer_controller.js"/> //<include src="file_transfer_controller.js"/>
//<include src="metadata/metadata_provider.js"/>
//<include src="metadata/metadata_cache.js"/> //<include src="metadata/metadata_cache.js"/>
// // For accurate load performance tracking place main.js should be // // For accurate load performance tracking place main.js should be
// // the last include to include. // // the last include to include.
......
...@@ -18,7 +18,7 @@ document.addEventListener('DOMContentLoaded', function() { ...@@ -18,7 +18,7 @@ document.addEventListener('DOMContentLoaded', function() {
*/ */
function AudioPlayer(container, filesystemRootURL) { function AudioPlayer(container, filesystemRootURL) {
this.container_ = container; this.container_ = container;
this.metadataProvider_ = new MetadataProvider(filesystemRootURL); this.metadataCache_ = MetadataCache.createFull();
this.currentTrack_ = -1; this.currentTrack_ = -1;
this.playlistGeneration_ = 0; this.playlistGeneration_ = 0;
...@@ -52,6 +52,8 @@ function AudioPlayer(container, filesystemRootURL) { ...@@ -52,6 +52,8 @@ function AudioPlayer(container, filesystemRootURL) {
chrome.fileBrowserPrivate.getStrings(function(strings) { chrome.fileBrowserPrivate.getStrings(function(strings) {
container.ownerDocument.title = strings['AUDIO_PLAYER_TITLE']; container.ownerDocument.title = strings['AUDIO_PLAYER_TITLE'];
this.errorString_ = strings['AUDIO_ERROR']; this.errorString_ = strings['AUDIO_ERROR'];
AudioPlayer.TrackInfo.DEFAULT_ARTIST =
strings['AUDIO_PLAYER_DEFAULT_ARTIST'];
}.bind(this)); }.bind(this));
} }
...@@ -140,15 +142,16 @@ AudioPlayer.prototype.select_ = function(newTrack) { ...@@ -140,15 +142,16 @@ AudioPlayer.prototype.select_ = function(newTrack) {
this.fetchMetadata_(url, function(metadata) { this.fetchMetadata_(url, function(metadata) {
var media = this.audioControls_.getMedia(); var media = this.audioControls_.getMedia();
// Do not try no stream when offline. // Do not try no stream when offline.
media.src = (navigator.onLine && metadata.streamingURL) || url; media.src =
(navigator.onLine && metadata.streaming && metadata.streaming.url) ||
url;
media.load(); media.load();
this.audioControls_.play(); this.audioControls_.play();
}.bind(this)); }.bind(this));
}; };
AudioPlayer.prototype.fetchMetadata_ = function(url, callback) { AudioPlayer.prototype.fetchMetadata_ = function(url, callback) {
this.metadataProvider_.fetch( this.metadataCache_.get(url, 'thumbnail|media|streaming',
url,
function(generation, metadata) { function(generation, metadata) {
// Do nothing if another load happened since the metadata request. // Do nothing if another load happened since the metadata request.
if (this.playlistGeneration_ == generation) if (this.playlistGeneration_ == generation)
...@@ -220,7 +223,7 @@ AudioPlayer.prototype.onError_ = function() { ...@@ -220,7 +223,7 @@ AudioPlayer.prototype.onError_ = function() {
this.urls_[track], this.urls_[track],
function(metadata) { function(metadata) {
metadata.error = true; metadata.error = true;
metadata.artist = this.errorString_; metadata.media = { artist: this.errorString_ };
this.displayMetadata_(track, metadata); this.displayMetadata_(track, metadata);
this.scheduleAutoAdvance_(); this.scheduleAutoAdvance_();
}.bind(this)); }.bind(this));
...@@ -319,12 +322,14 @@ AudioPlayer.TrackInfo.prototype.getDefaultTitle = function() { ...@@ -319,12 +322,14 @@ AudioPlayer.TrackInfo.prototype.getDefaultTitle = function() {
return title; return title;
}; };
AudioPlayer.TrackInfo.DEFAULT_ARTIST = 'Unknown Artist';
AudioPlayer.TrackInfo.prototype.getDefaultArtist = function() { AudioPlayer.TrackInfo.prototype.getDefaultArtist = function() {
return 'Unknown Artist'; // TODO(kaznacheev): i18n return AudioPlayer.TrackInfo.DEFAULT_ARTIST;
}; };
/** /**
* @param {Object} metadata The metadata object * @param {Object} metadata The metadata object.
* @param {HTMLElement} container The container for the tracks. * @param {HTMLElement} container The container for the tracks.
*/ */
AudioPlayer.TrackInfo.prototype.setMetadata = function(metadata, container) { AudioPlayer.TrackInfo.prototype.setMetadata = function(metadata, container) {
...@@ -332,14 +337,14 @@ AudioPlayer.TrackInfo.prototype.setMetadata = function(metadata, container) { ...@@ -332,14 +337,14 @@ AudioPlayer.TrackInfo.prototype.setMetadata = function(metadata, container) {
this.art_.classList.add('blank'); this.art_.classList.add('blank');
this.art_.classList.add('error'); this.art_.classList.add('error');
container.classList.remove('noart'); container.classList.remove('noart');
} else if (metadata.thumbnailURL) { } else if (metadata.thumbnail && metadata.thumbnail.url) {
this.img_.onload = function() { this.img_.onload = function() {
// Only display the image if the thumbnail loaded successfully. // Only display the image if the thumbnail loaded successfully.
this.art_.classList.remove('blank'); this.art_.classList.remove('blank');
container.classList.remove('noart'); container.classList.remove('noart');
}.bind(this); }.bind(this);
this.img_.src = metadata.thumbnailURL; this.img_.src = metadata.thumbnail.url;
} }
this.title_.textContent = metadata.title || this.getDefaultTitle(); this.title_.textContent = metadata.media.title || this.getDefaultTitle();
this.artist_.textContent = metadata.artist || this.getDefaultArtist(); this.artist_.textContent = metadata.media.artist || this.getDefaultArtist();
}; };
...@@ -10,4 +10,4 @@ ...@@ -10,4 +10,4 @@
//<include src="audio_player.js"/> //<include src="audio_player.js"/>
//<include src="media_controls.js"/> //<include src="media_controls.js"/>
//<include src="../metadata/metadata_provider.js"/> //<include src="../metadata/metadata_cache.js"/>
...@@ -179,14 +179,6 @@ LocalMetadataFetcher.prototype.onMessage_ = function(event) { ...@@ -179,14 +179,6 @@ LocalMetadataFetcher.prototype.onMessage_ = function(event) {
*/ */
LocalMetadataFetcher.prototype.onInitialized_ = function(regexp) { LocalMetadataFetcher.prototype.onInitialized_ = function(regexp) {
this.urlFilter = regexp; this.urlFilter = regexp;
// Tests can monitor for this state with
// ExtensionTestMessageListener listener("worker-initialized");
// ASSERT_TRUE(listener.WaitUntilSatisfied());
// Automated tests need to wait for this, otherwise we crash in
// browser_test cleanup because the worker process still has
// URL requests in-flight.
chrome.test.sendMessage('worker-initialized');
this.initialized_ = true; this.initialized_ = true;
}; };
......
...@@ -75,7 +75,6 @@ ...@@ -75,7 +75,6 @@
<script src="js/file_manager_pyauto.js"></script> <script src="js/file_manager_pyauto.js"></script>
<script src="js/file_transfer_controller.js"></script> <script src="js/file_transfer_controller.js"></script>
<script src="js/file_type.js"></script> <script src="js/file_type.js"></script>
<script src="js/metadata/metadata_provider.js"></script>
<script src="js/metadata/metadata_cache.js"></script> <script src="js/metadata/metadata_cache.js"></script>
<!-- For accurate load performance tracking main.js should be <!-- For accurate load performance tracking main.js should be
the last script to include. --> the last script to include. -->
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
Keep the list in sync with mediaplayer_scripts.js. --> Keep the list in sync with mediaplayer_scripts.js. -->
<script src="js/media/audio_player.js"></script> <script src="js/media/audio_player.js"></script>
<script src="js/media/media_controls.js"></script> <script src="js/media/media_controls.js"></script>
<script src="js/metadata/metadata_provider.js"></script> <script src="js/metadata/metadata_cache.js"></script>
</if> </if>
</head> </head>
<body> <body>
......
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