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

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

Issue 400703002: Ensure that the callback for MetadataCache.getOne() is called asynchronously. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add a blank line for long comment block. Created 6 years, 5 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 | no next file » | 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/metadata_cache.js
diff --git a/ui/file_manager/file_manager/foreground/js/metadata/metadata_cache.js b/ui/file_manager/file_manager/foreground/js/metadata/metadata_cache.js
index e991451208acadfaf94cc8d2157062333850675c..79e19e2c57a82e6f328afdeabfda9ab75f8cc2c7 100644
--- a/ui/file_manager/file_manager/foreground/js/metadata/metadata_cache.js
+++ b/ui/file_manager/file_manager/foreground/js/metadata/metadata_cache.js
@@ -199,9 +199,10 @@ MetadataCache.prototype.currentEvictionThreshold_ = function() {
* @param {Array.<Entry>} entries The list of entries.
* @param {string} type The metadata type.
* @param {function(Object)} callback The metadata is passed to callback.
+ * The callback is called asynchronously.
*/
MetadataCache.prototype.get = function(entries, type, callback) {
- return this.getInternal_(entries, type, false, callback);
+ this.getInternal_(entries, type, false, callback);
};
/**
@@ -211,9 +212,10 @@ MetadataCache.prototype.get = function(entries, type, callback) {
* @param {Array.<Entry>} entries The list of entries.
* @param {string} type The metadata type.
* @param {function(Object)} callback The metadata is passed to callback.
+ * The callback is called asynchronously.
*/
MetadataCache.prototype.getLatest = function(entries, type, callback) {
- return this.getInternal_(entries, type, true, callback);
+ this.getInternal_(entries, type, true, callback);
};
/**
@@ -224,11 +226,12 @@ MetadataCache.prototype.getLatest = function(entries, type, callback) {
* @param {boolean} refresh True to get the latest value and refresh the cache,
* false to get the value from the cache.
* @param {function(Object)} callback The metadata is passed to callback.
+ * The callback is called asynchronously.
*/
MetadataCache.prototype.getInternal_ =
function(entries, type, refresh, callback) {
if (entries.length === 0) {
- if (callback) callback([]);
+ if (callback) setTimeout(callback.bind(null, []), 0);
return;
}
@@ -241,7 +244,7 @@ MetadataCache.prototype.getInternal_ =
remaining--;
if (remaining === 0) {
this.endBatchUpdates();
- if (callback) setTimeout(callback, 0, result);
+ if (callback) callback(result);
}
};
@@ -256,12 +259,14 @@ MetadataCache.prototype.getInternal_ =
/**
* Fetches the metadata for one Entry. See comments to |get|.
+ *
* @param {Entry} entry The entry.
* @param {string} type Metadata type.
- * @param {function(Object)} callback The callback.
+ * @param {function(Object)} callback The metadata is passed to callback.
+ * The callback is called asynchronously.
*/
MetadataCache.prototype.getOne = function(entry, type, callback, refresh) {
- return this.getOneInternal_(entry, type, false, callback);
+ this.getOneInternal_(entry, type, false, callback);
};
/**
@@ -271,7 +276,8 @@ MetadataCache.prototype.getOne = function(entry, type, callback, refresh) {
* @param {string} type Metadata type.
* @param {boolean} refresh True to get the latest value and refresh the cache,
* false to get the value from the cache.
- * @param {function(Object)} callback The callback.
+ * @param {function(Object)} callback The metadata is passed to callback.
+ * The callback is called asynchronously.
* @private
*/
MetadataCache.prototype.getOneInternal_ =
@@ -306,7 +312,7 @@ MetadataCache.prototype.getOneInternal_ =
if (!refresh && type in item.properties) {
// Uses cache, if available and not on the 'refresh' mode.
- callback(item.properties[type]);
+ setTimeout(callback.bind(null, item.properties[type]), 0);
return;
}
@@ -354,7 +360,7 @@ MetadataCache.prototype.getOneInternal_ =
var tryNextProvider = function() {
if (providers.length === 0) {
self.endBatchUpdates();
- callback(item.properties[type] || null);
+ setTimeout(callback.bind(null, item.properties[type] || null), 0);
return;
}
@@ -684,7 +690,7 @@ MetadataProvider.prototype.isInitialized = function() { return true; };
* @param {Entry} entry File entry.
* @param {string} type Requested metadata type.
* @param {function(Object)} callback Callback expects a map from metadata type
- * to metadata value.
+ * to metadata value. This callback must be called asynchronously.
*/
MetadataProvider.prototype.fetch = function(entry, type, callback) {
throw new Error('Default metadata provider cannot fetch.');
@@ -731,7 +737,7 @@ FilesystemProvider.prototype.getId = function() { return 'filesystem'; };
* @param {Entry} entry File entry.
* @param {string} type Requested metadata type.
* @param {function(Object)} callback Callback expects a map from metadata type
- * to metadata value.
+ * to metadata value. This callback is called asynchronously.
*/
FilesystemProvider.prototype.fetch = function(
entry, type, callback) {
@@ -809,7 +815,7 @@ DriveProvider.prototype.getId = function() { return 'drive'; };
* @param {Entry} entry File entry.
* @param {string} type Requested metadata type.
* @param {function(Object)} callback Callback expects a map from metadata type
- * to metadata value.
+ * to metadata value. This callback is called asynchronously.
*/
DriveProvider.prototype.fetch = function(entry, type, callback) {
this.entries_.push(entry);
@@ -994,11 +1000,11 @@ ContentProvider.prototype.getId = function() { return 'content'; };
* @param {Entry} entry File entry.
* @param {string} type Requested metadata type.
* @param {function(Object)} callback Callback expects a map from metadata type
- * to metadata value.
+ * to metadata value. This callback is called asynchronously.
*/
ContentProvider.prototype.fetch = function(entry, type, callback) {
if (entry.isDirectory) {
- callback({});
+ setTimeout(callback.bind(null, {}), 0);
return;
}
var entryURL = entry.toURL();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698