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

Unified Diff: ui/file_manager/file_manager/foreground/js/metadata/new_metadata_provider.js

Issue 899603002: Files.app: Handles corner cases in NewMetadataProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update test + add assertion. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/file_manager/file_manager/foreground/js/metadata/new_metadata_provider_unittest.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/file_manager/file_manager/foreground/js/metadata/new_metadata_provider.js
diff --git a/ui/file_manager/file_manager/foreground/js/metadata/new_metadata_provider.js b/ui/file_manager/file_manager/foreground/js/metadata/new_metadata_provider.js
index 49b60b905200a9b0828be5afe807789e2bc80c51..a3c767d815d29aa9dd65ccfcb62c1677b0cc6aea 100644
--- a/ui/file_manager/file_manager/foreground/js/metadata/new_metadata_provider.js
+++ b/ui/file_manager/file_manager/foreground/js/metadata/new_metadata_provider.js
@@ -5,11 +5,12 @@
/**
* TODO(hirono): Remove 'New' from the name after removing old MetadataProvider.
* @param {!MetadataProviderCache} cache
+ * @param {!Array<string>} validPropertyNames
* @constructor
* @struct
* @template T
*/
-function NewMetadataProvider(cache) {
+function NewMetadataProvider(cache, validPropertyNames) {
/**
* @private {!MetadataProviderCache}
* @const
@@ -17,6 +18,17 @@ function NewMetadataProvider(cache) {
this.cache_ = cache;
/**
+ * Set of valid property names. Key is the name of property and value is
+ * always true.
+ * @private {!Object<string, boolean>}
+ * @const
+ */
+ this.validPropertyNames_ = {};
+ for (var i = 0; i < validPropertyNames.length; i++) {
+ this.validPropertyNames_[validPropertyNames[i]] = true;
+ }
+
+ /**
* @private {!Array<!MetadataProviderCallbackRequest<T>>}
* @const
*/
@@ -25,8 +37,6 @@ function NewMetadataProvider(cache) {
/**
* Obtains the metadata for the request.
- * Note: this must return all the properties requested by the argument.
- * Otherwise Promise returned by NewMetadataProvider#get may not be fulfilled.
* @param {!Array<!MetadataRequest>} requests
* @return {!Promise<!Array<!T>>}
* @protected
@@ -40,6 +50,11 @@ NewMetadataProvider.prototype.getImpl;
* @return {!Promise<!Array<!T>>}
*/
NewMetadataProvider.prototype.get = function(entries, names) {
+ // Check if the property name is correct or not.
+ for (var i = 0; i < names.length; i++) {
+ assert(this.validPropertyNames_[names[i]]);
+ }
+
// Check if the results are cached or not.
if (this.cache_.hasFreshCache(entries, names))
return Promise.resolve(this.getCache(entries, names));
@@ -60,11 +75,19 @@ NewMetadataProvider.prototype.get = function(entries, names) {
// If the requests are not empty, call the requests.
if (requests.length) {
- var requestedEntries = [];
- for (var i = 0; i < requests.length; i++) {
- requestedEntries.push(requests[i].entry);
- }
this.getImpl(requests).then(function(list) {
+ // Obtain requested entries and ensure all the requested properties are
+ // contained in the result.
+ var requestedEntries = [];
+ for (var i = 0; i < requests.length; i++) {
+ requestedEntries.push(requests[i].entry);
+ for (var j = 0; j < requests[i].names.length; j++) {
+ var name = requests[i].names[j];
+ if (!(name in list[i]))
+ list[i][name] = undefined;
+ }
+ }
+
// Store cache.
if (this.cache_.storeProperties(requestId, requestedEntries, list)) {
// TODO(hirono): Dispatch metadata change event here.
« no previous file with comments | « no previous file | ui/file_manager/file_manager/foreground/js/metadata/new_metadata_provider_unittest.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698