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

Unified Diff: ui/file_manager/file_manager/background/js/volume_manager.js

Issue 858563005: Immediately open MTP and other eligible removable devices with media directory on mount. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to review comments. Created 5 years, 11 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
Index: ui/file_manager/file_manager/background/js/volume_manager.js
diff --git a/ui/file_manager/file_manager/background/js/volume_manager.js b/ui/file_manager/file_manager/background/js/volume_manager.js
index 329527a4d6ed61d7671219994a9c5630f96eebc7..660ec4dab53c75834ad6b56e89ffb1f6a5d03680 100644
--- a/ui/file_manager/file_manager/background/js/volume_manager.js
+++ b/ui/file_manager/file_manager/background/js/volume_manager.js
@@ -46,6 +46,8 @@ function VolumeInfo(
this.displayRoot_ = null;
this.fakeEntries_ = {};
this.displayRoot_ = null;
+
+ /** @type {Promise.<DirectoryEntry>} */
this.displayRootPromise_ = null;
if (volumeType === VolumeManagerCommon.VolumeType.DRIVE) {
@@ -168,7 +170,7 @@ VolumeInfo.prototype = /** @struct */ {
* @param {function(DirectoryEntry)=} opt_onSuccess Success callback with the
* display root directory as an argument.
* @param {function(*)=} opt_onFailure Failure callback.
- * @return {Promise}
+ * @return {Promise.<DirectoryEntry>}
*/
VolumeInfo.prototype.resolveDisplayRoot = function(opt_onSuccess,
opt_onFailure) {
@@ -177,9 +179,11 @@ VolumeInfo.prototype.resolveDisplayRoot = function(opt_onSuccess,
// remove this if logic. Call opt_onSuccess() always, instead.
if (this.volumeType !== VolumeManagerCommon.VolumeType.DRIVE) {
if (this.fileSystem_)
- this.displayRootPromise_ = Promise.resolve(this.fileSystem_.root);
+ this.displayRootPromise_ = /** @type {Promise.<DirectoryEntry>} */ (
+ Promise.resolve(this.fileSystem_.root));
else
- this.displayRootPromise_ = Promise.reject(this.error);
+ this.displayRootPromise_ = /** @type {Promise.<DirectoryEntry>} */ (
+ Promise.reject(this.error));
} else {
// For Drive, we need to resolve.
var displayRootURL = this.fileSystem_.root.toURL() + '/root';
@@ -351,6 +355,9 @@ function VolumeInfoList() {
(volumeManagerUtil.compareVolumeInfo_));
this.model_.sort(field, 'asc');
+ /** @private {!Object.<string, !importer.Resolver.<!VolumeInfo>>} */
+ this.volumeInfoResolvers_ = {};
+
Object.freeze(this);
}
@@ -387,6 +394,14 @@ VolumeInfoList.prototype.add = function(volumeInfo) {
this.model_.splice(index, 1, volumeInfo);
else
this.model_.push(volumeInfo);
+
+ // Some folks might be expecting this volume to be initialized soon.
+ // In that case there'll be a resolver function (associated with a promise)
+ // waiting for us here.
+ var resolver = this.volumeInfoResolvers_[volumeInfo.volumeId];
+ if (resolver) {
+ resolver.resolve(volumeInfo);
+ }
};
/**
@@ -397,6 +412,9 @@ VolumeInfoList.prototype.remove = function(volumeId) {
var index = this.findIndex(volumeId);
if (index !== -1)
this.model_.splice(index, 1);
+
+ // Remove any associated resolvers.
+ delete this.volumeInfoResolvers_[volumeId];
};
/**
@@ -451,6 +469,43 @@ VolumeInfoList.prototype.findByDevicePath = function(devicePath) {
};
/**
+ * Returns a VolumInfo for the volume ID, or null if not found.
+ *
+ * @param {string} volumeId
+ * @return {VolumeInfo} The volume's information, or null if not found.
+ * @private
+ */
+VolumeInfoList.prototype.findByVolumeId_ = function(volumeId) {
+ var index = this.findIndex(volumeId);
+ return (index !== -1) ?
+ /** @type {VolumeInfo} */ (this.model_.item(index)) :
+ null;
+};
+
+/**
+ * Returns a promise that will be resolved when volume info, identified
+ * by {@code volumeId} is created.
+ *
+ * @param {string} volumeId
+ * @return {!Promise.<!VolumeInfo>} The VolumeInfo. Will not resolve
+ * if the volume is never mounted.
+ */
+VolumeInfoList.prototype.whenVolumeInfoReady = function(volumeId) {
+ var info = this.findByVolumeId_(volumeId);
+ if (!!info) {
+ return Promise.resolve(info);
+ }
+
+ var resolver = this.volumeInfoResolvers_[volumeId];
+ if (!resolver) {
+ resolver = new importer.Resolver();
+ this.volumeInfoResolvers_[volumeId] = resolver;
+ }
+
+ return resolver.promise;
+};
+
+/**
* @param {number} index The index of the volume in the list.
* @return {!VolumeInfo} The VolumeInfo instance.
*/

Powered by Google App Engine
This is Rietveld 408576698