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 /** | 5 /** |
6 * MetadataCache is a map from Entry to an object containing properties. | 6 * MetadataCache is a map from Entry to an object containing properties. |
7 * Properties are divided by types, and all properties of one type are accessed | 7 * Properties are divided by types, and all properties of one type are accessed |
8 * at once. | 8 * at once. |
9 * Some of the properties: | 9 * Some of the properties: |
10 * { | 10 * { |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 | 351 |
352 fetchedCallbacks.push(onFetched); | 352 fetchedCallbacks.push(onFetched); |
353 | 353 |
354 // Querying now. | 354 // Querying now. |
355 if (fetchedCallbacks.length === 1) | 355 if (fetchedCallbacks.length === 1) |
356 currentProvider.fetch(entry, type, onProviderProperties); | 356 currentProvider.fetch(entry, type, onProviderProperties); |
357 }; | 357 }; |
358 | 358 |
359 var tryNextProvider = function() { | 359 var tryNextProvider = function() { |
360 if (providers.length === 0) { | 360 if (providers.length === 0) { |
| 361 // If not found, then mark the property as unavailable, so it's not |
| 362 // retrieved again. |
| 363 if (!(type in item.properties)) |
| 364 item.properties[type] = null; |
| 365 |
361 self.endBatchUpdates(); | 366 self.endBatchUpdates(); |
362 setTimeout(callback.bind(null, item.properties[type] || null), 0); | 367 setTimeout(callback.bind(null, item.properties[type]), 0); |
363 return; | 368 return; |
364 } | 369 } |
365 | 370 |
366 currentProvider = providers.shift(); | 371 currentProvider = providers.shift(); |
367 if (currentProvider.supportsEntry(entry) && | 372 if (currentProvider.supportsEntry(entry) && |
368 currentProvider.providesType(type)) { | 373 currentProvider.providesType(type)) { |
369 queryProvider(); | 374 queryProvider(); |
370 } else { | 375 } else { |
371 tryNextProvider(); | 376 tryNextProvider(); |
372 } | 377 } |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 sharedWithMe: data.sharedWithMe, | 890 sharedWithMe: data.sharedWithMe, |
886 shared: data.shared, | 891 shared: data.shared, |
887 thumbnailUrl: data.thumbnailUrl // Thumbnail passed from external server. | 892 thumbnailUrl: data.thumbnailUrl // Thumbnail passed from external server. |
888 }; | 893 }; |
889 | 894 |
890 result.filesystem = { | 895 result.filesystem = { |
891 size: (entry.isFile ? (data.fileSize || 0) : -1), | 896 size: (entry.isFile ? (data.fileSize || 0) : -1), |
892 modificationTime: new Date(data.lastModifiedTime) | 897 modificationTime: new Date(data.lastModifiedTime) |
893 }; | 898 }; |
894 | 899 |
895 if (data.isPresent) { | 900 // TODO(mtomasz): Remove all of the if logic in the new metadata cache. |
896 // If the file is present, don't fill the thumbnail here and allow to | 901 // If the file is not present, then use the thumbnail url instead of |
897 // generate it by next providers. | 902 // extracting the thumbnail from contents. |
898 result.thumbnail = null; | 903 if (data.isPresent === false) { |
899 } else if ('thumbnailUrl' in data) { | 904 if ('thumbnailUrl' in data) { |
900 result.thumbnail = { | 905 result.thumbnail = { |
901 url: data.thumbnailUrl, | 906 url: data.thumbnailUrl, |
902 transform: null | 907 transform: null |
903 }; | 908 }; |
904 } else { | 909 } else { |
905 // Not present in cache, so do not allow to generate it by next providers. | 910 // Not present in cache, so do not allow to generate it by next providers. |
906 result.thumbnail = {url: '', transform: null}; | 911 result.thumbnail = {url: '', transform: null}; |
| 912 } |
907 } | 913 } |
908 | 914 |
909 // If present in cache, then allow to fetch media by next providers. | 915 // If not present in cache, then do not allow to fetch media by next |
910 result.media = data.isPresent ? null : {}; | 916 // providers. |
| 917 if (data.isPresent === false) |
| 918 result.media = {}; |
911 | 919 |
912 return result; | 920 return result; |
913 }; | 921 }; |
914 | 922 |
915 | 923 |
916 /** | 924 /** |
917 * Provider of content metadata. | 925 * Provider of content metadata. |
918 * This provider returns the following objects: | 926 * This provider returns the following objects: |
919 * thumbnail: { url, transform } | 927 * thumbnail: { url, transform } |
920 * media: { artist, album, title, width, height, imageTransform, etc. } | 928 * media: { artist, album, title, width, height, imageTransform, etc. } |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 | 1108 |
1101 /** | 1109 /** |
1102 * Handles the 'log' message from the worker. | 1110 * Handles the 'log' message from the worker. |
1103 * @param {Array.<*>} arglist Log arguments. | 1111 * @param {Array.<*>} arglist Log arguments. |
1104 * @private | 1112 * @private |
1105 */ | 1113 */ |
1106 ContentProvider.prototype.onLog_ = function(arglist) { | 1114 ContentProvider.prototype.onLog_ = function(arglist) { |
1107 if (MetadataCache.log) // Avoid log spam by default. | 1115 if (MetadataCache.log) // Avoid log spam by default. |
1108 console.log.apply(console, ['metadata:'].concat(arglist)); | 1116 console.log.apply(console, ['metadata:'].concat(arglist)); |
1109 }; | 1117 }; |
OLD | NEW |