Chromium Code Reviews| Index: ui/file_manager/file_manager/common/js/importer_common.js |
| diff --git a/ui/file_manager/file_manager/common/js/importer_common.js b/ui/file_manager/file_manager/common/js/importer_common.js |
| index c03b8237506b776c94dcfa996edae7f8ee4dfbdf..02aa42b07bfa66a21a38fdc7fba72245cd8cd5e4 100644 |
| --- a/ui/file_manager/file_manager/common/js/importer_common.js |
| +++ b/ui/file_manager/file_manager/common/js/importer_common.js |
| @@ -197,6 +197,28 @@ importer.isMediaDirectory = function(entry, volumeInfoProvider) { |
| }; |
| /** |
| + * @param {!DirectoryEntry} directory Presumably the root of a filesystem. |
| + * @return {!Promise<boolean>} True if the directory has a media directory |
| + * (like DCIM) as a direct child. |
| + */ |
| +importer.hasMediaDirectory = function(directory) { |
|
mtomasz
2015/03/24 01:34:58
nit: This may be slow. Are we fine with it? Instea
Steve McKay
2015/03/24 22:39:20
I agree about this possibly being slow. Fixed.
|
| + var hasMediaDirectory = false; |
| + return importer.listEntries_( |
| + directory, |
| + /** @param {!Entry} entry */ |
| + function(entry) { |
| + if (!hasMediaDirectory && |
| + entry.name.toUpperCase() in importer.ValidImportRoots_) { |
| + hasMediaDirectory = true; |
| + } |
| + }) |
| + .then( |
| + function() { |
| + return hasMediaDirectory; |
| + }); |
| +}; |
| + |
| +/** |
| * @return {!Promise<boolean>} Resolves with true when Cloud Import feature |
| * is enabled. |
| */ |
| @@ -329,7 +351,7 @@ importer.getUnownedHistoryFiles_ = function(machineId) { |
| .then( |
| /** @param {!DirectoryEntry} root */ |
| function(root) { |
| - return fileOperationUtil.listEntries( |
| + return importer.listEntries_( |
| root, |
| /** @param {Entry} entry */ |
| function(entry) { |
| @@ -375,6 +397,37 @@ importer.getHistoryFiles = function() { |
| }; |
| /** |
| + * Calls {@code callback} for each child entry of {@code directory}. |
| + * |
| + * @param {!DirectoryEntry} directory |
| + * @param {function(!Entry)} callback |
| + * @return {!Promise} Resolves when listing is complete. |
| + * @private |
| + */ |
| +importer.listEntries_ = function(directory, callback) { |
| + return new Promise( |
| + function(resolve, reject) { |
| + var reader = directory.createReader(); |
| + |
| + var readEntries = function() { |
| + reader.readEntries ( |
| + /** @param {!Array<!Entry>} entries */ |
| + function(entries) { |
| + if (entries.length === 0) { |
| + resolve(undefined); |
| + return; |
| + } |
| + entries.forEach(callback); |
|
mtomasz
2015/03/24 01:34:58
nit: I think this should cause a js compile error,
Steve McKay
2015/03/24 22:39:20
Callback is required, all others are optional.
|
| + readEntries(); |
| + }, |
| + reject); |
| + }; |
| + |
| + readEntries(); |
| + }); |
| +}; |
| + |
| +/** |
| * A Promise wrapper that provides public access to resolve and reject methods. |
| * |
| * @constructor |