| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Represents each volume, such as "drive", "download directory", each "USB | 8 * Represents each volume, such as "drive", "download directory", each "USB |
| 9 * flush storage", or "mounted zip archive" etc. | 9 * flush storage", or "mounted zip archive" etc. |
| 10 * | 10 * |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 }.bind(this)); | 537 }.bind(this)); |
| 538 }; | 538 }; |
| 539 | 539 |
| 540 /** | 540 /** |
| 541 * Event handler called when some volume was mounted or unmounted. | 541 * Event handler called when some volume was mounted or unmounted. |
| 542 * @param {MountCompletedEvent} event Received event. | 542 * @param {MountCompletedEvent} event Received event. |
| 543 * @private | 543 * @private |
| 544 */ | 544 */ |
| 545 VolumeManager.prototype.onMountCompleted_ = function(event) { | 545 VolumeManager.prototype.onMountCompleted_ = function(event) { |
| 546 this.mountQueue_.run(function(callback) { | 546 this.mountQueue_.run(function(callback) { |
| 547 if (event.eventType === 'mount') { | 547 switch (event.eventType) { |
| 548 var requestKey = this.makeRequestKey_( | 548 case 'mount': |
| 549 'mount', | 549 var requestKey = this.makeRequestKey_( |
| 550 event.volumeMetadata.sourcePath); | 550 'mount', |
| 551 event.volumeMetadata.sourcePath); |
| 551 | 552 |
| 552 // TODO(mtomasz): Migrate to volumeId once possible. | |
| 553 if (event.volumeMetadata.mountPath) { | |
| 554 var error = event.status === 'success' ? '' : event.status; | 553 var error = event.status === 'success' ? '' : event.status; |
| 555 volumeManagerUtil.createVolumeInfo( | 554 if (!error || event.status === 'error_unknown_filesystem') { |
| 556 event.volumeMetadata, | 555 volumeManagerUtil.createVolumeInfo( |
| 557 function(volumeInfo) { | 556 event.volumeMetadata, |
| 558 this.volumeInfoList.add(volumeInfo); | 557 function(volumeInfo) { |
| 559 this.finishRequest_(requestKey, event.status, volumeInfo); | 558 this.volumeInfoList.add(volumeInfo); |
| 560 if (volumeInfo.volumeType === util.VolumeType.DRIVE) { | 559 this.finishRequest_(requestKey, event.status, volumeInfo); |
| 561 // Update the network connection status, because until the | 560 |
| 562 // drive is initialized, the status is set to not ready. | 561 if (volumeInfo.volumeType === util.VolumeType.DRIVE) { |
| 563 // TODO(hidehiko): The connection status should be migrated into | 562 // Update the network connection status, because until the |
| 564 // VolumeMetadata. | 563 // drive is initialized, the status is set to not ready. |
| 565 this.onDriveConnectionStatusChanged_(); | 564 // TODO(mtomasz): The connection status should be migrated |
| 566 } | 565 // into VolumeMetadata. |
| 567 callback(); | 566 this.onDriveConnectionStatusChanged_(); |
| 568 }.bind(this)); | 567 } |
| 569 } else { | 568 callback(); |
| 570 console.warn('No mount path.'); | 569 }.bind(this)); |
| 571 this.finishRequest_(requestKey, event.status); | 570 } else { |
| 571 console.warn('Failed to mount a volume: ' + event.status); |
| 572 this.finishRequest_(requestKey, event.status); |
| 573 callback(); |
| 574 } |
| 575 break; |
| 576 |
| 577 case 'unmount': |
| 578 var volumeId = event.volumeMetadata.volumeId; |
| 579 var status = event.status; |
| 580 if (status === util.VolumeError.PATH_UNMOUNTED) { |
| 581 console.warn('Volume already unmounted: ', volumeId); |
| 582 status = 'success'; |
| 583 } |
| 584 var requestKey = this.makeRequestKey_('unmount', volumeId); |
| 585 var requested = requestKey in this.requests_; |
| 586 var volumeInfoIndex = |
| 587 this.volumeInfoList.findIndex(volumeId); |
| 588 var volumeInfo = volumeInfoIndex !== -1 ? |
| 589 this.volumeInfoList.item(volumeInfoIndex) : null; |
| 590 if (event.status === 'success' && !requested && volumeInfo) { |
| 591 console.warn('Mounted volume without a request: ' + volumeId); |
| 592 var e = new Event('externally-unmounted'); |
| 593 e.volumeInfo = volumeInfo; |
| 594 this.dispatchEvent(e); |
| 595 } |
| 596 |
| 597 this.finishRequest_(requestKey, status); |
| 598 if (event.status === 'success') |
| 599 this.volumeInfoList.remove(event.volumeMetadata.volumeId); |
| 572 callback(); | 600 callback(); |
| 573 } | 601 break; |
| 574 } else if (event.eventType === 'unmount') { | |
| 575 var volumeId = event.volumeMetadata.volumeId; | |
| 576 var status = event.status; | |
| 577 if (status === util.VolumeError.PATH_UNMOUNTED) { | |
| 578 console.warn('Volume already unmounted: ', volumeId); | |
| 579 status = 'success'; | |
| 580 } | |
| 581 var requestKey = this.makeRequestKey_('unmount', volumeId); | |
| 582 var requested = requestKey in this.requests_; | |
| 583 var volumeInfoIndex = | |
| 584 this.volumeInfoList.findIndex(volumeId); | |
| 585 var volumeInfo = volumeInfoIndex !== -1 ? | |
| 586 this.volumeInfoList.item(volumeInfoIndex) : null; | |
| 587 if (event.status === 'success' && !requested && volumeInfo) { | |
| 588 console.warn('Mounted volume without a request: ', volumeId); | |
| 589 var e = new Event('externally-unmounted'); | |
| 590 e.volumeInfo = volumeInfo; | |
| 591 this.dispatchEvent(e); | |
| 592 } | |
| 593 this.finishRequest_(requestKey, status); | |
| 594 | |
| 595 if (event.status === 'success') | |
| 596 this.volumeInfoList.remove(event.volumeMetadata.volumeId); | |
| 597 callback(); | |
| 598 } | 602 } |
| 599 }.bind(this)); | 603 }.bind(this)); |
| 600 }; | 604 }; |
| 601 | 605 |
| 602 /** | 606 /** |
| 603 * Creates string to match mount events with requests. | 607 * Creates string to match mount events with requests. |
| 604 * @param {string} requestType 'mount' | 'unmount'. TODO(hidehiko): Replace by | 608 * @param {string} requestType 'mount' | 'unmount'. TODO(hidehiko): Replace by |
| 605 * enum. | 609 * enum. |
| 606 * @param {string} argument Argument describing the request, eg. source file | 610 * @param {string} argument Argument describing the request, eg. source file |
| 607 * path of the archive to be mounted, or a volumeId for unmounting. | 611 * path of the archive to be mounted, or a volumeId for unmounting. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 entry.fullPath.indexOf('/other/') === 0) { | 703 entry.fullPath.indexOf('/other/') === 0) { |
| 700 rootType = RootType.DRIVE_OTHER; | 704 rootType = RootType.DRIVE_OTHER; |
| 701 isReadOnly = true; | 705 isReadOnly = true; |
| 702 isRootEntry = entry.fullPath === '/other'; | 706 isRootEntry = entry.fullPath === '/other'; |
| 703 } else { | 707 } else { |
| 704 // Accessing Drive files outside of /drive/root and /drive/other is not | 708 // Accessing Drive files outside of /drive/root and /drive/other is not |
| 705 // allowed, but can happen. Therefore returning null. | 709 // allowed, but can happen. Therefore returning null. |
| 706 return null; | 710 return null; |
| 707 } | 711 } |
| 708 } else { | 712 } else { |
| 709 // Otherwise, root path is same with a mount path of the volume. | |
| 710 switch (volumeInfo.volumeType) { | 713 switch (volumeInfo.volumeType) { |
| 711 case util.VolumeType.DOWNLOADS: | 714 case util.VolumeType.DOWNLOADS: |
| 712 rootType = RootType.DOWNLOADS; | 715 rootType = RootType.DOWNLOADS; |
| 713 break; | 716 break; |
| 714 case util.VolumeType.REMOVABLE: | 717 case util.VolumeType.REMOVABLE: |
| 715 rootType = RootType.REMOVABLE; | 718 rootType = RootType.REMOVABLE; |
| 716 break; | 719 break; |
| 717 case util.VolumeType.ARCHIVE: | 720 case util.VolumeType.ARCHIVE: |
| 718 rootType = RootType.ARCHIVE; | 721 rootType = RootType.ARCHIVE; |
| 719 break; | 722 break; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 this.isDriveBased; | 869 this.isDriveBased; |
| 867 | 870 |
| 868 /** | 871 /** |
| 869 * Whether the entry is read only or not. | 872 * Whether the entry is read only or not. |
| 870 * @type {boolean} | 873 * @type {boolean} |
| 871 */ | 874 */ |
| 872 this.isReadOnly = isReadOnly; | 875 this.isReadOnly = isReadOnly; |
| 873 | 876 |
| 874 Object.freeze(this); | 877 Object.freeze(this); |
| 875 } | 878 } |
| OLD | NEW |