Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / ui / file_manager / file_manager / foreground / js / metadata / metadata_cache.js
index e64307d..f72d3dd 100644 (file)
  * {
  *   filesystem: size, modificationTime
  *   internal: presence
- *   drive: pinned, present, hosted, availableOffline
- *   streaming: (no property)
+ *   external: pinned, present, hosted, availableOffline
  *
- *   Following are not fetched for non-present drive files.
+ *   Following are not fetched for non-present external files.
  *   media: artist, album, title, width, height, imageTransform, etc.
  *   thumbnail: url, transform
  *
  *   Following are always fetched from content, and so force the downloading
- *   of remote drive files. One should use this for required content metadata,
+ *   of external files. One should use this for required content metadata,
  *   i.e. image orientation.
  *   fetchedMedia: width, height, etc.
  * }
  *
  * Typical usages:
  * {
- *   cache.get([entry1, entry2], 'drive|filesystem', function(metadata) {
- *     if (metadata[0].drive.pinned && metadata[1].filesystem.size === 0)
+ *   cache.get([entry1, entry2], 'external|filesystem', function(metadata) {
+ *     if (metadata[0].external.pinned && metadata[1].filesystem.size === 0)
  *       alert("Pinned and empty!");
  *   });
  *
@@ -119,10 +118,10 @@ MetadataCache.EVICTION_THRESHOLD_MARGIN = 500;
  * @return {MetadataCache!} The cache with all providers.
  */
 MetadataCache.createFull = function(volumeManager) {
-  // DriveProvider should be prior to FileSystemProvider, because it covers
-  // FileSystemProvider for files in Drive.
+  // ExternalProvider should be prior to FileSystemProvider, because it covers
+  // FileSystemProvider for files on the external backend, eg. Drive.
   return new MetadataCache([
-    new DriveProvider(volumeManager),
+    new ExternalProvider(volumeManager),
     new FilesystemProvider(),
     new ContentProvider()
   ]);
@@ -227,6 +226,7 @@ MetadataCache.prototype.getLatest = function(entries, type, callback) {
  *     false to get the value from the cache.
  * @param {function(Object)} callback The metadata is passed to callback.
  *     The callback is called asynchronously.
+ * @private
  */
 MetadataCache.prototype.getInternal_ =
     function(entries, type, refresh, callback) {
@@ -759,15 +759,14 @@ FilesystemProvider.prototype.fetch = function(
 };
 
 /**
- * Provider of drive metadata.
+ * Provider of metadata for entries on the external file system backend.
  * This provider returns the following objects:
- *     drive: { pinned, hosted, present, customIconUrl, etc. }
+ *     external: { pinned, hosted, present, customIconUrl, etc. }
  *     thumbnail: { url, transform }
- *     streaming: { }
  * @param {VolumeManagerWrapper} volumeManager Volume manager instance.
  * @constructor
  */
-function DriveProvider(volumeManager) {
+function ExternalProvider(volumeManager) {
   MetadataProvider.call(this);
 
   /**
@@ -784,7 +783,7 @@ function DriveProvider(volumeManager) {
   this.callApiBound_ = this.callApi_.bind(this);
 }
 
-DriveProvider.prototype = {
+ExternalProvider.prototype = {
   __proto__: MetadataProvider.prototype
 };
 
@@ -792,8 +791,9 @@ DriveProvider.prototype = {
  * @param {Entry} entry The entry.
  * @return {boolean} Whether this provider supports the entry.
  */
-DriveProvider.prototype.supportsEntry = function(entry) {
+ExternalProvider.prototype.supportsEntry = function(entry) {
   var locationInfo = this.volumeManager_.getLocationInfo(entry);
+  // TODO(mtomasz): Add support for provided file systems.
   return locationInfo && locationInfo.isDriveBased;
 };
 
@@ -801,15 +801,15 @@ DriveProvider.prototype.supportsEntry = function(entry) {
  * @param {string} type The metadata type.
  * @return {boolean} Whether this provider provides this metadata.
  */
-DriveProvider.prototype.providesType = function(type) {
-  return type === 'drive' || type === 'thumbnail' ||
-      type === 'streaming' || type === 'media' || type === 'filesystem';
+ExternalProvider.prototype.providesType = function(type) {
+  return type === 'external' || type === 'thumbnail' ||
+      type === 'media' || type === 'filesystem';
 };
 
 /**
  * @return {string} Unique provider id.
  */
-DriveProvider.prototype.getId = function() { return 'drive'; };
+ExternalProvider.prototype.getId = function() { return 'external'; };
 
 /**
  * Fetches the metadata.
@@ -818,7 +818,7 @@ DriveProvider.prototype.getId = function() { return 'drive'; };
  * @param {function(Object)} callback Callback expects a map from metadata type
  *     to metadata value. This callback is called asynchronously.
  */
-DriveProvider.prototype.fetch = function(entry, type, callback) {
+ExternalProvider.prototype.fetch = function(entry, type, callback) {
   this.entries_.push(entry);
   this.callbacks_.push(callback);
   if (!this.scheduled_) {
@@ -831,7 +831,7 @@ DriveProvider.prototype.fetch = function(entry, type, callback) {
  * Schedules the API call.
  * @private
  */
-DriveProvider.prototype.callApi_ = function() {
+ExternalProvider.prototype.callApi_ = function() {
   this.scheduled_ = false;
 
   var entries = this.entries_;
@@ -840,9 +840,10 @@ DriveProvider.prototype.callApi_ = function() {
   this.callbacks_ = [];
   var self = this;
 
-  // TODO(mtomasz): Make getDriveEntryProperties accept Entry instead of URL.
+  // TODO(mtomasz): Move conversion from entry to url to custom bindings.
+  // crbug.com/345527.
   var entryURLs = util.entriesToURLs(entries);
-  chrome.fileBrowserPrivate.getDriveEntryProperties(
+  chrome.fileManagerPrivate.getEntryProperties(
       entryURLs,
       function(propertiesList) {
         console.assert(propertiesList.length === callbacks.length);
@@ -853,57 +854,28 @@ DriveProvider.prototype.callApi_ = function() {
 };
 
 /**
- * @param {DriveEntryProperties} data Drive entry properties.
- * @param {Entry} entry File entry.
- * @return {boolean} True if the file is available offline.
- */
-DriveProvider.isAvailableOffline = function(data, entry) {
-  if (data.isPresent)
-    return true;
-
-  if (!data.isHosted)
-    return false;
-
-  // What's available offline? See the 'Web' column at:
-  // http://support.google.com/drive/answer/1628467
-  var subtype = FileType.getType(entry).subtype;
-  return (subtype === 'doc' ||
-          subtype === 'draw' ||
-          subtype === 'sheet' ||
-          subtype === 'slides');
-};
-
-/**
- * @param {DriveEntryProperties} data Drive entry properties.
- * @return {boolean} True if opening the file does not require downloading it
- *    via a metered connection.
- */
-DriveProvider.isAvailableWhenMetered = function(data) {
-  return data.isPresent || data.isHosted;
-};
-
-/**
  * Converts API metadata to internal format.
  * @param {Object} data Metadata from API call.
  * @param {Entry} entry File entry.
  * @return {Object} Metadata in internal format.
  * @private
  */
-DriveProvider.prototype.convert_ = function(data, entry) {
+ExternalProvider.prototype.convert_ = function(data, entry) {
   var result = {};
-  result.drive = {
+  result.external = {
     present: data.isPresent,
     pinned: data.isPinned,
     hosted: data.isHosted,
     imageWidth: data.imageWidth,
     imageHeight: data.imageHeight,
     imageRotation: data.imageRotation,
-    availableOffline: DriveProvider.isAvailableOffline(data, entry),
-    availableWhenMetered: DriveProvider.isAvailableWhenMetered(data),
+    availableOffline: data.isAvailableOffline,
+    availableWhenMetered: data.isAvailableWhenMetered,
     customIconUrl: data.customIconUrl || '',
     contentMimeType: data.contentMimeType || '',
     sharedWithMe: data.sharedWithMe,
-    shared: data.shared
+    shared: data.shared,
+    thumbnailUrl: data.thumbnailUrl  // Thumbnail passed from external server.
   };
 
   result.filesystem = {
@@ -911,23 +883,22 @@ DriveProvider.prototype.convert_ = function(data, entry) {
     modificationTime: new Date(data.lastModifiedTime)
   };
 
-  if ('thumbnailUrl' in data) {
+  if (data.isPresent) {
+    // If the file is present, don't fill the thumbnail here and allow to
+    // generate it by next providers.
+    result.thumbnail = null;
+  } else if ('thumbnailUrl' in data) {
     result.thumbnail = {
       url: data.thumbnailUrl,
       transform: null
     };
-  } else if (data.isPresent) {
-    result.thumbnail = null;
   } else {
-    // Block the local fetch for drive files, which require downloading.
+    // Not present in cache, so do not allow to generate it by next providers.
     result.thumbnail = {url: '', transform: null};
   }
 
+  // If present in cache, then allow to fetch media by next providers.
   result.media = data.isPresent ? null : {};
-  // Indicate that the data is not available in local cache.
-  // It used to have a field 'url' for streaming play, but it is
-  // derprecated. See crbug.com/174560.
-  result.streaming = data.isPresent ? null : {};
 
   return result;
 };