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

Unified Diff: chrome/browser/resources/file_manager/js/metadata/metadata_cache.js

Issue 10187004: [filemanager] Move GData properties to metadata cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fixes. Created 8 years, 8 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 | « chrome/browser/resources/file_manager/js/file_manager.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/file_manager/js/metadata/metadata_cache.js
===================================================================
--- chrome/browser/resources/file_manager/js/metadata/metadata_cache.js (revision 133422)
+++ chrome/browser/resources/file_manager/js/metadata/metadata_cache.js (working copy)
@@ -10,7 +10,7 @@
* {
* filesystem: size, modificationTime, icon, fileType
* internal: presence
- * gdata: pinned, present, dirty, editUrl
+ * gdata: pinned, present, hosted, editUrl, contentUrl, availableOffline
* thumbnail: url, transform
* media: artist, album, title
* }
@@ -88,6 +88,7 @@
MetadataCache.createFull = function() {
var cache = new MetadataCache();
cache.providers_.push(new FilesystemProvider());
+ cache.providers_.push(new GDataProvider());
return cache;
};
@@ -119,7 +120,7 @@
remaining--;
if (remaining == 0) {
this.endBatchUpdates();
- if (callback) callback(result);
+ if (callback) setTimeout(callback, 0, result);
}
}
@@ -451,8 +452,8 @@
/**
* Provider of filesystem metadata.
- * This provider returns the following object:
- * {
+ * This provider returns the following objects:
+ * filesystem: {
* size;
* modificationTime;
* icon - string describing icon type;
@@ -525,3 +526,115 @@
else
webkitResolveLocalFileSystemURL(url, onEntry, onError);
};
+
+/**
+ * Provider of gdata metadata.
+ * This provider returns the following objects:
+ * gdata: { pinned, hosted, present, dirty, editUrl, contentUrl }
+ * thumbnail: { url, transform }
+ * @constructor
+ */
+function GDataProvider() {
+ MetadataProvider2.call(this, 'gdata');
+
+ // We batch metadata fetches into single API call.
+ this.urls_ = [];
+ this.callbacks_ = [];
+ this.scheduled_ = false;
+
+ this.scheduleBound_ = this.schedule_.bind(this);
+}
+
+GDataProvider.prototype = {
+ __proto__: MetadataProvider2.prototype
+};
+
+/**
+ * Pattern for urls supported by GDataProvider.
+ */
+GDataProvider.URL_PATTERN =
+ new RegExp('^filesystem:[^/]*://[^/]*/[^/]*/gdata/(.*)');
+
+/**
+ * @param {string} url The url.
+ * @return {boolean} Whether this provider supports the url.
+ */
+GDataProvider.prototype.supportsUrl = function(url) {
+ return GDataProvider.URL_PATTERN.test(url);
+};
+
+/**
+ * @param {string} type The metadata type.
+ * @return {boolean} Whether this provider provides this metadata.
+ */
+GDataProvider.prototype.providesType = function(type) {
+ return type == 'gdata' || type == 'thumbnail';
+};
+
+/**
+ * @return {string} Unique provider id.
+ */
+GDataProvider.prototype.getId = function() { return 'gdata'; };
+
+/**
+ * Fetches the metadata.
+ * @param {string} url File url.
+ * @param {string} type Requested metadata type.
+ * @param {Function(Object)} callback Callback expects a map from metadata type
+ * to metadata value.
+ * @param {Entry=} opt_entry The file entry if present.
+ */
+GDataProvider.prototype.fetch = function(url, type, callback, opt_entry) {
+ this.urls_.push(url);
+ this.callbacks_.push(callback);
+ if (!this.scheduled_) {
+ this.scheduled_ = true;
+ setTimeout(this.scheduleBound_, 0);
+ }
+};
+
+/**
+ * Schedules the API call.
+ * @private
+ */
+GDataProvider.prototype.schedule_ = function() {
Vladislav Kaznacheev 2012/04/24 12:48:10 The method name is confusing. "Schedule" means "do
dgozman 2012/04/24 13:18:08 Done.
+ this.scheduled_ = false;
+
+ var urls = this.urls_;
+ var callbacks = this.callbacks_;
+ this.urls_ = [];
+ this.callbacks_ = [];
+ var self = this;
+
+ chrome.fileBrowserPrivate.getGDataFileProperties(urls, function(props) {
+ for (var index = 0; index < urls.length; index++) {
+ callbacks[index](self.convert_(props[index]));
+ }
+ });
+};
+
+/**
+ * Converts API metadata to internal format.
+ * @param {Object} data Metadata from API call.
+ * @return {Object} Metadata in internal format.
+ * @private
+ */
+GDataProvider.prototype.convert_ = function(data) {
+ var result = {};
+ result.gdata = {
+ present: data.isPresent,
+ pinned: data.isPinned,
+ hosted: data.isHosted,
+ dirty: data.isDirty,
+ availableOffline: data.isPresent && !data.isHosted,
+ contentUrl: (data.contentUrl || '').replace(/\?.*$/gi, ''),
+ editUrl: data.editUrl || ''
+ };
+ if ('thumbnailUrl' in data) {
+ result.thumbnail = {
+ url: data.thumbnailUrl,
+ transform: ''
+ };
+ }
+ return result;
+};
« no previous file with comments | « chrome/browser/resources/file_manager/js/file_manager.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698