Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Side by Side Diff: ui/file_manager/file_manager/common/js/importer_common.js

Issue 2856533003: Add background-wide file metadata cache. (Closed)
Patch Set: Rename global_metadata_cache to metadata_proxy. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // Shared cloud importer namespace 5 // Shared cloud importer namespace
6 var importer = importer || {}; 6 var importer = importer || {};
7 7
8 /** @enum {string} */ 8 /** @enum {string} */
9 importer.ScanEvent = { 9 importer.ScanEvent = {
10 FINALIZED: 'finalized', 10 FINALIZED: 'finalized',
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 * @return {string} 636 * @return {string}
637 */ 637 */
638 importer.inflateAppUrl = function(deflated) { 638 importer.inflateAppUrl = function(deflated) {
639 if (deflated.substring(0, 1) === '$') { 639 if (deflated.substring(0, 1) === '$') {
640 return importer.APP_URL_PREFIX_ + deflated.substring(1); 640 return importer.APP_URL_PREFIX_ + deflated.substring(1);
641 } 641 }
642 return deflated; 642 return deflated;
643 }; 643 };
644 644
645 /** 645 /**
646 * @param {!FileEntry} fileEntry
647 * @return {!Promise<string>} Resolves with a "hashcode" consisting of
648 * just the last modified time and the file size.
649 */
650 importer.createMetadataHashcode = function(fileEntry) {
651 var entry = new importer.PromisingFileEntry(fileEntry);
652 return new Promise(
653 /**
654 * @param {function()} resolve
655 * @param {function()} reject
656 * @this {importer.PersistentImportHistory}
657 */
658 function(resolve, reject) {
659 entry.getMetadata()
660 .then(
661 /**
662 * @param {!Object} metadata
663 * @return {!Promise<string>}
664 * @this {importer.PersistentImportHistory}
665 */
666 function(metadata) {
667 if (!('modificationTime' in metadata)) {
668 reject('File entry missing "modificationTime" field.');
669 } else if (!('size' in metadata)) {
670 reject('File entry missing "size" field.');
671 } else {
672 var secondsSinceEpoch =
673 importer.toSecondsFromEpoch(metadata.modificationTime);
674 resolve(secondsSinceEpoch + '_' + metadata.size);
675 }
676 }.bind(this));
677 }.bind(this))
678 .catch(importer.getLogger().catcher('importer-common-create-hashcode'));
679 };
680
681 /**
682 * @param {string} date A date string in the form 646 * @param {string} date A date string in the form
683 * expected by Date.parse. 647 * expected by Date.parse.
684 * @return {string} The number of seconds from epoch to the date...as a string. 648 * @return {string} The number of seconds from epoch to the date...as a string.
685 */ 649 */
686 importer.toSecondsFromEpoch = function(date) { 650 importer.toSecondsFromEpoch = function(date) {
687 // Since we're parsing a value that only has 651 // Since we're parsing a value that only has
688 // precision to the second, our last three digits 652 // precision to the second, our last three digits
689 // will always be 000. We strip them and end up 653 // will always be 000. We strip them and end up
690 // with seconds. 654 // with seconds.
691 var milliseconds = String(Date.parse(date)); 655 var milliseconds = String(Date.parse(date));
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 }); 1056 });
1093 }; 1057 };
1094 1058
1095 /** @private @const {!importer.ChromeLocalStorage} */ 1059 /** @private @const {!importer.ChromeLocalStorage} */
1096 importer.ChromeLocalStorage.INSTANCE_ = new importer.ChromeLocalStorage(); 1060 importer.ChromeLocalStorage.INSTANCE_ = new importer.ChromeLocalStorage();
1097 1061
1098 /** @return {!importer.ChromeLocalStorage} */ 1062 /** @return {!importer.ChromeLocalStorage} */
1099 importer.ChromeLocalStorage.getInstance = function() { 1063 importer.ChromeLocalStorage.getInstance = function() {
1100 return importer.ChromeLocalStorage.INSTANCE_; 1064 return importer.ChromeLocalStorage.INSTANCE_;
1101 }; 1065 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698