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

Unified Diff: ui/file_manager/file_manager/common/js/importer_common.js

Issue 1022423005: Move view change analytics tracking into DirectoryModel where implementation details can be hidden. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add FSP extension whitelist so we can report names to analytics rather than extension ids for provi… Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/file_manager/file_manager/common/js/importer_common_unittest.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8e9cd7252137c7bf990a72755a41e773c56e4c9f..47e300c417dbe9d58bfe176f2904e287e3528dda 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,75 @@ importer.isMediaDirectory = function(entry, volumeInfoProvider) {
};
/**
+ * @param {!DirectoryEntry} directory Presumably the root of a filesystem.
+ * @return {!Promise<boolean>} True if the directory contains a
+ * child media directory (like 'DCIM').
+ */
+importer.hasMediaDirectory = function(directory) {
+ /**
+ * @param {boolean} answer
+ * @return {boolean}
+ */
+ var isTrue = function(answer) {
+ return answer;
+ };
+ var dirNames = Object.keys(importer.ValidImportRoots_);
+ return Promise.all(dirNames.map(importer.hasDirectory_.bind(null, directory)))
+ .then(
+ /**
+ * @param {!Array<boolean>} results
+ * @return {!Promise<boolean>}
+ */
+ function(results) {
+ if (results.some(isTrue)) {
+ return Promise.resolve(true);
+ } else {
+ // If standard (upper case) forms are not present,
+ // check for a lower-case "DCIM".
+ return importer.hasDirectory_(directory, 'dcim');
+ }
+ });
+};
+
+/**
+ * @param {!DirectoryEntry} parent
+ * @param {string} name
+ * @return {!Promise<boolean>} True if parent contains a directory
+ * with the specified name.
+ * @private
+ */
+importer.hasDirectory_ = function(parent, name) {
+ return importer.getDirectory_(parent, name)
+ .then(
+ function() {
+ return true;
+ },
+ function() {
+ return false;
+ });
+};
+
+/**
+ * @param {!DirectoryEntry} parent
+ * @param {string} name
+ * @return {!Promise<!DirectoryEntry>}
+ * @private
+ */
+importer.getDirectory_ = function(parent, name) {
+ return new Promise(
+ function(resolve, reject) {
+ parent.getDirectory(
+ name,
+ {
+ create: false,
+ exclusive: false
+ },
+ resolve,
+ reject);
+ });
+};
+
+/**
* @return {!Promise<boolean>} Resolves with true when Cloud Import feature
* is enabled.
*/
@@ -329,7 +398,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 +444,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);
+ readEntries();
+ },
+ reject);
+ };
+
+ readEntries();
+ });
+};
+
+/**
* A Promise wrapper that provides public access to resolve and reject methods.
*
* @constructor
@@ -665,7 +765,6 @@ importer.ChromeSyncFilesystem.getOrCreateFileEntry = function(fileNamePromise) {
resolve,
reject);
});
-
});
});
« no previous file with comments | « no previous file | ui/file_manager/file_manager/common/js/importer_common_unittest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698