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

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

Issue 778123006: Include MTP devices in Cloud Import happiness. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test files missing from CL. Created 6 years 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
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 ea6faa2a75434a4b01675b081b757e1764ddfb25..82e165b6172fc3192591aab966e03f78a5d2ebd9 100644
--- a/ui/file_manager/file_manager/common/js/importer_common.js
+++ b/ui/file_manager/file_manager/common/js/importer_common.js
@@ -6,6 +6,15 @@
var importer = importer || {};
/**
+ * Volume types eligible for the affections of Cloud Import.
+ * @private @const {!Array.<!VolumeManagerCommon.VolumeType>}
+ */
+importer.ELIGIBLE_VOLUME_TYPES_ = [
+ VolumeManagerCommon.VolumeType.MTP,
+ VolumeManagerCommon.VolumeType.REMOVABLE
+];
+
+/**
* @enum {string}
*/
importer.Destination = {
@@ -13,6 +22,30 @@ importer.Destination = {
};
/**
+ * Returns true if the entry is a media file (and a descendant of a DCIM dir).
+ *
+ * @param {Entry} entry
+ * @return {boolean}
+ */
+importer.isMediaEntry = function(entry) {
+ return !!entry &&
+ entry.isFile &&
+ FileType.isImageOrVideo(entry) &&
+ entry.fullPath.toUpperCase().indexOf('/DCIM/') === 0;
+};
+
+/**
+ * Returns true if the volume is eligible for Cloud Import.
+ *
+ * @param {VolumeInfo} volumeInfo
+ * @return {boolean}
+ */
+importer.isEligibleVolume = function(volumeInfo) {
+ return !!volumeInfo &&
+ importer.ELIGIBLE_VOLUME_TYPES_.indexOf(volumeInfo.volumeType) !== -1;
+};
+
+/**
* Returns true if the entry is cloud import eligible.
*
* @param {VolumeManagerCommon.VolumeInfoProvider} volumeInfoProvider
@@ -20,20 +53,17 @@ importer.Destination = {
* @return {boolean}
*/
importer.isEligibleEntry = function(volumeInfoProvider, entry) {
- assert(volumeInfoProvider != null);
- if (entry && entry.isFile && FileType.isImageOrVideo(entry)) {
+ console.assert(volumeInfoProvider != null);
+ if (importer.isMediaEntry(entry)) {
var volumeInfo = volumeInfoProvider.getVolumeInfo(entry);
- if (volumeInfo &&
- volumeInfo.volumeType == VolumeManagerCommon.VolumeType.REMOVABLE) {
- return entry.fullPath.indexOf('/DCIM/') === 0;
- }
+ return importer.isEligibleVolume(volumeInfo);
}
return false;
};
/**
* Returns true if the entry represents a media directory for the purposes
- * of cloud import.
+ * of Cloud Import.
*
* @param {Entry} entry
* @param {VolumeManagerCommon.VolumeInfoProvider} volumeInfoProvider
@@ -44,15 +74,14 @@ importer.isMediaDirectory = function(entry, volumeInfoProvider) {
return false;
}
- if (entry.fullPath !== '/DCIM') {
+ var fullPath = entry.fullPath.toUpperCase();
+ if (fullPath !== '/DCIM' && fullPath != '/DCIM/') {
return false;
}
- assert(volumeInfoProvider != null);
+ console.assert(volumeInfoProvider !== null);
var volumeInfo = volumeInfoProvider.getVolumeInfo(entry);
- return !!volumeInfo &&
- volumeInfo.isType(VolumeManagerCommon.VolumeType.REMOVABLE) &&
- volumeInfo.hasMedia;
+ return importer.isEligibleVolume(volumeInfo);
};
/**
@@ -60,15 +89,11 @@ importer.isMediaDirectory = function(entry, volumeInfoProvider) {
* is enabled.
*/
importer.importEnabled = function() {
- // TODO(smckay): Also verify that Drive is enabled and we're
- // not running in guest mode.
return new Promise(
function(resolve, reject) {
chrome.commandLinePrivate.hasSwitch(
'enable-cloud-backup',
- /**
- * @param {boolean} enabled
- */
+ /** @param {boolean} enabled */
function(enabled) {
importer.lastKnownImportEnabled = enabled;
resolve(enabled);

Powered by Google App Engine
This is Rietveld 408576698