1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 * Represents each volume, such as "drive", "download directory", each "USB
9 * flush storage", or "mounted zip archive" etc.
11 * @param {VolumeManagerCommon.VolumeType} volumeType The type of the volume.
12 * @param {string} volumeId ID of the volume.
13 * @param {DOMFileSystem} fileSystem The file system object for this volume.
14 * @param {string} error The error if an error is found.
15 * @param {string} deviceType The type of device ('usb'|'sd'|'optical'|'mobile'
16 * |'unknown') (as defined in chromeos/disks/disk_mount_manager.cc).
18 * @param {boolean} isReadOnly True if the volume is read only.
19 * @param {!{displayName:string, isCurrentProfile:boolean}} profile Profile
21 * @param {string} label Label of the volume.
22 * @param {string} extensionId Id of the extension providing this volume. Empty
36 this.volumeType_ = volumeType;
37 this.volumeId_ = volumeId;
38 this.fileSystem_ = fileSystem;
40 this.displayRoot_ = null;
41 this.fakeEntries_ = {};
42 this.displayRoot_ = null;
43 this.displayRootPromise_ = null;
45 if (volumeType === VolumeManagerCommon.VolumeType.DRIVE) {
46 // TODO(mtomasz): Convert fake entries to DirectoryProvider.
47 this.fakeEntries_[VolumeManagerCommon.RootType.DRIVE_OFFLINE] = {
49 rootType: VolumeManagerCommon.RootType.DRIVE_OFFLINE,
50 toURL: function() { return 'fake-entry://drive_offline'; }
52 this.fakeEntries_[VolumeManagerCommon.RootType.DRIVE_SHARED_WITH_ME] = {
54 rootType: VolumeManagerCommon.RootType.DRIVE_SHARED_WITH_ME,
55 toURL: function() { return 'fake-entry://drive_shared_with_me'; }
57 this.fakeEntries_[VolumeManagerCommon.RootType.DRIVE_RECENT] = {
59 rootType: VolumeManagerCommon.RootType.DRIVE_RECENT,
60 toURL: function() { return 'fake-entry://drive_recent'; }
64 // Note: This represents if the mounting of the volume is successfully done
65 // or not. (If error is empty string, the mount is successfully done).
66 // TODO(hidehiko): Rename to make this more understandable.
68 this.deviceType_ = deviceType;
69 this.isReadOnly_ = isReadOnly;
70 this.profile_ = Object.freeze(profile);
71 this.extensionId_ = extensionId;
76 VolumeInfo.prototype = {
78 * @return {VolumeManagerCommon.VolumeType} Volume type.
81 return this.volumeType_;
84 * @return {string} Volume ID.
87 return this.volumeId_;
90 * @return {DOMFileSystem} File system object.
93 return this.fileSystem_;
96 * @return {DirectoryEntry} Display root path. It is null before finishing to
100 return this.displayRoot_;
103 * @return {Object.<string, Object>} Fake entries.
106 return this.fakeEntries_;
109 * @return {string} Error identifier.
115 * @return {string} Device type identifier.
118 return this.deviceType_;
121 * @return {boolean} Whether read only or not.
124 return this.isReadOnly_;
127 * @return {!{displayName:string, isCurrentProfile:boolean}} Profile data.
130 return this.profile_;
133 * @return {string} Label for the volume.
139 * @return {string} Id of an extennsion providing this volume.
142 return this.extensionId_;
147 * Starts resolving the display root and obtains it. It may take long time for
148 * Drive. Once resolved, it is cached.
150 * @param {function(DirectoryEntry)} onSuccess Success callback with the
151 * display root directory as an argument.
152 * @param {function(FileError)} onFailure Failure callback.
154 VolumeInfo.prototype.resolveDisplayRoot = function(onSuccess, onFailure) {
155 if (!this.displayRootPromise_) {
156 // TODO(mtomasz): Do not add VolumeInfo which failed to resolve root, and
157 // remove this if logic. Call onSuccess() always, instead.
158 if (this.volumeType !== VolumeManagerCommon.VolumeType.DRIVE) {
159 if (this.fileSystem_)
160 this.displayRootPromise_ = Promise.resolve(this.fileSystem_.root);
162 this.displayRootPromise_ = Promise.reject(this.error);
164 // For Drive, we need to resolve.
165 var displayRootURL = this.fileSystem_.root.toURL() + '/root';
166 this.displayRootPromise_ = new Promise(
167 webkitResolveLocalFileSystemURL.bind(null, displayRootURL));
170 // Store the obtained displayRoot.
171 this.displayRootPromise_.then(function(displayRoot) {
172 this.displayRoot_ = displayRoot;
175 this.displayRootPromise_.then(onSuccess, onFailure);
179 * Utilities for volume manager implementation.
181 var volumeManagerUtil = {};
184 * Throws an Error when the given error is not in
185 * VolumeManagerCommon.VolumeError.
187 * @param {VolumeManagerCommon.VolumeError} error Status string usually received
190 volumeManagerUtil.validateError = function(error) {
191 for (var key in VolumeManagerCommon.VolumeError) {
192 if (error === VolumeManagerCommon.VolumeError[key])
196 throw new Error('Invalid mount error: ' + error);
200 * Builds the VolumeInfo data from VolumeMetadata.
201 * @param {VolumeMetadata} volumeMetadata Metadata instance for the volume.
202 * @param {function(VolumeInfo)} callback Called on completion.
204 volumeManagerUtil.createVolumeInfo = function(volumeMetadata, callback) {
206 switch (volumeMetadata.volumeType) {
207 case VolumeManagerCommon.VolumeType.DOWNLOADS:
208 localizedLabel = str('DOWNLOADS_DIRECTORY_LABEL');
210 case VolumeManagerCommon.VolumeType.DRIVE:
211 localizedLabel = str('DRIVE_DIRECTORY_LABEL');
214 // TODO(mtomasz): Calculate volumeLabel for all types of volumes in the
216 localizedLabel = volumeMetadata.volumeLabel ||
217 volumeMetadata.volumeId.split(':', 2)[1];
221 chrome.fileBrowserPrivate.requestFileSystem(
222 volumeMetadata.volumeId,
223 function(fileSystem) {
224 // TODO(mtomasz): chrome.runtime.lastError should have error reason.
226 console.error('File system not found: ' + volumeMetadata.volumeId);
227 callback(new VolumeInfo(
228 volumeMetadata.volumeType,
229 volumeMetadata.volumeId,
230 null, // File system is not found.
231 volumeMetadata.mountCondition,
232 volumeMetadata.deviceType,
233 volumeMetadata.isReadOnly,
234 volumeMetadata.profile,
236 volumeMetadata.extensionId));
239 if (volumeMetadata.volumeType ==
240 VolumeManagerCommon.VolumeType.DRIVE) {
241 // After file system is mounted, we "read" drive grand root
242 // entry at first. This triggers full feed fetch on background.
243 // Note: we don't need to handle errors here, because even if
244 // it fails, accessing to some path later will just become
245 // a fast-fetch and it re-triggers full-feed fetch.
246 fileSystem.root.createReader().readEntries(
247 function() { /* do nothing */ },
250 'Triggering full feed fetch is failed: ' + error.name);
253 callback(new VolumeInfo(
254 volumeMetadata.volumeType,
255 volumeMetadata.volumeId,
257 volumeMetadata.mountCondition,
258 volumeMetadata.deviceType,
259 volumeMetadata.isReadOnly,
260 volumeMetadata.profile,
262 volumeMetadata.extensionId));
267 * The order of the volume list based on root type.
268 * @type {Array.<VolumeManagerCommon.VolumeType>}
272 volumeManagerUtil.volumeListOrder_ = [
273 VolumeManagerCommon.VolumeType.DRIVE,
274 VolumeManagerCommon.VolumeType.DOWNLOADS,
275 VolumeManagerCommon.VolumeType.ARCHIVE,
276 VolumeManagerCommon.VolumeType.REMOVABLE,
277 VolumeManagerCommon.VolumeType.MTP,
278 VolumeManagerCommon.VolumeType.PROVIDED,
279 VolumeManagerCommon.VolumeType.CLOUD_DEVICE
283 * Orders two volumes by volumeType and volumeId.
285 * The volumes at first are compared by volume type in the order of
286 * volumeListOrder_. Then they are compared by volume ID.
288 * @param {VolumeInfo} volumeInfo1 Volume info to be compared.
289 * @param {VolumeInfo} volumeInfo2 Volume info to be compared.
290 * @return {number} Returns -1 if volume1 < volume2, returns 1 if volume2 >
291 * volume1, returns 0 if volume1 === volume2.
294 volumeManagerUtil.compareVolumeInfo_ = function(volumeInfo1, volumeInfo2) {
296 volumeManagerUtil.volumeListOrder_.indexOf(volumeInfo1.volumeType);
298 volumeManagerUtil.volumeListOrder_.indexOf(volumeInfo2.volumeType);
299 if (typeIndex1 !== typeIndex2)
300 return typeIndex1 < typeIndex2 ? -1 : 1;
301 if (volumeInfo1.volumeId !== volumeInfo2.volumeId)
302 return volumeInfo1.volumeId < volumeInfo2.volumeId ? -1 : 1;
307 * The container of the VolumeInfo for each mounted volume.
310 function VolumeInfoList() {
311 var field = 'volumeType,volumeId';
314 * Holds VolumeInfo instances.
315 * @type {cr.ui.ArrayDataModel}
318 this.model_ = new cr.ui.ArrayDataModel([]);
319 this.model_.setCompareFunction(field, volumeManagerUtil.compareVolumeInfo_);
320 this.model_.sort(field, 'asc');
325 VolumeInfoList.prototype = {
326 get length() { return this.model_.length; }
330 * Adds the event listener to listen the change of volume info.
331 * @param {string} type The name of the event.
332 * @param {function(Event)} handler The handler for the event.
334 VolumeInfoList.prototype.addEventListener = function(type, handler) {
335 this.model_.addEventListener(type, handler);
339 * Removes the event listener.
340 * @param {string} type The name of the event.
341 * @param {function(Event)} handler The handler to be removed.
343 VolumeInfoList.prototype.removeEventListener = function(type, handler) {
344 this.model_.removeEventListener(type, handler);
348 * Adds the volumeInfo to the appropriate position. If there already exists,
350 * @param {VolumeInfo} volumeInfo The information of the new volume.
352 VolumeInfoList.prototype.add = function(volumeInfo) {
353 var index = this.findIndex(volumeInfo.volumeId);
355 this.model_.splice(index, 1, volumeInfo);
357 this.model_.push(volumeInfo);
361 * Removes the VolumeInfo having the given ID.
362 * @param {string} volumeId ID of the volume.
364 VolumeInfoList.prototype.remove = function(volumeId) {
365 var index = this.findIndex(volumeId);
367 this.model_.splice(index, 1);
371 * Obtains an index from the volume ID.
372 * @param {string} volumeId Volume ID.
373 * @return {number} Index of the volume.
375 VolumeInfoList.prototype.findIndex = function(volumeId) {
376 for (var i = 0; i < this.model_.length; i++) {
377 if (this.model_.item(i).volumeId === volumeId)
384 * Searches the information of the volume that contains the passed entry.
385 * @param {Entry|Object} entry Entry on the volume to be found.
386 * @return {VolumeInfo} The volume's information, or null if not found.
388 VolumeInfoList.prototype.findByEntry = function(entry) {
389 for (var i = 0; i < this.length; i++) {
390 var volumeInfo = this.item(i);
391 if (volumeInfo.fileSystem &&
392 util.isSameFileSystem(volumeInfo.fileSystem, entry.filesystem)) {
395 // Additionally, check fake entries.
396 for (var key in volumeInfo.fakeEntries_) {
397 var fakeEntry = volumeInfo.fakeEntries_[key];
398 if (util.isSameEntry(fakeEntry, entry))
406 * @param {number} index The index of the volume in the list.
407 * @return {VolumeInfo} The VolumeInfo instance.
409 VolumeInfoList.prototype.item = function(index) {
410 return this.model_.item(index);
414 * VolumeManager is responsible for tracking list of mounted volumes.
417 * @extends {cr.EventTarget}
419 function VolumeManager() {
421 * The list of archives requested to mount. We will show contents once
422 * archive is mounted, but only for mounts from within this filebrowser tab.
423 * @type {Object.<string, Object>}
429 * The list of VolumeInfo instances for each mounted volume.
430 * @type {VolumeInfoList}
432 this.volumeInfoList = new VolumeInfoList();
435 * Queue for mounting.
436 * @type {AsyncUtil.Queue}
439 this.mountQueue_ = new AsyncUtil.Queue();
441 // The status should be merged into VolumeManager.
442 // TODO(hidehiko): Remove them after the migration.
443 this.driveConnectionState_ = {
444 type: VolumeManagerCommon.DriveConnectionType.OFFLINE,
445 reason: VolumeManagerCommon.DriveConnectionReason.NO_SERVICE
448 chrome.fileBrowserPrivate.onDriveConnectionStatusChanged.addListener(
449 this.onDriveConnectionStatusChanged_.bind(this));
450 this.onDriveConnectionStatusChanged_();
454 * Invoked when the drive connection status is changed.
457 VolumeManager.prototype.onDriveConnectionStatusChanged_ = function() {
458 chrome.fileBrowserPrivate.getDriveConnectionState(function(state) {
459 this.driveConnectionState_ = state;
460 cr.dispatchSimpleEvent(this, 'drive-connection-changed');
465 * Returns the drive connection state.
466 * @return {VolumeManagerCommon.DriveConnectionType} Connection type.
468 VolumeManager.prototype.getDriveConnectionState = function() {
469 return this.driveConnectionState_;
473 * VolumeManager extends cr.EventTarget.
475 VolumeManager.prototype.__proto__ = cr.EventTarget.prototype;
478 * Time in milliseconds that we wait a response for. If no response on
479 * mount/unmount received the request supposed failed.
481 VolumeManager.TIMEOUT = 15 * 60 * 1000;
484 * Queue to run getInstance sequentially.
485 * @type {AsyncUtil.Queue}
488 VolumeManager.getInstanceQueue_ = new AsyncUtil.Queue();
491 * The singleton instance of VolumeManager. Initialized by the first invocation
493 * @type {VolumeManager}
496 VolumeManager.instance_ = null;
499 * Returns the VolumeManager instance asynchronously. If it is not created or
500 * under initialization, it will waits for the finish of the initialization.
501 * @param {function(VolumeManager)} callback Called with the VolumeManager
504 VolumeManager.getInstance = function(callback) {
505 VolumeManager.getInstanceQueue_.run(function(continueCallback) {
506 if (VolumeManager.instance_) {
507 callback(VolumeManager.instance_);
512 VolumeManager.instance_ = new VolumeManager();
513 VolumeManager.instance_.initialize_(function() {
514 callback(VolumeManager.instance_);
521 * Initializes mount points.
522 * @param {function()} callback Called upon the completion of the
526 VolumeManager.prototype.initialize_ = function(callback) {
527 chrome.fileBrowserPrivate.getVolumeMetadataList(function(volumeMetadataList) {
528 // We must subscribe to the mount completed event in the callback of
529 // getVolumeMetadataList. crbug.com/330061.
530 // But volumes reported by onMountCompleted events must be added after the
531 // volumes in the volumeMetadataList are mounted. crbug.com/135477.
532 this.mountQueue_.run(function(inCallback) {
533 // Create VolumeInfo for each volume.
534 var group = new AsyncUtil.Group();
535 for (var i = 0; i < volumeMetadataList.length; i++) {
536 group.add(function(volumeMetadata, continueCallback) {
537 volumeManagerUtil.createVolumeInfo(
539 function(volumeInfo) {
540 this.volumeInfoList.add(volumeInfo);
541 if (volumeMetadata.volumeType ===
542 VolumeManagerCommon.VolumeType.DRIVE)
543 this.onDriveConnectionStatusChanged_();
546 }.bind(this, volumeMetadataList[i]));
548 group.run(function() {
549 // Call the callback of the initialize function.
551 // Call the callback of AsyncQueue. Maybe it invokes callbacks
552 // registered by mountCompleted events.
557 chrome.fileBrowserPrivate.onMountCompleted.addListener(
558 this.onMountCompleted_.bind(this));
563 * Event handler called when some volume was mounted or unmounted.
564 * @param {MountCompletedEvent} event Received event.
567 VolumeManager.prototype.onMountCompleted_ = function(event) {
568 this.mountQueue_.run(function(callback) {
569 switch (event.eventType) {
571 var requestKey = this.makeRequestKey_(
573 event.volumeMetadata.sourcePath);
575 var error = event.status === 'success' ? '' : event.status;
576 if (!error || event.status === 'error_unknown_filesystem') {
577 volumeManagerUtil.createVolumeInfo(
578 event.volumeMetadata,
579 function(volumeInfo) {
580 this.volumeInfoList.add(volumeInfo);
581 this.finishRequest_(requestKey, event.status, volumeInfo);
583 if (volumeInfo.volumeType ===
584 VolumeManagerCommon.VolumeType.DRIVE) {
585 // Update the network connection status, because until the
586 // drive is initialized, the status is set to not ready.
587 // TODO(mtomasz): The connection status should be migrated
588 // into VolumeMetadata.
589 this.onDriveConnectionStatusChanged_();
594 console.warn('Failed to mount a volume: ' + event.status);
595 this.finishRequest_(requestKey, event.status);
601 var volumeId = event.volumeMetadata.volumeId;
602 var status = event.status;
603 if (status === VolumeManagerCommon.VolumeError.PATH_UNMOUNTED) {
604 console.warn('Volume already unmounted: ', volumeId);
607 var requestKey = this.makeRequestKey_('unmount', volumeId);
608 var requested = requestKey in this.requests_;
609 var volumeInfoIndex =
610 this.volumeInfoList.findIndex(volumeId);
611 var volumeInfo = volumeInfoIndex !== -1 ?
612 this.volumeInfoList.item(volumeInfoIndex) : null;
613 if (event.status === 'success' && !requested && volumeInfo) {
614 console.warn('Mounted volume without a request: ' + volumeId);
615 var e = new Event('externally-unmounted');
616 e.volumeInfo = volumeInfo;
617 this.dispatchEvent(e);
620 this.finishRequest_(requestKey, status);
621 if (event.status === 'success')
622 this.volumeInfoList.remove(event.volumeMetadata.volumeId);
630 * Creates string to match mount events with requests.
631 * @param {string} requestType 'mount' | 'unmount'. TODO(hidehiko): Replace by
633 * @param {string} argument Argument describing the request, eg. source file
634 * path of the archive to be mounted, or a volumeId for unmounting.
635 * @return {string} Key for |this.requests_|.
638 VolumeManager.prototype.makeRequestKey_ = function(requestType, argument) {
639 return requestType + ':' + argument;
643 * @param {string} fileUrl File url to the archive file.
644 * @param {function(VolumeInfo)} successCallback Success callback.
645 * @param {function(VolumeManagerCommon.VolumeError)} errorCallback Error
648 VolumeManager.prototype.mountArchive = function(
649 fileUrl, successCallback, errorCallback) {
650 chrome.fileBrowserPrivate.addMount(fileUrl, function(sourcePath) {
652 'Mount request: url=' + fileUrl + '; sourcePath=' + sourcePath);
653 var requestKey = this.makeRequestKey_('mount', sourcePath);
654 this.startRequest_(requestKey, successCallback, errorCallback);
660 * @param {!VolumeInfo} volumeInfo Volume to be unmounted.
661 * @param {function()} successCallback Success callback.
662 * @param {function(VolumeManagerCommon.VolumeError)} errorCallback Error
665 VolumeManager.prototype.unmount = function(volumeInfo,
668 chrome.fileBrowserPrivate.removeMount(volumeInfo.volumeId);
669 var requestKey = this.makeRequestKey_('unmount', volumeInfo.volumeId);
670 this.startRequest_(requestKey, successCallback, errorCallback);
674 * Obtains a volume info containing the passed entry.
675 * @param {Entry|Object} entry Entry on the volume to be returned. Can be fake.
676 * @return {VolumeInfo} The VolumeInfo instance or null if not found.
678 VolumeManager.prototype.getVolumeInfo = function(entry) {
679 return this.volumeInfoList.findByEntry(entry);
683 * Obtains volume information of the current profile.
685 * @param {VolumeManagerCommon.VolumeType} volumeType Volume type.
686 * @return {VolumeInfo} Volume info.
688 VolumeManager.prototype.getCurrentProfileVolumeInfo = function(volumeType) {
689 for (var i = 0; i < this.volumeInfoList.length; i++) {
690 var volumeInfo = this.volumeInfoList.item(i);
691 if (volumeInfo.profile.isCurrentProfile &&
692 volumeInfo.volumeType === volumeType)
699 * Obtains location information from an entry.
701 * @param {Entry|Object} entry File or directory entry. It can be a fake entry.
702 * @return {EntryLocation} Location information.
704 VolumeManager.prototype.getLocationInfo = function(entry) {
705 var volumeInfo = this.volumeInfoList.findByEntry(entry);
709 if (util.isFakeEntry(entry)) {
710 return new EntryLocation(
713 true /* the entry points a root directory. */,
714 true /* fake entries are read only. */);
720 if (volumeInfo.volumeType === VolumeManagerCommon.VolumeType.DRIVE) {
721 // For Drive, the roots are /root and /other, instead of /. Root URLs
722 // contain trailing slashes.
723 if (entry.fullPath == '/root' || entry.fullPath.indexOf('/root/') === 0) {
724 rootType = VolumeManagerCommon.RootType.DRIVE;
725 isReadOnly = volumeInfo.isReadOnly;
726 isRootEntry = entry.fullPath === '/root';
727 } else if (entry.fullPath == '/other' ||
728 entry.fullPath.indexOf('/other/') === 0) {
729 rootType = VolumeManagerCommon.RootType.DRIVE_OTHER;
731 isRootEntry = entry.fullPath === '/other';
733 // Accessing Drive files outside of /drive/root and /drive/other is not
734 // allowed, but can happen. Therefore returning null.
738 switch (volumeInfo.volumeType) {
739 case VolumeManagerCommon.VolumeType.DOWNLOADS:
740 rootType = VolumeManagerCommon.RootType.DOWNLOADS;
742 case VolumeManagerCommon.VolumeType.REMOVABLE:
743 rootType = VolumeManagerCommon.RootType.REMOVABLE;
745 case VolumeManagerCommon.VolumeType.ARCHIVE:
746 rootType = VolumeManagerCommon.RootType.ARCHIVE;
748 case VolumeManagerCommon.VolumeType.CLOUD_DEVICE:
749 rootType = VolumeManagerCommon.RootType.CLOUD_DEVICE;
751 case VolumeManagerCommon.VolumeType.MTP:
752 rootType = VolumeManagerCommon.RootType.MTP;
754 case VolumeManagerCommon.VolumeType.PROVIDED:
755 rootType = VolumeManagerCommon.RootType.PROVIDED;
758 // Programming error, throw an exception.
759 throw new Error('Invalid volume type: ' + volumeInfo.volumeType);
761 isReadOnly = volumeInfo.isReadOnly;
762 isRootEntry = util.isSameEntry(entry, volumeInfo.fileSystem.root);
765 return new EntryLocation(volumeInfo, rootType, isRootEntry, isReadOnly);
769 * @param {string} key Key produced by |makeRequestKey_|.
770 * @param {function(VolumeInfo)} successCallback To be called when the request
771 * finishes successfully.
772 * @param {function(VolumeManagerCommon.VolumeError)} errorCallback To be called
773 * when the request fails.
776 VolumeManager.prototype.startRequest_ = function(key,
777 successCallback, errorCallback) {
778 if (key in this.requests_) {
779 var request = this.requests_[key];
780 request.successCallbacks.push(successCallback);
781 request.errorCallbacks.push(errorCallback);
783 this.requests_[key] = {
784 successCallbacks: [successCallback],
785 errorCallbacks: [errorCallback],
787 timeout: setTimeout(this.onTimeout_.bind(this, key),
788 VolumeManager.TIMEOUT)
794 * Called if no response received in |TIMEOUT|.
795 * @param {string} key Key produced by |makeRequestKey_|.
798 VolumeManager.prototype.onTimeout_ = function(key) {
799 this.invokeRequestCallbacks_(this.requests_[key],
800 VolumeManagerCommon.VolumeError.TIMEOUT);
801 delete this.requests_[key];
805 * @param {string} key Key produced by |makeRequestKey_|.
806 * @param {VolumeManagerCommon.VolumeError|'success'} status Status received
808 * @param {VolumeInfo=} opt_volumeInfo Volume info of the mounted volume.
811 VolumeManager.prototype.finishRequest_ = function(key, status, opt_volumeInfo) {
812 var request = this.requests_[key];
816 clearTimeout(request.timeout);
817 this.invokeRequestCallbacks_(request, status, opt_volumeInfo);
818 delete this.requests_[key];
822 * @param {Object} request Structure created in |startRequest_|.
823 * @param {VolumeManagerCommon.VolumeError|string} status If status ===
824 * 'success' success callbacks are called.
825 * @param {VolumeInfo=} opt_volumeInfo Volume info of the mounted volume.
828 VolumeManager.prototype.invokeRequestCallbacks_ = function(
829 request, status, opt_volumeInfo) {
830 var callEach = function(callbacks, self, args) {
831 for (var i = 0; i < callbacks.length; i++) {
832 callbacks[i].apply(self, args);
835 if (status === 'success') {
836 callEach(request.successCallbacks, this, [opt_volumeInfo]);
838 volumeManagerUtil.validateError(status);
839 callEach(request.errorCallbacks, this, [status]);
844 * Location information which shows where the path points in FileManager's
847 * @param {!VolumeInfo} volumeInfo Volume information.
848 * @param {VolumeManagerCommon.RootType} rootType Root type.
849 * @param {boolean} isRootEntry Whether the entry is root entry or not.
850 * @param {boolean} isReadOnly Whether the entry is read only or not.
853 function EntryLocation(volumeInfo, rootType, isRootEntry, isReadOnly) {
855 * Volume information.
856 * @type {!VolumeInfo}
858 this.volumeInfo = volumeInfo;
862 * @type {VolumeManagerCommon.RootType}
864 this.rootType = rootType;
867 * Whether the entry is root entry or not.
870 this.isRootEntry = isRootEntry;
873 * Whether the location obtained from the fake entry correspond to special
877 this.isSpecialSearchRoot =
878 this.rootType === VolumeManagerCommon.RootType.DRIVE_OFFLINE ||
879 this.rootType === VolumeManagerCommon.RootType.DRIVE_SHARED_WITH_ME ||
880 this.rootType === VolumeManagerCommon.RootType.DRIVE_RECENT;
883 * Whether the location is under Google Drive or a special search root which
884 * represents a special search from Google Drive.
888 this.rootType === VolumeManagerCommon.RootType.DRIVE ||
889 this.rootType === VolumeManagerCommon.RootType.DRIVE_OTHER ||
890 this.rootType === VolumeManagerCommon.RootType.DRIVE_SHARED_WITH_ME ||
891 this.rootType === VolumeManagerCommon.RootType.DRIVE_RECENT ||
892 this.rootType === VolumeManagerCommon.RootType.DRIVE_OFFLINE;
895 * Whether the given path can be a target path of folder shortcut.
898 this.isEligibleForFolderShortcut =
899 !this.isSpecialSearchRoot &&
904 * Whether the entry is read only or not.
907 this.isReadOnly = isReadOnly;