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 Entry to an object containing properties. | 8 * MetadataCache is a map from Entry 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 * of the observer Entry. | 101 * of the observer Entry. |
102 */ | 102 */ |
103 MetadataCache.DESCENDANTS = 2; | 103 MetadataCache.DESCENDANTS = 2; |
104 | 104 |
105 /** | 105 /** |
106 * Minimum number of items in cache to start eviction. | 106 * Minimum number of items in cache to start eviction. |
107 */ | 107 */ |
108 MetadataCache.EVICTION_NUMBER = 1000; | 108 MetadataCache.EVICTION_NUMBER = 1000; |
109 | 109 |
110 /** | 110 /** |
| 111 * @param {VolumeManagerWrapper} volumeManager Volume manager instance. |
111 * @return {MetadataCache!} The cache with all providers. | 112 * @return {MetadataCache!} The cache with all providers. |
112 */ | 113 */ |
113 MetadataCache.createFull = function() { | 114 MetadataCache.createFull = function(volumeManager) { |
114 var cache = new MetadataCache(); | 115 var cache = new MetadataCache(); |
115 cache.providers_.push(new FilesystemProvider()); | 116 cache.providers_.push(new FilesystemProvider()); |
116 cache.providers_.push(new DriveProvider()); | 117 cache.providers_.push(new DriveProvider(volumeManager)); |
117 cache.providers_.push(new ContentProvider()); | 118 cache.providers_.push(new ContentProvider()); |
118 return cache; | 119 return cache; |
119 }; | 120 }; |
120 | 121 |
121 /** | 122 /** |
122 * Clones metadata entry. Metadata entries may contain scalars, arrays, | 123 * Clones metadata entry. Metadata entries may contain scalars, arrays, |
123 * hash arrays and Date object. Other objects are not supported. | 124 * hash arrays and Date object. Other objects are not supported. |
124 * @param {Object} metadata Metadata object. | 125 * @param {Object} metadata Metadata object. |
125 * @return {Object} Cloned entry. | 126 * @return {Object} Cloned entry. |
126 */ | 127 */ |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 | 665 |
665 entry.getMetadata(onMetadata.bind(null, entry), onError); | 666 entry.getMetadata(onMetadata.bind(null, entry), onError); |
666 }; | 667 }; |
667 | 668 |
668 /** | 669 /** |
669 * Provider of drive metadata. | 670 * Provider of drive metadata. |
670 * This provider returns the following objects: | 671 * This provider returns the following objects: |
671 * drive: { pinned, hosted, present, customIconUrl, etc. } | 672 * drive: { pinned, hosted, present, customIconUrl, etc. } |
672 * thumbnail: { url, transform } | 673 * thumbnail: { url, transform } |
673 * streaming: { } | 674 * streaming: { } |
| 675 * @param {VolumeManagerWrapper} volumeManager Volume manager instance. |
674 * @constructor | 676 * @constructor |
675 */ | 677 */ |
676 function DriveProvider() { | 678 function DriveProvider(volumeManager) { |
677 MetadataProvider.call(this); | 679 MetadataProvider.call(this); |
678 | 680 |
| 681 /** |
| 682 * @type {VolumeManagerWrapper} |
| 683 * @private |
| 684 */ |
| 685 this.volumeManager_ = volumeManager; |
| 686 |
679 // We batch metadata fetches into single API call. | 687 // We batch metadata fetches into single API call. |
680 this.entries_ = []; | 688 this.entries_ = []; |
681 this.callbacks_ = []; | 689 this.callbacks_ = []; |
682 this.scheduled_ = false; | 690 this.scheduled_ = false; |
683 | 691 |
684 this.callApiBound_ = this.callApi_.bind(this); | 692 this.callApiBound_ = this.callApi_.bind(this); |
685 } | 693 } |
686 | 694 |
687 DriveProvider.prototype = { | 695 DriveProvider.prototype = { |
688 __proto__: MetadataProvider.prototype | 696 __proto__: MetadataProvider.prototype |
689 }; | 697 }; |
690 | 698 |
691 /** | 699 /** |
692 * @param {Entry} entry The entry. | 700 * @param {Entry} entry The entry. |
693 * @return {boolean} Whether this provider supports the entry. | 701 * @return {boolean} Whether this provider supports the entry. |
694 */ | 702 */ |
695 DriveProvider.prototype.supportsEntry = function(entry) { | 703 DriveProvider.prototype.supportsEntry = function(entry) { |
696 // TODO(mtomasz): Use Entry instead of paths. | 704 var locationInfo = this.volumeManager_.getLocationInfo(entry); |
697 return PathUtil.isDriveBasedPath(entry.fullPath); | 705 return locationInfo && locationInfo.isDriveBased; |
698 }; | 706 }; |
699 | 707 |
700 /** | 708 /** |
701 * @param {string} type The metadata type. | 709 * @param {string} type The metadata type. |
702 * @return {boolean} Whether this provider provides this metadata. | 710 * @return {boolean} Whether this provider provides this metadata. |
703 */ | 711 */ |
704 DriveProvider.prototype.providesType = function(type) { | 712 DriveProvider.prototype.providesType = function(type) { |
705 return type === 'drive' || type === 'thumbnail' || | 713 return type === 'drive' || type === 'thumbnail' || |
706 type === 'streaming' || type === 'media'; | 714 type === 'streaming' || type === 'media'; |
707 }; | 715 }; |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 | 1020 |
1013 /** | 1021 /** |
1014 * Handles the 'log' message from the worker. | 1022 * Handles the 'log' message from the worker. |
1015 * @param {Array.<*>} arglist Log arguments. | 1023 * @param {Array.<*>} arglist Log arguments. |
1016 * @private | 1024 * @private |
1017 */ | 1025 */ |
1018 ContentProvider.prototype.onLog_ = function(arglist) { | 1026 ContentProvider.prototype.onLog_ = function(arglist) { |
1019 if (MetadataCache.log) // Avoid log spam by default. | 1027 if (MetadataCache.log) // Avoid log spam by default. |
1020 console.log.apply(console, ['metadata:'].concat(arglist)); | 1028 console.log.apply(console, ['metadata:'].concat(arglist)); |
1021 }; | 1029 }; |
OLD | NEW |