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

Side by Side Diff: ui/file_manager/gallery/js/gallery.js

Issue 802283005: Gallery: Update metadata in GalleryItem when saving items. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 /** 5 /**
6 * Overrided metadata worker's path. 6 * Overrided metadata worker's path.
7 * @type {string} 7 * @type {string}
8 */ 8 */
9 ContentProvider.WORKER_SCRIPT = '/js/metadata_worker.js'; 9 ContentProvider.WORKER_SCRIPT = '/js/metadata_worker.js';
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 * @param {!Gallery.Item} item Original gallery item. 64 * @param {!Gallery.Item} item Original gallery item.
65 * @param {!HTMLCanvasElement} canvas Canvas containing new image. 65 * @param {!HTMLCanvasElement} canvas Canvas containing new image.
66 * @param {boolean} overwrite Whether to overwrite the image to the item or not. 66 * @param {boolean} overwrite Whether to overwrite the image to the item or not.
67 * @return {!Promise} Promise to be fulfilled with when the operation completes. 67 * @return {!Promise} Promise to be fulfilled with when the operation completes.
68 */ 68 */
69 GalleryDataModel.prototype.saveItem = function( 69 GalleryDataModel.prototype.saveItem = function(
70 volumeManager, item, canvas, overwrite) { 70 volumeManager, item, canvas, overwrite) {
71 var oldEntry = item.getEntry(); 71 var oldEntry = item.getEntry();
72 var oldMetadata = item.getMetadata(); 72 var oldMetadata = item.getMetadata();
73 var oldLocationInfo = item.getLocationInfo(); 73 var oldLocationInfo = item.getLocationInfo();
74 var metadataEncoder = ImageEncoder.encodeMetadata(
75 item.getMetadata(), canvas, 1 /* quality */);
76 var newMetadata = ContentProvider.ConvertContentMetadata(
77 metadataEncoder.getMetadata(),
78 MetadataCache.cloneMetadata(item.getMetadata()));
79 if (newMetadata.filesystem)
80 newMetadata.filesystem.modificationTime = new Date();
81 if (newMetadata.external)
82 newMetadata.external.present = true;
83
84 return new Promise(function(fulfill, reject) { 74 return new Promise(function(fulfill, reject) {
85 item.saveToFile( 75 item.saveToFile(
86 volumeManager, 76 volumeManager,
87 this.fallbackSaveDirectory, 77 this.fallbackSaveDirectory,
88 overwrite, 78 overwrite,
89 canvas, 79 canvas,
90 metadataEncoder,
91 function(success) { 80 function(success) {
92 if (!success) { 81 if (!success) {
93 reject('Failed to save the image.'); 82 reject('Failed to save the image.');
94 return; 83 return;
95 } 84 }
96 85
97 // The item's entry is updated to the latest entry. Update metadata.
98 item.setMetadata(newMetadata);
99
100 // Current entry is updated. 86 // Current entry is updated.
101 // Dispatch an event. 87 // Dispatch an event.
102 var event = new Event('content'); 88 var event = new Event('content');
103 event.item = item; 89 event.item = item;
104 event.oldEntry = oldEntry; 90 event.oldEntry = oldEntry;
105 event.metadata = newMetadata; 91 event.metadata = item.getMetadata();
106 this.dispatchEvent(event); 92 this.dispatchEvent(event);
107 93
108 if (util.isSameEntry(oldEntry, item.getEntry())) { 94 if (!util.isSameEntry(oldEntry, item.getEntry())) {
109 // Need an update of metdataCache.
110 this.metadataCache_.set(
111 item.getEntry(),
112 Gallery.METADATA_TYPE,
113 newMetadata);
114 } else {
115 // New entry is added and the item now tracks it. 95 // New entry is added and the item now tracks it.
116 // Add another item for the old entry. 96 // Add another item for the old entry.
117 var anotherItem = new Gallery.Item( 97 var anotherItem = new Gallery.Item(
118 oldEntry, 98 oldEntry,
119 oldLocationInfo, 99 oldLocationInfo,
120 oldMetadata, 100 oldMetadata,
121 this.metadataCache_, 101 this.metadataCache_,
122 item.isOriginal()); 102 item.isOriginal());
123 // The item must be added behind the existing item so that it does 103 // The item must be added behind the existing item so that it does
124 // not change the index of the existing item. 104 // not change the index of the existing item.
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 }; 1038 };
1059 1039
1060 /** 1040 /**
1061 * Loads entries. 1041 * Loads entries.
1062 * @param {!Array.<Entry>} entries Array of entries. 1042 * @param {!Array.<Entry>} entries Array of entries.
1063 * @param {!Array.<Entry>} selectedEntries Array of selected entries. 1043 * @param {!Array.<Entry>} selectedEntries Array of selected entries.
1064 */ 1044 */
1065 window.loadEntries = function(entries, selectedEntries) { 1045 window.loadEntries = function(entries, selectedEntries) {
1066 gallery.load(entries, selectedEntries); 1046 gallery.load(entries, selectedEntries);
1067 }; 1047 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698