Commit e45d066b authored by François Degros's avatar François Degros Committed by Commit Bot

[Files app] ES6 class for volume_manager.js and volume_info.js

Added property isReadOnlyRemovableDevice to interface VolumeInfo.

Added method dispose() to interface VolumeManager, since it is called by
Gallery.onPageHide_(). Added dummy implementation of dispose() to
VolumeManagerImpl and MockVolumeManager. FilteredVolumeManager already has a
dispose() implementation.

Made VolumeManagerImpl.initialize() public since it is called by
volumeManagerFactory.getInstance().


Bug: 778674
Change-Id: I978caaa79579fb8ea1f04fa207fe5c304e163a1b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1614771
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Auto-Submit: François Degros <fdegros@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660747}
parent 119284a1
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
* The inner list ownership is shared between FilteredVolumeInfoList and * The inner list ownership is shared between FilteredVolumeInfoList and
* FilteredVolumeManager to enforce these constraints. * FilteredVolumeManager to enforce these constraints.
* *
* @final
* @implements {VolumeInfoList} * @implements {VolumeInfoList}
*/ */
class FilteredVolumeInfoList { class FilteredVolumeInfoList {
...@@ -16,29 +17,35 @@ class FilteredVolumeInfoList { ...@@ -16,29 +17,35 @@ class FilteredVolumeInfoList {
* @param {!cr.ui.ArrayDataModel} list * @param {!cr.ui.ArrayDataModel} list
*/ */
constructor(list) { constructor(list) {
/** @private */ /** @private @const */
this.list_ = list; this.list_ = list;
} }
/** @override */ /** @override */
get length() { get length() {
return this.list_.length; return this.list_.length;
} }
/** @override */ /** @override */
addEventListener(type, handler) { addEventListener(type, handler) {
this.list_.addEventListener(type, handler); this.list_.addEventListener(type, handler);
} }
/** @override */ /** @override */
removeEventListener(type, handler) { removeEventListener(type, handler) {
this.list_.removeEventListener(type, handler); this.list_.removeEventListener(type, handler);
} }
/** @override */ /** @override */
add(volumeInfo) { add(volumeInfo) {
throw new Error('FilteredVolumeInfoList.add not allowed in foreground'); throw new Error('FilteredVolumeInfoList.add not allowed in foreground');
} }
/** @override */ /** @override */
remove(volumeInfo) { remove(volumeInfo) {
throw new Error('FilteredVolumeInfoList.remove not allowed in foreground'); throw new Error('FilteredVolumeInfoList.remove not allowed in foreground');
} }
/** @override */ /** @override */
item(index) { item(index) {
return /** @type {!VolumeInfo} */ (this.list_.item(index)); return /** @type {!VolumeInfo} */ (this.list_.item(index));
......
...@@ -7,131 +7,137 @@ ...@@ -7,131 +7,137 @@
* flush storage", or "mounted zip archive" etc. * flush storage", or "mounted zip archive" etc.
* @interface * @interface
*/ */
function VolumeInfo() {} class VolumeInfo {
constructor() {
/** @type {VolumeManagerCommon.VolumeType} */
this.volumeType;
/** @type {VolumeManagerCommon.VolumeType} */ /** @type {string} */
VolumeInfo.prototype.volumeType; this.volumeId;
/** @type {string} */ /** @type {FileSystem} */
VolumeInfo.prototype.volumeId; this.fileSystem;
/** @type {FileSystem} */ /**
VolumeInfo.prototype.fileSystem;
/**
* Display root path. It is null before finishing to resolve the entry. * Display root path. It is null before finishing to resolve the entry.
* @type {DirectoryEntry} * @type {DirectoryEntry}
*/ */
VolumeInfo.prototype.displayRoot; this.displayRoot;
/** /**
* The display root path of Shared Drives directory. It is null before finishing * The display root path of Shared Drives directory. It is null before
* to resolve the entry. Valid only for Drive volume. * finishing to resolve the entry. Valid only for Drive volume.
* @type {DirectoryEntry} * @type {DirectoryEntry}
*/ */
VolumeInfo.prototype.sharedDriveDisplayRoot; this.sharedDriveDisplayRoot;
/** /**
* The display root path of Computers directory. It is null before finishing * The display root path of Computers directory. It is null before finishing
* to resolve the entry. Valid only for Drive volume. * to resolve the entry. Valid only for Drive volume.
* @type {DirectoryEntry} * @type {DirectoryEntry}
*/ */
VolumeInfo.prototype.computersDisplayRoot; this.computersDisplayRoot;
/** /**
* The volume's fake entries such as Recent, Offline, Shared with me, etc... * The volume's fake entries such as Recent, Offline, Shared with me, etc...
* in Google Drive. * in Google Drive.
* @type {Object<!FakeEntry>}} * @type {Object<!FakeEntry>}}
*/ */
VolumeInfo.prototype.fakeEntries; this.fakeEntries;
/** /**
* This represents if the mounting of the volume is successfully done or not. * This represents if the mounting of the volume is successfully done or
* (If error is empty string, the mount is successfully done) * not. (If error is empty string, the mount is successfully done)
* @type {(string|undefined)} * @type {(string|undefined)}
*/ */
VolumeInfo.prototype.error; this.error;
/** /**
* The type of device. (e.g. USB, SD card, DVD etc.) * The type of device. (e.g. USB, SD card, DVD etc.)
* @type {(string|undefined)} * @type {(string|undefined)}
*/ */
VolumeInfo.prototype.deviceType; this.deviceType;
/** /**
* If the volume is removable, devicePath is the path of the system device this * If the volume is removable, devicePath is the path of the system device
* device's block is a part of. (e.g. /sys/devices/pci0000:00/.../8:0:0:0/) * this device's block is a part of. (e.g.
* Otherwise, this should be empty. * /sys/devices/pci0000:00/.../8:0:0:0/) Otherwise, this should be empty.
* @type {(string|undefined)} * @type {(string|undefined)}
*/ */
VolumeInfo.prototype.devicePath; this.devicePath;
/** @type {boolean} */ /** @type {boolean} */
VolumeInfo.prototype.isReadOnly; this.isReadOnly;
/** @type {!{displayName:string, isCurrentProfile:boolean}} */ /**
VolumeInfo.prototype.profile; * @type {boolean} Whether the device is read-only removable device or not.
*/
this.isReadOnlyRemovableDevice;
/** /** @type {!{displayName:string, isCurrentProfile:boolean}} */
this.profile;
/**
* Label for the volume if the volume is either removable or a provided file * Label for the volume if the volume is either removable or a provided file
* system. In case of removables, if disk is a parent, then its label, else * system. In case of removables, if disk is a parent, then its label, else
* parent's label (e.g. "TransMemory"). * parent's label (e.g. "TransMemory").
* @type {string} * @type {string}
*/ */
VolumeInfo.prototype.label; this.label;
/** /**
* ID of a provider for this volume. * ID of a provider for this volume.
* @type {(string|undefined)} * @type {(string|undefined)}
*/ */
VolumeInfo.prototype.providerId; this.providerId;
/** /**
* Set of icons for this volume. * Set of icons for this volume.
* @type {!chrome.fileManagerPrivate.IconSet} * @type {!chrome.fileManagerPrivate.IconSet}
*/ */
VolumeInfo.prototype.iconSet; this.iconSet;
/** /**
* True if the volume contains media. * True if the volume contains media.
* @type {boolean} * @type {boolean}
*/ */
VolumeInfo.prototype.hasMedia; this.hasMedia;
/** /**
* True if the volume is configurable. * True if the volume is configurable.
* See https://developer.chrome.com/apps/fileSystemProvider. * See https://developer.chrome.com/apps/fileSystemProvider.
* @type {boolean} * @type {boolean}
*/ */
VolumeInfo.prototype.configurable; this.configurable;
/** /**
* True if the volume notifies about changes via file/directory watchers. * True if the volume notifies about changes via file/directory watchers.
* @type {boolean} * @type {boolean}
*/ */
VolumeInfo.prototype.watchable; this.watchable;
/** @type {VolumeManagerCommon.Source} */ /** @type {VolumeManagerCommon.Source} */
VolumeInfo.prototype.source; this.source;
/** @type {VolumeManagerCommon.FileSystemType} */ /** @type {VolumeManagerCommon.FileSystemType} */
VolumeInfo.prototype.diskFileSystemType; this.diskFileSystemType;
/** /**
* @type {FilesAppEntry} an entry to be used as prefix of this volume on * @type {FilesAppEntry} an entry to be used as prefix of this volume on
* breadcrumbs, e.g. "My Files > Downloads", "My Files" is a prefixEntry on * breadcrumbs, e.g. "My Files > Downloads", "My Files" is a prefixEntry
* "Downloads" VolumeInfo. * on "Downloads" VolumeInfo.
*/ */
VolumeInfo.prototype.prefixEntry; this.prefixEntry;
}
/** /**
* Starts resolving the display root and obtains it. It may take long time for * Starts resolving the display root and obtains it. It may take long time
* Drive. Once resolved, it is cached. * for Drive. Once resolved, it is cached.
* *
* @param {function(!DirectoryEntry)=} opt_onSuccess Success callback with the * @param {function(!DirectoryEntry)=} opt_onSuccess Success callback with the
* display root directory as an argument. * display root directory as an argument.
* @param {function(*)=} opt_onFailure Failure callback. * @param {function(*)=} opt_onFailure Failure callback.
* @return {!Promise<!DirectoryEntry>} * @return {!Promise<!DirectoryEntry>}
*/ */
VolumeInfo.prototype.resolveDisplayRoot = function( resolveDisplayRoot(opt_onSuccess, opt_onFailure) {}
opt_onSuccess, opt_onFailure) {}; }
...@@ -6,40 +6,42 @@ ...@@ -6,40 +6,42 @@
* The container of the VolumeInfo for each mounted volume. * The container of the VolumeInfo for each mounted volume.
* @interface * @interface
*/ */
function VolumeInfoList() {} class VolumeInfoList {
constructor() {
/** @const {number} */
VolumeInfoList.prototype.length;
}
/** @type {number} */ /**
VolumeInfoList.prototype.length;
/**
* Adds the event listener to listen the change of volume info. * Adds the event listener to listen the change of volume info.
* @param {string} type The name of the event. * @param {string} type The name of the event.
* @param {function(Event)} handler The handler for the event. * @param {function(Event)} handler The handler for the event.
*/ */
VolumeInfoList.prototype.addEventListener = function(type, handler) {}; addEventListener(type, handler) {}
/** /**
* Removes the event listener. * Removes the event listener.
* @param {string} type The name of the event. * @param {string} type The name of the event.
* @param {function(Event)} handler The handler to be removed. * @param {function(Event)} handler The handler to be removed.
*/ */
VolumeInfoList.prototype.removeEventListener = function(type, handler) {}; removeEventListener(type, handler) {}
/** /**
* Adds the volumeInfo to the appropriate position. If there already exists, * Adds the volumeInfo to the appropriate position. If there already exists,
* just replaces it. * just replaces it.
* @param {VolumeInfo} volumeInfo The information of the new volume. * @param {VolumeInfo} volumeInfo The information of the new volume.
*/ */
VolumeInfoList.prototype.add = function(volumeInfo) {}; add(volumeInfo) {}
/** /**
* Removes the VolumeInfo having the given ID. * Removes the VolumeInfo having the given ID.
* @param {string} volumeId ID of the volume. * @param {string} volumeId ID of the volume.
*/ */
VolumeInfoList.prototype.remove = function(volumeId) {}; remove(volumeId) {}
/** /**
* @param {number} index The index of the volume in the list. * @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) {}; item(index) {}
}
...@@ -6,104 +6,110 @@ ...@@ -6,104 +6,110 @@
* VolumeManager is responsible for tracking list of mounted volumes. * VolumeManager is responsible for tracking list of mounted volumes.
* @interface * @interface
*/ */
function VolumeManager() {} class VolumeManager {
constructor() {
/** /**
* The list of VolumeInfo instances for each mounted volume. * The list of VolumeInfo instances for each mounted volume.
* @type {VolumeInfoList} * @type {VolumeInfoList}
*/ */
VolumeManager.prototype.volumeInfoList; this.volumeInfoList;
}
/** /**
* Disposes the instance. After the invocation of this method, any other
* method should not be called.
*/
dispose() {}
/**
* Obtains a volume info containing the passed entry. * Obtains a volume info containing the passed entry.
* @param {!Entry|!FilesAppEntry} entry Entry on the volume to be * @param {!Entry|!FilesAppEntry} entry Entry on the volume to be
* returned. Can be fake. * returned. Can be fake.
* @return {VolumeInfo} The VolumeInfo instance or null if not found. * @return {VolumeInfo} The VolumeInfo instance or null if not found.
*/ */
VolumeManager.prototype.getVolumeInfo; getVolumeInfo(entry) {}
/** /**
* Returns the drive connection state. * Returns the drive connection state.
* @return {VolumeManagerCommon.DriveConnectionState} Connection state. * @return {VolumeManagerCommon.DriveConnectionState} Connection state.
*/ */
VolumeManager.prototype.getDriveConnectionState = function() {}; getDriveConnectionState() {}
/** /**
* @param {string} fileUrl File url to the archive file. * @param {string} fileUrl File url to the archive file.
* @param {function(VolumeInfo)} successCallback Success callback. * @param {function(VolumeInfo)} successCallback Success callback.
* @param {function(VolumeManagerCommon.VolumeError)} errorCallback Error * @param {function(VolumeManagerCommon.VolumeError)} errorCallback Error
* callback. * callback.
*/ */
VolumeManager.prototype.mountArchive = mountArchive(fileUrl, successCallback, errorCallback) {}
function(fileUrl, successCallback, errorCallback) {};
/** /**
* Unmounts a volume. * Unmounts a volume.
* @param {!VolumeInfo} volumeInfo Volume to be unmounted. * @param {!VolumeInfo} volumeInfo Volume to be unmounted.
* @param {function()} successCallback Success callback. * @param {function()} successCallback Success callback.
* @param {function(VolumeManagerCommon.VolumeError)} errorCallback Error * @param {function(VolumeManagerCommon.VolumeError)} errorCallback Error
* callback. * callback.
*/ */
VolumeManager.prototype.unmount = unmount(volumeInfo, successCallback, errorCallback) {}
function(volumeInfo, successCallback, errorCallback) {};
/** /**
* Configures a volume. * Configures a volume.
* @param {!VolumeInfo} volumeInfo Volume to be configured. * @param {!VolumeInfo} volumeInfo Volume to be configured.
* @return {!Promise} Fulfilled on success, otherwise rejected with an error * @return {!Promise} Fulfilled on success, otherwise rejected with an error
* message. * message.
*/ */
VolumeManager.prototype.configure = function(volumeInfo) {}; configure(volumeInfo) {}
/** /**
* Obtains volume information of the current profile. * Obtains volume information of the current profile.
* *
* @param {VolumeManagerCommon.VolumeType} volumeType Volume type. * @param {VolumeManagerCommon.VolumeType} volumeType Volume type.
* @return {VolumeInfo} Volume info. * @return {VolumeInfo} Volume info.
*/ */
VolumeManager.prototype.getCurrentProfileVolumeInfo = function(volumeType) {}; getCurrentProfileVolumeInfo(volumeType) {}
/** /**
* Obtains location information from an entry. * Obtains location information from an entry.
* *
* @param {!Entry|!FilesAppEntry} entry File or directory entry. It * @param {!Entry|!FilesAppEntry} entry File or directory entry. It
* can be a fake entry. * can be a fake entry.
* @return {EntryLocation} Location information. * @return {EntryLocation} Location information.
*/ */
VolumeManager.prototype.getLocationInfo = function(entry) {}; getLocationInfo(entry) {}
/** /**
* Adds an event listener to the target. * Adds an event listener to the target.
* @param {string} type The name of the event. * @param {string} type The name of the event.
* @param {function(!Event)} handler The handler for the event. This is * @param {function(!Event)} handler The handler for the event. This is
* called when the event is dispatched. * called when the event is dispatched.
*/ */
VolumeManager.prototype.addEventListener = function(type, handler) {}; addEventListener(type, handler) {}
/** /**
* Removes an event listener from the target. * Removes an event listener from the target.
* @param {string} type The name of the event. * @param {string} type The name of the event.
* @param {function(!Event)} handler The handler for the event. * @param {function(!Event)} handler The handler for the event.
*/ */
VolumeManager.prototype.removeEventListener = function(type, handler) {}; removeEventListener(type, handler) {}
/** /**
* Dispatches an event and calls all the listeners that are listening to * Dispatches an event and calls all the listeners that are listening to
* the type of the event. * the type of the event.
* @param {!Event} event The event to dispatch. * @param {!Event} event The event to dispatch.
* @return {boolean} Whether the default action was prevented. If someone * @return {boolean} Whether the default action was prevented. If someone
* calls preventDefault on the event object then this returns false. * calls preventDefault on the event object then this returns false.
*/ */
VolumeManager.prototype.dispatchEvent = function(event) {}; dispatchEvent(event) {}
/** /**
* Searches the information of the volume that exists on the given device path. * Searches the information of the volume that exists on the given device
* path.
* @param {string} devicePath Path of the device to search. * @param {string} devicePath Path of the device to search.
* @return {VolumeInfo} The volume's information, or null if not found. * @return {VolumeInfo} The volume's information, or null if not found.
*/ */
VolumeManager.prototype.findByDevicePath = function(devicePath) {}; findByDevicePath(devicePath) {}
/** /**
* Returns a promise that will be resolved when volume info, identified * Returns a promise that will be resolved when volume info, identified
* by {@code volumeId} is created. * by {@code volumeId} is created.
* *
...@@ -111,14 +117,15 @@ VolumeManager.prototype.findByDevicePath = function(devicePath) {}; ...@@ -111,14 +117,15 @@ VolumeManager.prototype.findByDevicePath = function(devicePath) {};
* @return {!Promise<!VolumeInfo>} The VolumeInfo. Will not resolve * @return {!Promise<!VolumeInfo>} The VolumeInfo. Will not resolve
* if the volume is never mounted. * if the volume is never mounted.
*/ */
VolumeManager.prototype.whenVolumeInfoReady = function(volumeId) {}; whenVolumeInfoReady(volumeId) {}
/** /**
* Obtains the default display root entry. * Obtains the default display root entry.
* @param {function(DirectoryEntry)|function(FilesAppDirEntry)} callback * @param {function(DirectoryEntry)|function(FilesAppDirEntry)} callback
* Callback passed the default display root. * Callback passed the default display root.
*/ */
VolumeManager.prototype.getDefaultDisplayRoot = function(callback) {}; getDefaultDisplayRoot(callback) {}
}
/** /**
* Event object which is dispached with 'externally-unmounted' event. * Event object which is dispached with 'externally-unmounted' event.
......
...@@ -4,18 +4,23 @@ ...@@ -4,18 +4,23 @@
/** /**
* Mock class for VolumeManager. * Mock class for VolumeManager.
* @constructor * @final
* @implements {VolumeManager} * @implements {VolumeManager}
*/ */
function MockVolumeManager() { class MockVolumeManager {
constructor() {
/** @const {!VolumeInfoList} */
this.volumeInfoList = new VolumeInfoListImpl(); this.volumeInfoList = new VolumeInfoListImpl();
/** @type {!VolumeManagerCommon.DriveConnectionState} */
this.driveConnectionState = { this.driveConnectionState = {
type: VolumeManagerCommon.DriveConnectionType.ONLINE type: VolumeManagerCommon.DriveConnectionType.ONLINE
}; };
// Create Drive. Drive attempts to resolve FilesSystemURLs for '/root', // Create Drive. Drive attempts to resolve FilesSystemURLs for '/root',
// '/team_drives' and '/Computers' during initialization. Create a filesystem // '/team_drives' and '/Computers' during initialization. Create a
// with those entries now, and mock webkitResolveLocalFileSystemURL. // filesystem with those entries now, and mock
// webkitResolveLocalFileSystemURL.
const driveFs = new MockFileSystem( const driveFs = new MockFileSystem(
VolumeManagerCommon.VolumeType.DRIVE, VolumeManagerCommon.VolumeType.DRIVE,
'filesystem:' + VolumeManagerCommon.VolumeType.DRIVE); 'filesystem:' + VolumeManagerCommon.VolumeType.DRIVE);
...@@ -37,8 +42,8 @@ function MockVolumeManager() { ...@@ -37,8 +42,8 @@ function MockVolumeManager() {
// Create Drive, swap entries back in, revert window.webkitResolve. // Create Drive, swap entries back in, revert window.webkitResolve.
const drive = this.createVolumeInfo( const drive = this.createVolumeInfo(
VolumeManagerCommon.VolumeType.DRIVE, VolumeManagerCommon.RootType.DRIVE, VolumeManagerCommon.VolumeType.DRIVE,
str('DRIVE_DIRECTORY_LABEL')); VolumeManagerCommon.RootType.DRIVE, str('DRIVE_DIRECTORY_LABEL'));
/** @type {MockFileSystem} */ (drive.fileSystem) /** @type {MockFileSystem} */ (drive.fileSystem)
.populate(Object.values(driveFs.entries)); .populate(Object.values(driveFs.entries));
window.webkitResolveLocalFileSystmeURL = orig; window.webkitResolveLocalFileSystmeURL = orig;
...@@ -46,27 +51,26 @@ function MockVolumeManager() { ...@@ -46,27 +51,26 @@ function MockVolumeManager() {
// Create Downloads. // Create Downloads.
this.createVolumeInfo( this.createVolumeInfo(
VolumeManagerCommon.VolumeType.DOWNLOADS, VolumeManagerCommon.VolumeType.DOWNLOADS,
VolumeManagerCommon.RootType.DOWNLOADS, str('DOWNLOADS_DIRECTORY_LABEL')); VolumeManagerCommon.RootType.DOWNLOADS,
} str('DOWNLOADS_DIRECTORY_LABEL'));
}
/** /** @override */
* @private {?VolumeManager} dispose() {}
*/
MockVolumeManager.instance_ = null;
/** /**
* Replaces the VolumeManager singleton with a MockVolumeManager. * Replaces the VolumeManager singleton with a MockVolumeManager.
* @param {!MockVolumeManager=} opt_singleton * @param {!MockVolumeManager=} opt_singleton
*/ */
MockVolumeManager.installMockSingleton = opt_singleton => { static installMockSingleton(opt_singleton) {
MockVolumeManager.instance_ = opt_singleton || new MockVolumeManager(); MockVolumeManager.instance_ = opt_singleton || new MockVolumeManager();
volumeManagerFactory.getInstance = () => { volumeManagerFactory.getInstance = () => {
return Promise.resolve(MockVolumeManager.instance_); return Promise.resolve(MockVolumeManager.instance_);
}; };
}; }
/** /**
* Creates, installs and returns a mock VolumeInfo instance. * Creates, installs and returns a mock VolumeInfo instance.
* *
* @param {!VolumeManagerCommon.VolumeType} type * @param {!VolumeManagerCommon.VolumeType} type
...@@ -76,35 +80,25 @@ MockVolumeManager.installMockSingleton = opt_singleton => { ...@@ -76,35 +80,25 @@ MockVolumeManager.installMockSingleton = opt_singleton => {
* *
* @return {!VolumeInfo} * @return {!VolumeInfo}
*/ */
MockVolumeManager.prototype.createVolumeInfo = function( createVolumeInfo(type, volumeId, label, providerId) {
type, volumeId, label, providerId) {
const volumeInfo = MockVolumeManager.createMockVolumeInfo( const volumeInfo = MockVolumeManager.createMockVolumeInfo(
type, volumeId, label, undefined, providerId); type, volumeId, label, undefined, providerId);
this.volumeInfoList.add(volumeInfo); this.volumeInfoList.add(volumeInfo);
return volumeInfo; return volumeInfo;
}; }
/** @override */
MockVolumeManager.prototype.getVolumeInfo =
VolumeManagerImpl.prototype.getVolumeInfo;
/** @override */
MockVolumeManager.prototype.getDefaultDisplayRoot =
VolumeManagerImpl.prototype.getDefaultDisplayRoot;
/** /**
* Obtains location information from an entry. * Obtains location information from an entry.
* Current implementation can handle only fake entries. * Current implementation can handle only fake entries.
* *
* @param {!Entry|!FilesAppEntry} entry A fake entry. * @param {!Entry|!FilesAppEntry} entry A fake entry.
* @return {EntryLocation} Location information. * @return {!EntryLocation} Location information.
*/ */
MockVolumeManager.prototype.getLocationInfo = function(entry) { getLocationInfo(entry) {
if (util.isFakeEntry(entry)) { if (util.isFakeEntry(entry)) {
return new EntryLocationImpl( return new EntryLocationImpl(
this.volumeInfoList.item(0), /** @type {!FakeEntry} */ (entry).rootType, this.volumeInfoList.item(0),
true, true); /** @type {!FakeEntry} */ (entry).rootType, true, true);
} }
if (entry.filesystem.name === VolumeManagerCommon.VolumeType.DRIVE) { if (entry.filesystem.name === VolumeManagerCommon.VolumeType.DRIVE) {
...@@ -136,21 +130,13 @@ MockVolumeManager.prototype.getLocationInfo = function(entry) { ...@@ -136,21 +130,13 @@ MockVolumeManager.prototype.getLocationInfo = function(entry) {
VolumeManagerCommon.getRootTypeFromVolumeType(volumeInfo.volumeType); VolumeManagerCommon.getRootTypeFromVolumeType(volumeInfo.volumeType);
isRootEntry = util.isSameEntry(entry, volumeInfo.fileSystem.root); isRootEntry = util.isSameEntry(entry, volumeInfo.fileSystem.root);
return new EntryLocationImpl(volumeInfo, rootType, isRootEntry, false); return new EntryLocationImpl(volumeInfo, rootType, isRootEntry, false);
}; }
/** @override */
MockVolumeManager.prototype.findByDevicePath =
VolumeManagerImpl.prototype.findByDevicePath;
/** @override */
MockVolumeManager.prototype.whenVolumeInfoReady =
VolumeManagerImpl.prototype.whenVolumeInfoReady;
/** /**
* @param {VolumeManagerCommon.VolumeType} volumeType Volume type. * @param {VolumeManagerCommon.VolumeType} volumeType Volume type.
* @return {VolumeInfo} Volume info. * @return {?VolumeInfo} Volume info.
*/ */
MockVolumeManager.prototype.getCurrentProfileVolumeInfo = function(volumeType) { getCurrentProfileVolumeInfo(volumeType) {
for (let i = 0; i < this.volumeInfoList.length; i++) { for (let i = 0; i < this.volumeInfoList.length; i++) {
const volumeInfo = this.volumeInfoList.item(i); const volumeInfo = this.volumeInfoList.item(i);
if (volumeInfo.profile.isCurrentProfile && if (volumeInfo.profile.isCurrentProfile &&
...@@ -159,17 +145,17 @@ MockVolumeManager.prototype.getCurrentProfileVolumeInfo = function(volumeType) { ...@@ -159,17 +145,17 @@ MockVolumeManager.prototype.getCurrentProfileVolumeInfo = function(volumeType) {
} }
} }
return null; return null;
}; }
/** /**
* @return {VolumeManagerCommon.DriveConnectionState} Current drive connection * @return {!VolumeManagerCommon.DriveConnectionState} Current drive
* state. * connection state.
*/ */
MockVolumeManager.prototype.getDriveConnectionState = function() { getDriveConnectionState() {
return this.driveConnectionState; return this.driveConnectionState;
}; }
/** /**
* Utility function to create a mock VolumeInfo. * Utility function to create a mock VolumeInfo.
* @param {!VolumeManagerCommon.VolumeType} type Volume type. * @param {!VolumeManagerCommon.VolumeType} type Volume type.
* @param {string} volumeId Volume id. * @param {string} volumeId Volume id.
...@@ -178,8 +164,7 @@ MockVolumeManager.prototype.getDriveConnectionState = function() { ...@@ -178,8 +164,7 @@ MockVolumeManager.prototype.getDriveConnectionState = function() {
* @param {string=} providerId Provider id. * @param {string=} providerId Provider id.
* @return {!VolumeInfo} Created mock VolumeInfo. * @return {!VolumeInfo} Created mock VolumeInfo.
*/ */
MockVolumeManager.createMockVolumeInfo = static createMockVolumeInfo(type, volumeId, label, devicePath, providerId) {
(type, volumeId, label, devicePath, providerId) => {
const fileSystem = new MockFileSystem(volumeId, 'filesystem:' + volumeId); const fileSystem = new MockFileSystem(volumeId, 'filesystem:' + volumeId);
// If there's no label set it to volumeId to make it shorter to write // If there's no label set it to volumeId to make it shorter to write
...@@ -203,25 +188,49 @@ MockVolumeManager.createMockVolumeInfo = ...@@ -203,25 +188,49 @@ MockVolumeManager.createMockVolumeInfo =
''); // driveLabel ''); // driveLabel
return volumeInfo; return volumeInfo;
}; }
MockVolumeManager.prototype.mountArchive = mountArchive(fileUrl, successCallback, errorCallback) {
(fileUrl, successCallback, errorCallback) => { throw new Error('Not implemented');
throw new Error('Not implemented.'); }
};
MockVolumeManager.prototype.unmount = unmount(volumeInfo, successCallback, errorCallback) {
(volumeInfo, successCallback, errorCallback) => { throw new Error('Not implemented');
throw new Error('Not implemented.'); }
};
MockVolumeManager.prototype.configure = volumeInfo => { configure(volumeInfo) {
throw new Error('Not implemented.'); throw new Error('Not implemented');
}; }
MockVolumeManager.prototype.addEventListener = (type, handler) => {
throw new Error('Not implemented.'); addEventListener(type, handler) {
}; throw new Error('Not implemented');
MockVolumeManager.prototype.removeEventListener = (type, handler) => { }
throw new Error('Not implemented.');
}; removeEventListener(type, handler) {
MockVolumeManager.prototype.dispatchEvent = event => { throw new Error('Not implemented');
throw new Error('Not implemented.'); }
};
dispatchEvent(event) {
throw new Error('Not implemented');
}
}
/** @private {?VolumeManager} */
MockVolumeManager.instance_ = null;
/** @override */
MockVolumeManager.prototype.getVolumeInfo =
VolumeManagerImpl.prototype.getVolumeInfo;
/** @override */
MockVolumeManager.prototype.getDefaultDisplayRoot =
VolumeManagerImpl.prototype.getDefaultDisplayRoot;
/** @override */
MockVolumeManager.prototype.findByDevicePath =
VolumeManagerImpl.prototype.findByDevicePath;
/** @override */
MockVolumeManager.prototype.whenVolumeInfoReady =
VolumeManagerImpl.prototype.whenVolumeInfoReady;
...@@ -6,10 +6,11 @@ ...@@ -6,10 +6,11 @@
* Represents each volume, such as "drive", "download directory", each "USB * Represents each volume, such as "drive", "download directory", each "USB
* flush storage", or "mounted zip archive" etc. * flush storage", or "mounted zip archive" etc.
* *
* @constructor * @final
* @implements {VolumeInfo} * @implements {VolumeInfo}
* @struct */
* class VolumeInfoImpl {
/**
* @param {VolumeManagerCommon.VolumeType} volumeType The type of the volume. * @param {VolumeManagerCommon.VolumeType} volumeType The type of the volume.
* @param {string} volumeId ID of the volume. * @param {string} volumeId ID of the volume.
* @param {FileSystem} fileSystem The file system object for this volume. * @param {FileSystem} fileSystem The file system object for this volume.
...@@ -33,16 +34,18 @@ ...@@ -33,16 +34,18 @@
* @param {boolean} watchable When true, then the volume can be watched. * @param {boolean} watchable When true, then the volume can be watched.
* @param {VolumeManagerCommon.Source} source Source of the volume's data. * @param {VolumeManagerCommon.Source} source Source of the volume's data.
* @param {VolumeManagerCommon.FileSystemType} diskFileSystemType File system * @param {VolumeManagerCommon.FileSystemType} diskFileSystemType File system
* type indentifier. * type identifier.
* @param {!chrome.fileManagerPrivate.IconSet} iconSet Set of icons for this * @param {!chrome.fileManagerPrivate.IconSet} iconSet Set of icons for this
* volume. * volume.
* @param {(string|undefined)} driveLabel Drive label of the volume. Removable * @param {(string|undefined)} driveLabel Drive label of the volume. Removable
* partitions belonging to the same device will share the same drive label. * partitions belonging to the same device will share the same drive
* label.
*/ */
function VolumeInfoImpl( constructor(
volumeType, volumeId, fileSystem, error, deviceType, devicePath, isReadOnly, volumeType, volumeId, fileSystem, error, deviceType, devicePath,
isReadOnlyRemovableDevice, profile, label, providerId, hasMedia, isReadOnly, isReadOnlyRemovableDevice, profile, label, providerId,
configurable, watchable, source, diskFileSystemType, iconSet, driveLabel) { hasMedia, configurable, watchable, source, diskFileSystemType, iconSet,
driveLabel) {
this.volumeType_ = volumeType; this.volumeType_ = volumeType;
this.volumeId_ = volumeId; this.volumeId_ = volumeId;
this.fileSystem_ = fileSystem; this.fileSystem_ = fileSystem;
...@@ -52,13 +55,13 @@ function VolumeInfoImpl( ...@@ -52,13 +55,13 @@ function VolumeInfoImpl(
this.computersDisplayRoot_ = null; this.computersDisplayRoot_ = null;
/** /**
* @type {FilesAppEntry} an entry to be used as prefix of this volume on * @private {?FilesAppEntry} an entry to be used as prefix of this volume on
* breadcrumbs, e.g. "My Files > Downloads", "My Files" is a prefixEntry * breadcrumbs, e.g. "My Files > Downloads", "My Files" is a prefixEntry
* on "Downloads" VolumeInfo. * on "Downloads" VolumeInfo.
*/ */
this.prefixEntry_ = null; this.prefixEntry_ = null;
/** @type {Object<!FakeEntry>} */ /** @private @const {!Object<!FakeEntry>} */
this.fakeEntries_ = {}; this.fakeEntries_ = {};
if (volumeType === VolumeManagerCommon.VolumeType.DRIVE) { if (volumeType === VolumeManagerCommon.VolumeType.DRIVE) {
...@@ -91,36 +94,39 @@ function VolumeInfoImpl( ...@@ -91,36 +94,39 @@ function VolumeInfoImpl(
this.iconSet_ = iconSet; this.iconSet_ = iconSet;
this.driveLabel_ = driveLabel; this.driveLabel_ = driveLabel;
/** @type {Promise<!DirectoryEntry>} */ /** @private @const {Promise<!DirectoryEntry>} */
this.displayRootPromise_ = this.resolveDisplayRootImpl_(); this.displayRootPromise_ = this.resolveDisplayRootImpl_();
} }
VolumeInfoImpl.prototype = /** @struct */ {
/** /**
* @return {VolumeManagerCommon.VolumeType} Volume type. * @return {VolumeManagerCommon.VolumeType} Volume type.
*/ */
get volumeType() { get volumeType() {
return this.volumeType_; return this.volumeType_;
}, }
/** /**
* @return {string} Volume ID. * @return {string} Volume ID.
*/ */
get volumeId() { get volumeId() {
return this.volumeId_; return this.volumeId_;
}, }
/** /**
* @return {FileSystem} File system object. * @return {FileSystem} File system object.
*/ */
get fileSystem() { get fileSystem() {
return this.fileSystem_; return this.fileSystem_;
}, }
/** /**
* @return {DirectoryEntry} Display root path. It is null before finishing to * @return {DirectoryEntry} Display root path. It is null before finishing to
* resolve the entry. * resolve the entry.
*/ */
get displayRoot() { get displayRoot() {
return this.displayRoot_; return this.displayRoot_;
}, }
/** /**
* @return {DirectoryEntry} The display root path of Shared Drives directory. * @return {DirectoryEntry} The display root path of Shared Drives directory.
* It is null before finishing to resolve the entry. Valid only for Drive * It is null before finishing to resolve the entry. Valid only for Drive
...@@ -128,7 +134,8 @@ VolumeInfoImpl.prototype = /** @struct */ { ...@@ -128,7 +134,8 @@ VolumeInfoImpl.prototype = /** @struct */ {
*/ */
get sharedDriveDisplayRoot() { get sharedDriveDisplayRoot() {
return this.sharedDriveDisplayRoot_; return this.sharedDriveDisplayRoot_;
}, }
/** /**
* @return {DirectoryEntry} The display root path of Computers directory. * @return {DirectoryEntry} The display root path of Computers directory.
* It is null before finishing to resolve the entry. Valid only for Drive * It is null before finishing to resolve the entry. Valid only for Drive
...@@ -136,97 +143,113 @@ VolumeInfoImpl.prototype = /** @struct */ { ...@@ -136,97 +143,113 @@ VolumeInfoImpl.prototype = /** @struct */ {
*/ */
get computersDisplayRoot() { get computersDisplayRoot() {
return this.computersDisplayRoot_; return this.computersDisplayRoot_;
}, }
/** /**
* @return {Object<!FakeEntry>} Fake entries. * @return {Object<!FakeEntry>} Fake entries.
*/ */
get fakeEntries() { get fakeEntries() {
return this.fakeEntries_; return this.fakeEntries_;
}, }
/** /**
* @return {(string|undefined)} Error identifier. * @return {(string|undefined)} Error identifier.
*/ */
get error() { get error() {
return this.error_; return this.error_;
}, }
/** /**
* @return {(string|undefined)} Device type identifier. * @return {(string|undefined)} Device type identifier.
*/ */
get deviceType() { get deviceType() {
return this.deviceType_; return this.deviceType_;
}, }
/** /**
* @return {(string|undefined)} Device identifier. * @return {(string|undefined)} Device identifier.
*/ */
get devicePath() { get devicePath() {
return this.devicePath_; return this.devicePath_;
}, }
/** /**
* @return {boolean} Whether read only or not. * @return {boolean} Whether read only or not.
*/ */
get isReadOnly() { get isReadOnly() {
return this.isReadOnly_; return this.isReadOnly_;
}, }
/** /**
* @return {boolean} Whether the device is read-only removable device or not. * @return {boolean} Whether the device is read-only removable device or not.
*/ */
get isReadOnlyRemovableDevice() { get isReadOnlyRemovableDevice() {
return this.isReadOnlyRemovableDevice_; return this.isReadOnlyRemovableDevice_;
}, }
/** /**
* @return {!{displayName:string, isCurrentProfile:boolean}} Profile data. * @return {!{displayName:string, isCurrentProfile:boolean}} Profile data.
*/ */
get profile() { get profile() {
return this.profile_; return this.profile_;
}, }
/** /**
* @return {string} Label for the volume. * @return {string} Label for the volume.
*/ */
get label() { get label() {
return this.label_; return this.label_;
}, }
/** /**
* @return {(string|undefined)} Id of a provider for this volume. * @return {(string|undefined)} Id of a provider for this volume.
*/ */
get providerId() { get providerId() {
return this.providerId_; return this.providerId_;
}, }
/** /**
* @return {boolean} True if the volume contains media. * @return {boolean} True if the volume contains media.
*/ */
get hasMedia() { get hasMedia() {
return this.hasMedia_; return this.hasMedia_;
}, }
/** /**
* @return {boolean} True if the volume is configurable. * @return {boolean} True if the volume is configurable.
*/ */
get configurable() { get configurable() {
return this.configurable_; return this.configurable_;
}, }
/** /**
* @return {boolean} True if the volume is watchable. * @return {boolean} True if the volume is watchable.
*/ */
get watchable() { get watchable() {
return this.watchable_; return this.watchable_;
}, }
/** /**
* @return {VolumeManagerCommon.Source} Source of the volume's data. * @return {VolumeManagerCommon.Source} Source of the volume's data.
*/ */
get source() { get source() {
return this.source_; return this.source_;
}, }
/** /**
* @return {VolumeManagerCommon.FileSystemType} File system type identifier. * @return {VolumeManagerCommon.FileSystemType} File system type identifier.
*/ */
get diskFileSystemType() { get diskFileSystemType() {
return this.diskFileSystemType_; return this.diskFileSystemType_;
}, }
/** /**
* @return {chrome.fileManagerPrivate.IconSet} Set of icons for this volume. * @return {chrome.fileManagerPrivate.IconSet} Set of icons for this volume.
*/ */
get iconSet() { get iconSet() {
return this.iconSet_; return this.iconSet_;
}, }
/** /**
* @return {(string|undefined)} Drive label for the volume. Removable * @return {(string|undefined)} Drive label for the volume. Removable
* partitions belonging to the same physical media device will share the * partitions belonging to the same physical media device will share the
...@@ -234,7 +257,8 @@ VolumeInfoImpl.prototype = /** @struct */ { ...@@ -234,7 +257,8 @@ VolumeInfoImpl.prototype = /** @struct */ {
*/ */
get driveLabel() { get driveLabel() {
return this.driveLabel_; return this.driveLabel_;
}, }
/** /**
* @type {FilesAppEntry} an entry to be used as prefix of this volume on * @type {FilesAppEntry} an entry to be used as prefix of this volume on
* breadcrumbs, e.g. "My Files > Downloads", "My Files" is a prefixEntry * breadcrumbs, e.g. "My Files > Downloads", "My Files" is a prefixEntry
...@@ -242,28 +266,29 @@ VolumeInfoImpl.prototype = /** @struct */ { ...@@ -242,28 +266,29 @@ VolumeInfoImpl.prototype = /** @struct */ {
*/ */
get prefixEntry() { get prefixEntry() {
return this.prefixEntry_; return this.prefixEntry_;
}, }
set prefixEntry(entry) { set prefixEntry(entry) {
this.prefixEntry_ = entry; this.prefixEntry_ = entry;
}, }
};
/** /**
* Returns a promise to the entry for the given URL * Returns a promise to the entry for the given URL
* @param {string} url The filesystem URL * @param {string} url The filesystem URL
* @return {!Promise<Entry>} * @return {!Promise<Entry>}
* @private
*/ */
VolumeInfoImpl.resolveFileSystemUrl_ = url => { static resolveFileSystemUrl_(url) {
return new Promise(window.webkitResolveLocalFileSystemURL.bind(null, url)); return new Promise(window.webkitResolveLocalFileSystemURL.bind(null, url));
}; }
/** /**
* Sets |sharedDriveDisplayRoot_| if team drives are enabled. * Sets |sharedDriveDisplayRoot_| if team drives are enabled.
* *
* The return value will resolve once this operation is complete. * The return value will resolve once this operation is complete.
* @return {!Promise<void>} * @return {!Promise<void>}
*/ */
VolumeInfoImpl.prototype.resolveSharedDrivesRoot_ = function() { resolveSharedDrivesRoot_() {
return VolumeInfoImpl return VolumeInfoImpl
.resolveFileSystemUrl_( .resolveFileSystemUrl_(
this.fileSystem_.root.toURL() + this.fileSystem_.root.toURL() +
...@@ -277,18 +302,19 @@ VolumeInfoImpl.prototype.resolveSharedDrivesRoot_ = function() { ...@@ -277,18 +302,19 @@ VolumeInfoImpl.prototype.resolveSharedDrivesRoot_ = function() {
throw error; throw error;
} }
}); });
}; }
/** /**
* Sets |computersDisplayRoot_| if Computers are enabled. * Sets |computersDisplayRoot_| if Computers are enabled.
* *
* If Computers are not enabled, resolveFileSystemUrl_ will return a * If Computers are not enabled, resolveFileSystemUrl_ will return a
* 'NotFoundError' which will be caught here. Any other errors will be rethrown. * 'NotFoundError' which will be caught here. Any other errors will be
* rethrown.
* *
* The return value will resolve once this operation is complete. * The return value will resolve once this operation is complete.
* @return {!Promise<void>} * @return {!Promise<void>}
*/ */
VolumeInfoImpl.prototype.resolveComputersRoot_ = function() { resolveComputersRoot_() {
return VolumeInfoImpl return VolumeInfoImpl
.resolveFileSystemUrl_( .resolveFileSystemUrl_(
this.fileSystem_.root.toURL() + this.fileSystem_.root.toURL() +
...@@ -302,13 +328,13 @@ VolumeInfoImpl.prototype.resolveComputersRoot_ = function() { ...@@ -302,13 +328,13 @@ VolumeInfoImpl.prototype.resolveComputersRoot_ = function() {
throw error; throw error;
} }
}); });
}; }
/** /**
* Returns a promise that resolves when the display root is resolved. * Returns a promise that resolves when the display root is resolved.
* @return {Promise<!DirectoryEntry>} Volume type. * @return {Promise<!DirectoryEntry>} Volume type.
*/ */
VolumeInfoImpl.prototype.resolveDisplayRootImpl_ = function() { resolveDisplayRootImpl_() {
// TODO(mtomasz): Do not add VolumeInfo which failed to resolve root, and // TODO(mtomasz): Do not add VolumeInfo which failed to resolve root, and
// remove this if logic. // remove this if logic.
if (this.volumeType !== VolumeManagerCommon.VolumeType.DRIVE) { if (this.volumeType !== VolumeManagerCommon.VolumeType.DRIVE) {
...@@ -332,15 +358,15 @@ VolumeInfoImpl.prototype.resolveDisplayRootImpl_ = function() { ...@@ -332,15 +358,15 @@ VolumeInfoImpl.prototype.resolveDisplayRootImpl_ = function() {
this.displayRoot_ = displayRoot; this.displayRoot_ = displayRoot;
return displayRoot; return displayRoot;
}); });
}; }
/** /**
* @override * @override
*/ */
VolumeInfoImpl.prototype.resolveDisplayRoot = function( resolveDisplayRoot(opt_onSuccess, opt_onFailure) {
opt_onSuccess, opt_onFailure) {
if (opt_onSuccess) { if (opt_onSuccess) {
this.displayRootPromise_.then(opt_onSuccess, opt_onFailure); this.displayRootPromise_.then(opt_onSuccess, opt_onFailure);
} }
return assert(this.displayRootPromise_); return assert(this.displayRootPromise_);
}; }
}
...@@ -4,68 +4,67 @@ ...@@ -4,68 +4,67 @@
/** /**
* The container of the VolumeInfo for each mounted volume. * The container of the VolumeInfo for each mounted volume.
* @constructor * @final
* @implements {VolumeInfoList} * @implements {VolumeInfoList}
*/ */
function VolumeInfoListImpl() { class VolumeInfoListImpl {
constructor() {
/** /**
* Holds VolumeInfo instances. * Holds VolumeInfo instances.
* @type {cr.ui.ArrayDataModel} * @private @const {cr.ui.ArrayDataModel}
* @private
*/ */
this.model_ = new cr.ui.ArrayDataModel([]); this.model_ = new cr.ui.ArrayDataModel([]);
Object.freeze(this); Object.freeze(this);
} }
VolumeInfoListImpl.prototype = {
get length() { get length() {
return this.model_.length; return this.model_.length;
} }
};
/** @override */ /** @override */
VolumeInfoListImpl.prototype.addEventListener = function(type, handler) { addEventListener(type, handler) {
this.model_.addEventListener(type, handler); this.model_.addEventListener(type, handler);
}; }
/** @override */ /** @override */
VolumeInfoListImpl.prototype.removeEventListener = function(type, handler) { removeEventListener(type, handler) {
this.model_.removeEventListener(type, handler); this.model_.removeEventListener(type, handler);
}; }
/** @override */ /** @override */
VolumeInfoListImpl.prototype.add = function(volumeInfo) { add(volumeInfo) {
const index = this.findIndex(volumeInfo.volumeId); const index = this.findIndex(volumeInfo.volumeId);
if (index !== -1) { if (index !== -1) {
this.model_.splice(index, 1, volumeInfo); this.model_.splice(index, 1, volumeInfo);
} else { } else {
this.model_.push(volumeInfo); this.model_.push(volumeInfo);
} }
}; }
/** @override */ /** @override */
VolumeInfoListImpl.prototype.remove = function(volumeId) { remove(volumeId) {
const index = this.findIndex(volumeId); const index = this.findIndex(volumeId);
if (index !== -1) { if (index !== -1) {
this.model_.splice(index, 1); this.model_.splice(index, 1);
} }
}; }
/** @override */ /** @override */
VolumeInfoListImpl.prototype.item = function(index) { item(index) {
return /** @type {!VolumeInfo} */ (this.model_.item(index)); return /** @type {!VolumeInfo} */ (this.model_.item(index));
}; }
/** /**
* Obtains an index from the volume ID. * Obtains an index from the volume ID.
* @param {string} volumeId Volume ID. * @param {string} volumeId Volume ID.
* @return {number} Index of the volume. * @return {number} Index of the volume.
*/ */
VolumeInfoListImpl.prototype.findIndex = function(volumeId) { findIndex(volumeId) {
for (let i = 0; i < this.model_.length; i++) { for (let i = 0; i < this.model_.length; i++) {
if (this.model_.item(i).volumeId === volumeId) { if (this.model_.item(i).volumeId === volumeId) {
return i; return i;
} }
} }
return -1; return -1;
}; }
}
...@@ -6,12 +6,12 @@ var volumeManagerFactory = (() => { ...@@ -6,12 +6,12 @@ var volumeManagerFactory = (() => {
/** /**
* The singleton instance of VolumeManager. Initialized by the first * The singleton instance of VolumeManager. Initialized by the first
* invocation of getInstance(). * invocation of getInstance().
* @type {VolumeManager} * @type {?VolumeManagerImpl}
*/ */
let instance = null; let instance = null;
/** /**
* @type {Promise} * @type {?Promise<!VolumeManager>}
*/ */
let instancePromise = null; let instancePromise = null;
...@@ -22,16 +22,14 @@ var volumeManagerFactory = (() => { ...@@ -22,16 +22,14 @@ var volumeManagerFactory = (() => {
* @param {function(VolumeManager)=} opt_callback Called with the * @param {function(VolumeManager)=} opt_callback Called with the
* VolumeManager instance. TODO(hirono): Remove the callback and use * VolumeManager instance. TODO(hirono): Remove the callback and use
* Promise instead. * Promise instead.
* @return {Promise} Promise to be fulfilled with the volume manager. * @return {!Promise<!VolumeManager>} Promise to be fulfilled with the volume
* manager.
*/ */
function getInstance(opt_callback) { function getInstance(opt_callback) {
if (!instancePromise) { if (!instancePromise) {
instance = new VolumeManagerImpl(); instance = new VolumeManagerImpl();
instancePromise = new Promise(fulfill => { instancePromise =
instance.initialize_(() => { new Promise(fulfill => instance.initialize(() => fulfill(instance)));
return fulfill(instance);
});
});
} }
if (opt_callback) { if (opt_callback) {
instancePromise.then(opt_callback); instancePromise.then(opt_callback);
......
...@@ -46,6 +46,9 @@ class VolumeManagerImpl extends cr.EventTarget { ...@@ -46,6 +46,9 @@ class VolumeManagerImpl extends cr.EventTarget {
this.onDriveConnectionStatusChanged_(); this.onDriveConnectionStatusChanged_();
} }
/** @override */
dispose() {}
/** /**
* Invoked when the drive connection status is changed. * Invoked when the drive connection status is changed.
* @private * @private
...@@ -122,9 +125,8 @@ class VolumeManagerImpl extends cr.EventTarget { ...@@ -122,9 +125,8 @@ class VolumeManagerImpl extends cr.EventTarget {
* Initializes mount points. * Initializes mount points.
* @param {function()} callback Called upon the completion of the * @param {function()} callback Called upon the completion of the
* initialization. * initialization.
* @private
*/ */
initialize_(callback) { initialize(callback) {
chrome.fileManagerPrivate.onMountCompleted.addListener( chrome.fileManagerPrivate.onMountCompleted.addListener(
this.onMountCompleted_.bind(this)); this.onMountCompleted_.bind(this));
console.warn('Requesting volume list.'); console.warn('Requesting volume list.');
...@@ -277,8 +279,8 @@ class VolumeManagerImpl extends cr.EventTarget { ...@@ -277,8 +279,8 @@ class VolumeManagerImpl extends cr.EventTarget {
return volumeInfo; return volumeInfo;
} }
// Additionally, check fake entries. // Additionally, check fake entries.
for (let key in volumeInfo.fakeEntries_) { for (let key in volumeInfo.fakeEntries) {
const fakeEntry = volumeInfo.fakeEntries_[key]; const fakeEntry = volumeInfo.fakeEntries[key];
if (util.isSameEntry(fakeEntry, entry)) { if (util.isSameEntry(fakeEntry, entry)) {
return volumeInfo; return volumeInfo;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment