// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-'use strict';
-
/**
* Represents each volume, such as "drive", "download directory", each "USB
* flush storage", or "mounted zip archive" etc.
*
* @param {VolumeManagerCommon.VolumeType} volumeType The type of the volume.
* @param {string} volumeId ID of the volume.
- * @param {DOMFileSystem} fileSystem The file system object for this volume.
- * @param {string} error The error if an error is found.
- * @param {?string} deviceType The type of device ('usb'|'sd'|'optical'|'mobile'
- * |'unknown') (as defined in chromeos/disks/disk_mount_manager.cc).
- * Can be null.
- * @param {?string} devicePath Identifier of the device that the volume belongs
- * to. Can be null.
+ * @param {FileSystem} fileSystem The file system object for this volume.
+ * @param {(string|undefined)} error The error if an error is found.
+ * @param {(string|undefined)} deviceType The type of device
+ * ('usb'|'sd'|'optical'|'mobile'|'unknown') (as defined in
+ * chromeos/disks/disk_mount_manager.cc). Can be undefined.
+ * @param {(string|undefined)} devicePath Identifier of the device that the
+ * volume belongs to. Can be undefined.
* @param {boolean} isReadOnly True if the volume is read only.
* @param {!{displayName:string, isCurrentProfile:boolean}} profile Profile
* information.
* @param {string} label Label of the volume.
- * @param {string} extensionId Id of the extension providing this volume. Empty
- * for native volumes.
+ * @param {(string|undefined)} extensionId Id of the extension providing this
+ * volume. Empty for native volumes.
* @constructor
*/
function VolumeInfo(
return this.volumeId_;
},
/**
- * @return {DOMFileSystem} File system object.
+ * @return {FileSystem} File system object.
*/
get fileSystem() {
return this.fileSystem_;
return this.fakeEntries_;
},
/**
- * @return {string} Error identifier.
+ * @return {(string|undefined)} Error identifier.
*/
get error() {
return this.error_;
},
/**
- * @return {string} Device type identifier.
+ * @return {(string|undefined)} Device type identifier.
*/
get deviceType() {
return this.deviceType_;
},
/**
- * @return {string} Device identifier.
+ * @return {(string|undefined)} Device identifier.
*/
get devicePath() {
return this.devicePath_;
return this.label_;
},
/**
- * @return {string} Id of an extennsion providing this volume.
+ * @return {(string|undefined)} Id of an extennsion providing this volume.
*/
get extensionId() {
return this.extensionId_;
* Starts resolving the display root and obtains it. It may take long time for
* Drive. Once resolved, it is cached.
*
- * @param {function(DirectoryEntry)} onSuccess Success callback with the
+ * @param {function(DirectoryEntry)=} opt_onSuccess Success callback with the
* display root directory as an argument.
- * @param {function(FileError)} onFailure Failure callback.
+ * @param {function(*)=} opt_onFailure Failure callback.
* @return {Promise}
*/
-VolumeInfo.prototype.resolveDisplayRoot = function(onSuccess, onFailure) {
+VolumeInfo.prototype.resolveDisplayRoot = function(opt_onSuccess,
+ opt_onFailure) {
if (!this.displayRootPromise_) {
// TODO(mtomasz): Do not add VolumeInfo which failed to resolve root, and
- // remove this if logic. Call onSuccess() always, instead.
+ // 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);
// For Drive, we need to resolve.
var displayRootURL = this.fileSystem_.root.toURL() + '/root';
this.displayRootPromise_ = new Promise(
- webkitResolveLocalFileSystemURL.bind(null, displayRootURL));
+ window.webkitResolveLocalFileSystemURL.bind(null, displayRootURL));
}
// Store the obtained displayRoot.
this.displayRoot_ = displayRoot;
}.bind(this));
}
- if (onSuccess)
- this.displayRootPromise_.then(onSuccess, onFailure);
+ if (opt_onSuccess)
+ this.displayRootPromise_.then(opt_onSuccess, opt_onFailure);
return this.displayRootPromise_;
};
* Throws an Error when the given error is not in
* VolumeManagerCommon.VolumeError.
*
- * @param {VolumeManagerCommon.VolumeError} error Status string usually received
- * from APIs.
+ * @param {string} error Status string usually received from APIs.
*/
volumeManagerUtil.validateError = function(error) {
for (var key in VolumeManagerCommon.VolumeError) {
if (!fileSystem) {
console.error('File system not found: ' + volumeMetadata.volumeId);
callback(new VolumeInfo(
- volumeMetadata.volumeType,
+ /** @type {VolumeManagerCommon.VolumeType} */
+ (volumeMetadata.volumeType),
volumeMetadata.volumeId,
null, // File system is not found.
volumeMetadata.mountCondition,
});
}
callback(new VolumeInfo(
- volumeMetadata.volumeType,
+ /** @type {VolumeManagerCommon.VolumeType} */
+ (volumeMetadata.volumeType),
volumeMetadata.volumeId,
fileSystem,
volumeMetadata.mountCondition,
* The volumes at first are compared by volume type in the order of
* volumeListOrder_. Then they are compared by volume ID.
*
- * @param {VolumeInfo} volumeInfo1 Volume info to be compared.
- * @param {VolumeInfo} volumeInfo2 Volume info to be compared.
+ * @param {!VolumeInfo} volumeInfo1 Volume info to be compared.
+ * @param {!VolumeInfo} volumeInfo2 Volume info to be compared.
* @return {number} Returns -1 if volume1 < volume2, returns 1 if volume2 >
* volume1, returns 0 if volume1 === volume2.
* @private
* @private
*/
this.model_ = new cr.ui.ArrayDataModel([]);
- this.model_.setCompareFunction(field, volumeManagerUtil.compareVolumeInfo_);
+ this.model_.setCompareFunction(field,
+ /** @type {function(*, *): number} */
+ (volumeManagerUtil.compareVolumeInfo_));
this.model_.sort(field, 'asc');
Object.freeze(this);
/**
* @param {number} index The index of the volume in the list.
- * @return {VolumeInfo} The VolumeInfo instance.
+ * @return {!VolumeInfo} The VolumeInfo instance.
*/
VolumeInfoList.prototype.item = function(index) {
- return this.model_.item(index);
+ return /** @type {!VolumeInfo} */ (this.model_.item(index));
};
/**
// The status should be merged into VolumeManager.
// TODO(hidehiko): Remove them after the migration.
+ /**
+ * Connection state of the Drive.
+ * @type {VolumeManagerCommon.DriveConnectionState}
+ * @private
+ */
this.driveConnectionState_ = {
type: VolumeManagerCommon.DriveConnectionType.OFFLINE,
- reason: VolumeManagerCommon.DriveConnectionReason.NO_SERVICE
+ reason: VolumeManagerCommon.DriveConnectionReason.NO_SERVICE,
+ hasCellularNetworkAccess: false
};
chrome.fileManagerPrivate.onDriveConnectionStatusChanged.addListener(
/**
* Invoked when the drive connection status is changed.
- * @private_
+ * @private
*/
VolumeManager.prototype.onDriveConnectionStatusChanged_ = function() {
chrome.fileManagerPrivate.getDriveConnectionState(function(state) {
/**
* Returns the drive connection state.
- * @return {VolumeManagerCommon.DriveConnectionType} Connection type.
+ * @return {VolumeManagerCommon.DriveConnectionState} Connection state.
*/
VolumeManager.prototype.getDriveConnectionState = function() {
return this.driveConnectionState_;
VolumeManager.TIMEOUT = 15 * 60 * 1000;
/**
- * Queue to run getInstance sequentially.
- * @type {AsyncUtil.Queue}
- * @private
- */
-VolumeManager.getInstanceQueue_ = new AsyncUtil.Queue();
-
-/**
* The singleton instance of VolumeManager. Initialized by the first invocation
* of getInstance().
* @type {VolumeManager}
VolumeManager.instance_ = null;
/**
+ * Returns instance of VolumeManager for debug purpose.
+ * This method returns VolumeManager.instance_ which may not be initialized.
+ *
+ * @return {VolumeManager} Volume manager.
+ */
+VolumeManager.getInstanceForDebug = function() {
+ return VolumeManager.instance_;
+};
+
+/**
* @type {Promise}
* @private
*/
/**
* Returns the VolumeManager instance asynchronously. If it is not created or
* under initialization, it will waits for the finish of the initialization.
- * @param {function(VolumeManager)} callback Called with the VolumeManager
+ * @param {function(VolumeManager)=} opt_callback Called with the VolumeManager
* instance. TODO(hirono): Remove the callback and use Promise instead.
* @return {Promise} Promise to be fulfilled with the volume manager.
*/
-VolumeManager.getInstance = function(callback) {
+VolumeManager.getInstance = function(opt_callback) {
if (!VolumeManager.instancePromise_) {
VolumeManager.instance_ = new VolumeManager();
VolumeManager.instancePromise_ = new Promise(function(fulfill) {
});
});
}
- if (callback)
- VolumeManager.instancePromise_.then(callback);
+ if (opt_callback)
+ VolumeManager.instancePromise_.then(opt_callback);
return VolumeManager.instancePromise_;
};
/**
+ * Revokes the singleton instance for testing.
+ */
+VolumeManager.revokeInstanceForTesting = function() {
+ VolumeManager.instancePromise_ = null;
+ VolumeManager.instance_ = null;
+}
+
+/**
* Initializes mount points.
* @param {function()} callback Called upon the completion of the
* initialization.
/**
* @param {string} key Key produced by |makeRequestKey_|.
- * @param {VolumeManagerCommon.VolumeError|'success'} status Status received
+ * @param {VolumeManagerCommon.VolumeError|string} status Status received
* from the API.
* @param {VolumeInfo=} opt_volumeInfo Volume info of the mounted volume.
* @private
};
/**
+ * Returns current state of VolumeManager.
+ * @return {string} Current state of VolumeManager.
+ */
+VolumeManager.prototype.toString = function() {
+ return 'VolumeManager\n' +
+ '- MountQueue_:\n' +
+ ' ' + this.mountQueue_.toString().replace(/\n/g, '\n ');
+};
+
+/**
* Location information which shows where the path points in FileManager's
* file system.
*