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

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

Issue 976713004: Add thumbnailMetadataItem to GalleryItem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 9 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 * Data model for gallery. 6 * Data model for gallery.
7 * 7 *
8 * @param {!MetadataCache} metadataCache Metadata cache.
9 * @param {!MetadataModel} metadataModel 8 * @param {!MetadataModel} metadataModel
10 * @param {!EntryListWatcher=} opt_watcher Entry list watcher. 9 * @param {!EntryListWatcher=} opt_watcher Entry list watcher.
11 * @constructor 10 * @constructor
12 * @extends {cr.ui.ArrayDataModel} 11 * @extends {cr.ui.ArrayDataModel}
13 */ 12 */
14 function GalleryDataModel(metadataCache, metadataModel, opt_watcher) { 13 function GalleryDataModel(metadataModel, opt_watcher) {
15 cr.ui.ArrayDataModel.call(this, []); 14 cr.ui.ArrayDataModel.call(this, []);
16 15
17 /** 16 /**
18 * Metadata cache.
19 * @private {!MetadataCache}
20 * @const
21 */
22 this.metadataCache_ = metadataCache;
23
24 /**
25 * File system metadata. 17 * File system metadata.
26 * @private {!MetadataModel} 18 * @private {!MetadataModel}
27 * @const 19 * @const
28 */ 20 */
29 this.metadataModel_ = metadataModel; 21 this.metadataModel_ = metadataModel;
30 22
31 /** 23 /**
32 * Directory where the image is saved if the image is located in a read-only 24 * Directory where the image is saved if the image is located in a read-only
33 * volume. 25 * volume.
34 * @public {DirectoryEntry} 26 * @public {DirectoryEntry}
(...skipping 30 matching lines...) Expand all
65 * 57 *
66 * @param {!VolumeManager} volumeManager Volume manager instance. 58 * @param {!VolumeManager} volumeManager Volume manager instance.
67 * @param {!Gallery.Item} item Original gallery item. 59 * @param {!Gallery.Item} item Original gallery item.
68 * @param {!HTMLCanvasElement} canvas Canvas containing new image. 60 * @param {!HTMLCanvasElement} canvas Canvas containing new image.
69 * @param {boolean} overwrite Whether to overwrite the image to the item or not. 61 * @param {boolean} overwrite Whether to overwrite the image to the item or not.
70 * @return {!Promise} Promise to be fulfilled with when the operation completes. 62 * @return {!Promise} Promise to be fulfilled with when the operation completes.
71 */ 63 */
72 GalleryDataModel.prototype.saveItem = function( 64 GalleryDataModel.prototype.saveItem = function(
73 volumeManager, item, canvas, overwrite) { 65 volumeManager, item, canvas, overwrite) {
74 var oldEntry = item.getEntry(); 66 var oldEntry = item.getEntry();
75 var oldMetadata = item.getMetadata();
76 var oldMetadataItem = item.getMetadataItem(); 67 var oldMetadataItem = item.getMetadataItem();
68 var oldThumbnailMetadataItem = item.getThumbnailMetadataItem();
77 var oldLocationInfo = item.getLocationInfo(); 69 var oldLocationInfo = item.getLocationInfo();
78 return new Promise(function(fulfill, reject) { 70 return new Promise(function(fulfill, reject) {
79 item.saveToFile( 71 item.saveToFile(
80 volumeManager, 72 volumeManager,
73 this.metadataModel_,
81 this.fallbackSaveDirectory, 74 this.fallbackSaveDirectory,
82 overwrite, 75 overwrite,
83 canvas, 76 canvas,
84 function(success) { 77 function(success) {
85 if (!success) { 78 if (!success) {
86 reject('Failed to save the image.'); 79 reject('Failed to save the image.');
87 return; 80 return;
88 } 81 }
89 82
90 // Current entry is updated. 83 // Current entry is updated.
91 // Dispatch an event. 84 // Dispatch an event.
92 var event = new Event('content'); 85 var event = new Event('content');
93 event.item = item; 86 event.item = item;
94 event.oldEntry = oldEntry; 87 event.oldEntry = oldEntry;
95 event.metadata = item.getMetadata(); 88 event.thumbnailChanged = true;
96 this.dispatchEvent(event); 89 this.dispatchEvent(event);
97 90
98 if (!util.isSameEntry(oldEntry, item.getEntry())) { 91 if (!util.isSameEntry(oldEntry, item.getEntry())) {
99 // New entry is added and the item now tracks it. 92 // New entry is added and the item now tracks it.
100 // Add another item for the old entry. 93 // Add another item for the old entry.
101 var anotherItem = new Gallery.Item( 94 var anotherItem = new Gallery.Item(
102 oldEntry, 95 oldEntry,
103 oldLocationInfo, 96 oldLocationInfo,
104 oldMetadata,
105 oldMetadataItem, 97 oldMetadataItem,
106 this.metadataCache_, 98 oldThumbnailMetadataItem,
107 this.metadataModel_,
108 item.isOriginal()); 99 item.isOriginal());
109 // The item must be added behind the existing item so that it does 100 // The item must be added behind the existing item so that it does
110 // not change the index of the existing item. 101 // not change the index of the existing item.
111 // TODO(hirono): Update the item index of the selection model 102 // TODO(hirono): Update the item index of the selection model
112 // correctly. 103 // correctly.
113 this.splice(this.indexOf(item) + 1, 0, anotherItem); 104 this.splice(this.indexOf(item) + 1, 0, anotherItem);
114 } 105 }
115 106
116 fulfill(); 107 fulfill();
117 }.bind(this)); 108 }.bind(this));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } else { 141 } else {
151 // Force to free the buffer of the canvas by assigning zero size. 142 // Force to free the buffer of the canvas by assigning zero size.
152 sorted[i].screenImage.width = 0; 143 sorted[i].screenImage.width = 0;
153 sorted[i].screenImage.height = 0; 144 sorted[i].screenImage.height = 0;
154 sorted[i].screenImage = null; 145 sorted[i].screenImage = null;
155 } 146 }
156 } 147 }
157 } 148 }
158 } 149 }
159 }; 150 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698