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 url to an object containing properties. | 6 * MetadataCache is a map from url 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 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 var self = this; | 607 var self = this; |
608 | 608 |
609 chrome.fileBrowserPrivate.getGDataFileProperties(urls, function(props) { | 609 chrome.fileBrowserPrivate.getGDataFileProperties(urls, function(props) { |
610 for (var index = 0; index < urls.length; index++) { | 610 for (var index = 0; index < urls.length; index++) { |
611 callbacks[index](self.convert_(props[index])); | 611 callbacks[index](self.convert_(props[index])); |
612 } | 612 } |
613 }); | 613 }); |
614 }; | 614 }; |
615 | 615 |
616 /** | 616 /** |
| 617 * Pattern for Docs urls that are available in the offline mode. |
| 618 */ |
| 619 GDataProvider.OFFLINE_DOCS_REGEXP = /\/(document|spreadsheet)\//; |
| 620 |
| 621 /** |
| 622 * @param {GDataFileProperties} data GData file properties. |
| 623 * @return {boolean} True if the file is available offline. |
| 624 */ |
| 625 GDataProvider.isAvailableOffline = function(data) { |
| 626 return data.isPresent || |
| 627 (data.isHosted && GDataProvider.OFFLINE_DOCS_REGEXP.test(data.editUrl)); |
| 628 }; |
| 629 |
| 630 /** |
617 * Converts API metadata to internal format. | 631 * Converts API metadata to internal format. |
618 * @param {Object} data Metadata from API call. | 632 * @param {Object} data Metadata from API call. |
619 * @return {Object} Metadata in internal format. | 633 * @return {Object} Metadata in internal format. |
620 * @private | 634 * @private |
621 */ | 635 */ |
622 GDataProvider.prototype.convert_ = function(data) { | 636 GDataProvider.prototype.convert_ = function(data) { |
623 var result = {}; | 637 var result = {}; |
624 result.gdata = { | 638 result.gdata = { |
625 present: data.isPresent, | 639 present: data.isPresent, |
626 pinned: data.isPinned, | 640 pinned: data.isPinned, |
627 hosted: data.isHosted, | 641 hosted: data.isHosted, |
628 dirty: data.isDirty, | 642 dirty: data.isDirty, |
629 availableOffline: data.isPresent && !data.isHosted, | 643 availableOffline: GDataProvider.isAvailableOffline(data), |
630 contentUrl: (data.contentUrl || '').replace(/\?.*$/gi, ''), | 644 contentUrl: (data.contentUrl || '').replace(/\?.*$/gi, ''), |
631 editUrl: data.editUrl || '' | 645 editUrl: data.editUrl || '' |
632 }; | 646 }; |
633 if ('thumbnailUrl' in data) { | 647 if ('thumbnailUrl' in data) { |
634 result.thumbnail = { | 648 result.thumbnail = { |
635 url: data.thumbnailUrl, | 649 url: data.thumbnailUrl, |
636 transform: '' | 650 transform: '' |
637 }; | 651 }; |
638 } | 652 } |
639 return result; | 653 return result; |
640 }; | 654 }; |
OLD | NEW |