Commit d6f5dd7d authored by hirono@chromium.org's avatar hirono@chromium.org

Gallery.app: Update thumbnail when a file is edited on the photo editor.

This CL do followings to ensure to update thumbnails after the app saves images.

* Add '?nocache=xxx' to FileEntry's URL to ignore browser caches.
* Stop to use drive thumbnails for files that are on the drive but cached
  locally. These files may be edited locally and be out of sync with the local
  cache.
* Specify the current time as modificationTime of the metadata that is
  dispatched when the edited file is saved.

BUG=378648
TEST=manually

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274506 0039d316-1c4b-4281-b951-d872f2087c98
parent 2b3c83f2
...@@ -49,6 +49,13 @@ function ThumbnailLoader(entry, opt_loaderType, opt_metadata, opt_mediaType, ...@@ -49,6 +49,13 @@ function ThumbnailLoader(entry, opt_loaderType, opt_metadata, opt_mediaType,
}; };
} }
// If the file is on the drive and it is present, the file may be out of sync
// drive's thumbnail. So we don't use it.
if (opt_metadata.drive && opt_metadata.drive.present) {
opt_metadata = MetadataCache.cloneMetadata(opt_metadata);
opt_metadata.thumbnail = null;
}
if (opt_metadata.thumbnail && opt_metadata.thumbnail.url && if (opt_metadata.thumbnail && opt_metadata.thumbnail.url &&
opt_useEmbedded === ThumbnailLoader.UseEmbedded.USE_EMBEDDED) { opt_useEmbedded === ThumbnailLoader.UseEmbedded.USE_EMBEDDED) {
this.thumbnailUrl_ = opt_metadata.thumbnail.url; this.thumbnailUrl_ = opt_metadata.thumbnail.url;
......
...@@ -489,14 +489,9 @@ ImageUtil.ImageLoader.prototype.load = function( ...@@ -489,14 +489,9 @@ ImageUtil.ImageLoader.prototype.load = function(
// general error should not be specified // general error should not be specified
this.image_.onerror = onError.bind(this, 'GALLERY_IMAGE_ERROR'); this.image_.onerror = onError.bind(this, 'GALLERY_IMAGE_ERROR');
// Extract the last modification date to determine if the cached image // Load the image directly. The query parameter is workaround for
// is outdated. // crbug.com/379678, which force to update the contents of the image.
var modificationTime = opt_metadata && this.image_.src = entry.toURL() + "?nocache=" + Date.now();
opt_metadata.modificationTime &&
opt_metadata.modificationTime.getTime();
// Load the image directly.
this.image_.src = entry.toURL();
}.bind(this); }.bind(this);
// Loads the image. If already loaded, then forces a reload. // Loads the image. If already loaded, then forces a reload.
......
...@@ -403,13 +403,24 @@ ImageView.prototype.load = function(entry, metadata, effect, ...@@ -403,13 +403,24 @@ ImageView.prototype.load = function(entry, metadata, effect,
function displayThumbnail(loadType, canvas) { function displayThumbnail(loadType, canvas) {
if (canvas) { if (canvas) {
var width = null;
var height = null;
if (metadata.media) {
width = metadata.media.width;
height = metadata.media.height;
}
// If metadata.drive.present is true, the image data is loaded directly
// from local cache, whose size may be out of sync with the drive
// metadata.
if (metadata.drive && !metadata.drive.present) {
width = metadata.drive.imageWidth;
height = metadata.drive.imageHeight;
}
self.replace( self.replace(
canvas, canvas,
effect, effect,
(metadata.media && metadata.media.width) || width,
metadata.drive.imageWidth, height,
(metadata.media && metadata.media.height) ||
metadata.drive.imageHeight,
true /* preview */); true /* preview */);
if (displayCallback) displayCallback(); if (displayCallback) displayCallback();
} }
......
...@@ -344,7 +344,13 @@ Ribbon.prototype.setThumbnailImage_ = function(thumbnail, entry, metadata) { ...@@ -344,7 +344,13 @@ Ribbon.prototype.setThumbnailImage_ = function(thumbnail, entry, metadata) {
*/ */
Ribbon.prototype.onContentChange_ = function(event) { Ribbon.prototype.onContentChange_ = function(event) {
var url = event.item.getEntry().toURL(); var url = event.item.getEntry().toURL();
this.remapCache_(event.oldEntry.toURL(), url); if (event.oldEntry.toURL() !== url) {
this.remapCache_(event.oldEntry.toURL(), url);
} else {
delete this.renderCache_[url];
var index = this.dataModel_.indexOf(event.item);
this.renderThumbnail_(index);
}
var thumbnail = this.renderCache_[url]; var thumbnail = this.renderCache_[url];
if (thumbnail && event.metadata) if (thumbnail && event.metadata)
......
...@@ -940,6 +940,8 @@ SlideMode.prototype.saveCurrentImage_ = function(callback) { ...@@ -940,6 +940,8 @@ SlideMode.prototype.saveCurrentImage_ = function(callback) {
this.selectedImageMetadata_.media, canvas, 1 /* quality */); this.selectedImageMetadata_.media, canvas, 1 /* quality */);
var selectedImageMetadata = ContentProvider.ConvertContentMetadata( var selectedImageMetadata = ContentProvider.ConvertContentMetadata(
metadataEncoder.getMetadata(), this.selectedImageMetadata_); metadataEncoder.getMetadata(), this.selectedImageMetadata_);
if (selectedImageMetadata.filesystem)
selectedImageMetadata.filesystem.modificationTime = new Date();
this.selectedImageMetadata_ = selectedImageMetadata; this.selectedImageMetadata_ = selectedImageMetadata;
this.metadataCache_.set(oldEntry, this.metadataCache_.set(oldEntry,
Gallery.METADATA_TYPE, Gallery.METADATA_TYPE,
......
...@@ -273,8 +273,15 @@ AuthorizedXHR.prototype.load = function(url, onSuccess, onFailure) { ...@@ -273,8 +273,15 @@ AuthorizedXHR.prototype.load = function(url, onSuccess, onFailure) {
}.bind(this); }.bind(this);
// Do not request a token for local resources, since it is not necessary. // Do not request a token for local resources, since it is not necessary.
if (url.indexOf('filesystem:') === 0) { if (/^filesystem:/.test(url)) {
this.xhr_ = AuthorizedXHR.load_(null, url, onMaybeSuccess, onMaybeFailure); // The query parameter is workaround for
// crbug.com/379678, which force to obtain the latest contents of the image.
var noCacheUrl = url + '?nocache=' + Date.now();
this.xhr_ = AuthorizedXHR.load_(
null,
noCacheUrl,
onMaybeSuccess,
onMaybeFailure);
return; return;
} }
......
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