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 * Namespace for utility functions. | 6 * Namespace for utility functions. |
7 */ | 7 */ |
8 var util = {}; | 8 var util = {}; |
9 | 9 |
10 /** | 10 /** |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 */ | 676 */ |
677 util.isSameEntry = function(entry1, entry2) { | 677 util.isSameEntry = function(entry1, entry2) { |
678 if (!entry1 && !entry2) | 678 if (!entry1 && !entry2) |
679 return true; | 679 return true; |
680 if (!entry1 || !entry2) | 680 if (!entry1 || !entry2) |
681 return false; | 681 return false; |
682 return entry1.toURL() === entry2.toURL(); | 682 return entry1.toURL() === entry2.toURL(); |
683 }; | 683 }; |
684 | 684 |
685 /** | 685 /** |
686 * Compares two entry arrays. | |
687 * @param {Array<!Entry>} entries1 The entry array to be compared. | |
688 * @param {Array<!Entry>} entries2 The entry array to be compared. | |
689 * @return {boolean} True if the both arrays contain same files or directories | |
690 * in the same order. Returns true if both arrays are null. | |
691 */ | |
692 util.isSameEntries = function(entries1, entries2) { | |
693 if (!entries1 && !entries2) | |
694 return true; | |
695 if (!entries1 || !entries2) | |
696 return false; | |
697 if (entries1.length !== entries2.length) | |
698 return false; | |
699 for (var i = 0; i < entries1.length; i++) { | |
700 if (!util.isSameEntry(entries1[i], entries2[i])) { | |
701 return false; | |
702 } | |
703 } | |
704 return true; | |
705 }; | |
706 | |
707 /** | |
708 * Compares two file systems. | 686 * Compares two file systems. |
709 * @param {FileSystem} fileSystem1 The file system to be compared. | 687 * @param {FileSystem} fileSystem1 The file system to be compared. |
710 * @param {FileSystem} fileSystem2 The file system to be compared. | 688 * @param {FileSystem} fileSystem2 The file system to be compared. |
711 * @return {boolean} True if the both file systems are equal. Also, returns true | 689 * @return {boolean} True if the both file systems are equal. Also, returns true |
712 * if both file systems are null. | 690 * if both file systems are null. |
713 */ | 691 */ |
714 util.isSameFileSystem = function(fileSystem1, fileSystem2) { | 692 util.isSameFileSystem = function(fileSystem1, fileSystem2) { |
715 if (!fileSystem1 && !fileSystem2) | 693 if (!fileSystem1 && !fileSystem2) |
716 return true; | 694 return true; |
717 if (!fileSystem1 || !fileSystem2) | 695 if (!fileSystem1 || !fileSystem2) |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 * @return {!Promise} A promise which can be rejected by timeout. | 1079 * @return {!Promise} A promise which can be rejected by timeout. |
1102 */ | 1080 */ |
1103 util.timeoutPromise = function(promise, ms, opt_message) { | 1081 util.timeoutPromise = function(promise, ms, opt_message) { |
1104 return Promise.race([ | 1082 return Promise.race([ |
1105 promise, | 1083 promise, |
1106 util.delay(ms).then(function() { | 1084 util.delay(ms).then(function() { |
1107 throw new Error(opt_message || 'Operation timed out.'); | 1085 throw new Error(opt_message || 'Operation timed out.'); |
1108 }) | 1086 }) |
1109 ]); | 1087 ]); |
1110 }; | 1088 }; |
OLD | NEW |