OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * MetadataCache is a map from url to an object containing properties. | 8 * MetadataCache is a map from url to an object containing properties. |
9 * Properties are divided by types, and all properties of one type are accessed | 9 * Properties are divided by types, and all properties of one type are accessed |
10 * at once. | 10 * at once. |
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 DriveProvider.prototype.callApi_ = function() { | 792 DriveProvider.prototype.callApi_ = function() { |
793 this.scheduled_ = false; | 793 this.scheduled_ = false; |
794 | 794 |
795 var urls = this.urls_; | 795 var urls = this.urls_; |
796 var callbacks = this.callbacks_; | 796 var callbacks = this.callbacks_; |
797 this.urls_ = []; | 797 this.urls_ = []; |
798 this.callbacks_ = []; | 798 this.callbacks_ = []; |
799 var self = this; | 799 var self = this; |
800 | 800 |
801 var task = function(url, callback) { | 801 var task = function(url, callback) { |
802 chrome.fileBrowserPrivate.getDriveFileProperties(url, function(properties) { | 802 chrome.fileBrowserPrivate.getDriveEntryProperties(url, |
803 callback(self.convert_(properties, url)); | 803 function(properties) { |
804 }); | 804 callback(self.convert_(properties, url)); |
| 805 }); |
805 }; | 806 }; |
806 | 807 |
807 for (var i = 0; i < urls.length; i++) | 808 for (var i = 0; i < urls.length; i++) |
808 task(urls[i], callbacks[i]); | 809 task(urls[i], callbacks[i]); |
809 }; | 810 }; |
810 | 811 |
811 /** | 812 /** |
812 * @param {DriveFileProperties} data Drive file properties. | 813 * @param {DriveEntryProperties} data Drive entry properties. |
813 * @param {string} url File url. | 814 * @param {string} url File url. |
814 * @return {boolean} True if the file is available offline. | 815 * @return {boolean} True if the file is available offline. |
815 */ | 816 */ |
816 DriveProvider.isAvailableOffline = function(data, url) { | 817 DriveProvider.isAvailableOffline = function(data, url) { |
817 if (data.isPresent) | 818 if (data.isPresent) |
818 return true; | 819 return true; |
819 | 820 |
820 if (!data.isHosted) | 821 if (!data.isHosted) |
821 return false; | 822 return false; |
822 | 823 |
823 var subtype = FileType.getType(url).subtype; | 824 var subtype = FileType.getType(url).subtype; |
824 return subtype == 'doc' || subtype == 'sheet'; | 825 return subtype == 'doc' || subtype == 'sheet'; |
825 }; | 826 }; |
826 | 827 |
827 /** | 828 /** |
828 * @param {DriveFileProperties} data Drive file properties. | 829 * @param {DriveEntryProperties} data Drive entry properties. |
829 * @return {boolean} True if opening the file does not require downloading it | 830 * @return {boolean} True if opening the file does not require downloading it |
830 * via a metered connection. | 831 * via a metered connection. |
831 */ | 832 */ |
832 DriveProvider.isAvailableWhenMetered = function(data) { | 833 DriveProvider.isAvailableWhenMetered = function(data) { |
833 return data.isPresent || data.isHosted; | 834 return data.isPresent || data.isHosted; |
834 }; | 835 }; |
835 | 836 |
836 /** | 837 /** |
837 * Converts API metadata to internal format. | 838 * Converts API metadata to internal format. |
838 * @param {Object} data Metadata from API call. | 839 * @param {Object} data Metadata from API call. |
839 * @param {string} url File url. | 840 * @param {string} url File url. |
840 * @return {Object} Metadata in internal format. | 841 * @return {Object} Metadata in internal format. |
841 * @private | 842 * @private |
842 */ | 843 */ |
843 DriveProvider.prototype.convert_ = function(data, url) { | 844 DriveProvider.prototype.convert_ = function(data, url) { |
844 var result = {}; | 845 var result = {}; |
845 result.drive = { | 846 result.drive = { |
846 present: data.isPresent, | 847 present: data.isPresent, |
847 pinned: data.isPinned, | 848 pinned: data.isPinned, |
848 hosted: data.isHosted, | 849 hosted: data.isHosted, |
849 dirty: data.isDirty, | 850 dirty: data.isDirty, |
850 availableOffline: DriveProvider.isAvailableOffline(data, url), | 851 availableOffline: DriveProvider.isAvailableOffline(data, url), |
851 availableWhenMetered: DriveProvider.isAvailableWhenMetered(data), | 852 availableWhenMetered: DriveProvider.isAvailableWhenMetered(data), |
852 contentUrl: (data.contentUrl || '').replace(/\?.*$/gi, ''), | 853 contentUrl: (data.contentUrl || '').replace(/\?.*$/gi, ''), |
853 editUrl: data.editUrl || '', | 854 editUrl: data.editUrl || '', |
854 driveApps: data.driveApps || [], | 855 driveApps: data.driveApps || [], |
855 contentMimeType: data.contentMimeType || '' | 856 contentMimeType: data.contentMimeType || '', |
| 857 sharedWithMe: data.sharedWithMe |
856 }; | 858 }; |
857 | 859 |
858 if (!data.isPresent) { | 860 if (!data.isPresent) { |
859 // Block the local fetch for drive files, which require downloading. | 861 // Block the local fetch for drive files, which require downloading. |
860 result.thumbnail = { url: '', transform: null }; | 862 result.thumbnail = { url: '', transform: null }; |
861 result.media = {}; | 863 result.media = {}; |
862 } | 864 } |
863 | 865 |
864 if ('thumbnailUrl' in data) { | 866 if ('thumbnailUrl' in data) { |
865 result.thumbnail = { | 867 result.thumbnail = { |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 | 1072 |
1071 /** | 1073 /** |
1072 * Handles the 'log' message from the worker. | 1074 * Handles the 'log' message from the worker. |
1073 * @param {Array.<*>} arglist Log arguments. | 1075 * @param {Array.<*>} arglist Log arguments. |
1074 * @private | 1076 * @private |
1075 */ | 1077 */ |
1076 ContentProvider.prototype.onLog_ = function(arglist) { | 1078 ContentProvider.prototype.onLog_ = function(arglist) { |
1077 if (MetadataCache.log) // Avoid log spam by default. | 1079 if (MetadataCache.log) // Avoid log spam by default. |
1078 console.log.apply(console, ['metadata:'].concat(arglist)); | 1080 console.log.apply(console, ['metadata:'].concat(arglist)); |
1079 }; | 1081 }; |
OLD | NEW |