| 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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 // about Drive, Downloads nor archives. | 507 // about Drive, Downloads nor archives. |
| 508 // TODO(hidehiko): Figure out the historical intention of the method, | 508 // TODO(hidehiko): Figure out the historical intention of the method, |
| 509 // and clean them up. | 509 // and clean them up. |
| 510 | 510 |
| 511 // Create VolumeInfo for each mount point. | 511 // Create VolumeInfo for each mount point. |
| 512 var group = new AsyncUtil.Group(); | 512 var group = new AsyncUtil.Group(); |
| 513 for (var i = 0; i < mountPointList.length; i++) { | 513 for (var i = 0; i < mountPointList.length; i++) { |
| 514 var mountPoint = mountPointList[i]; | 514 var mountPoint = mountPointList[i]; |
| 515 | 515 |
| 516 // TODO(hidehiko): It should be ok that the drive is mounted already. | 516 // TODO(hidehiko): It should be ok that the drive is mounted already. |
| 517 if (mountPoint.mountType == 'drive') | 517 if (mountPoint.volumeType == 'drive') |
| 518 console.error('Drive is not expected initially mounted'); | 518 console.error('Drive is not expected initially mounted'); |
| 519 | 519 |
| 520 var error = mountPoint.mountCondition ? | 520 var error = mountPoint.mountCondition ? |
| 521 'error_' + mountPoint.mountCondition : ''; | 521 'error_' + mountPoint.mountCondition : ''; |
| 522 group.add(function(mountPoint, error, callback) { | 522 group.add(function(mountPoint, error, callback) { |
| 523 volumeManagerUtil.createVolumeInfo( | 523 volumeManagerUtil.createVolumeInfo( |
| 524 '/' + mountPoint.mountPath, error, | 524 '/' + mountPoint.mountPath, error, |
| 525 function(volumeInfo) { | 525 function(volumeInfo) { |
| 526 this.volumeInfoList.add(volumeInfo); | 526 this.volumeInfoList.add(volumeInfo); |
| 527 callback(); | 527 callback(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 555 | 555 |
| 556 /** | 556 /** |
| 557 * Event handler called when some volume was mounted or unmouted. | 557 * Event handler called when some volume was mounted or unmouted. |
| 558 * @param {MountCompletedEvent} event Received event. | 558 * @param {MountCompletedEvent} event Received event. |
| 559 * @private | 559 * @private |
| 560 */ | 560 */ |
| 561 VolumeManager.prototype.onMountCompleted_ = function(event) { | 561 VolumeManager.prototype.onMountCompleted_ = function(event) { |
| 562 if (event.eventType == 'mount') { | 562 if (event.eventType == 'mount') { |
| 563 if (event.mountPath) { | 563 if (event.mountPath) { |
| 564 var requestKey = this.makeRequestKey_( | 564 var requestKey = this.makeRequestKey_( |
| 565 'mount', event.mountType, event.sourcePath); | 565 'mount', event.volumeType, event.sourcePath); |
| 566 var error = event.status == 'success' ? '' : event.status; | 566 var error = event.status == 'success' ? '' : event.status; |
| 567 volumeManagerUtil.createVolumeInfo( | 567 volumeManagerUtil.createVolumeInfo( |
| 568 event.mountPath, error, function(volume) { | 568 event.mountPath, error, function(volume) { |
| 569 this.volumeInfoList.add(volume); | 569 this.volumeInfoList.add(volume); |
| 570 this.finishRequest_(requestKey, event.status, event.mountPath); | 570 this.finishRequest_(requestKey, event.status, event.mountPath); |
| 571 cr.dispatchSimpleEvent(this, 'change'); | 571 cr.dispatchSimpleEvent(this, 'change'); |
| 572 }.bind(this)); | 572 }.bind(this)); |
| 573 } else { | 573 } else { |
| 574 console.warn('No mount path.'); | 574 console.warn('No mount path.'); |
| 575 this.finishRequest_(requestKey, event.status); | 575 this.finishRequest_(requestKey, event.status); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 592 this.dispatchEvent(e); | 592 this.dispatchEvent(e); |
| 593 } | 593 } |
| 594 this.finishRequest_(requestKey, status); | 594 this.finishRequest_(requestKey, status); |
| 595 | 595 |
| 596 if (event.status == 'success') { | 596 if (event.status == 'success') { |
| 597 this.volumeInfoList.remove(mountPath); | 597 this.volumeInfoList.remove(mountPath); |
| 598 cr.dispatchSimpleEvent(this, 'change'); | 598 cr.dispatchSimpleEvent(this, 'change'); |
| 599 } | 599 } |
| 600 } | 600 } |
| 601 | 601 |
| 602 if (event.mountType == 'drive') { | 602 if (event.volumeType == 'drive') { |
| 603 if (event.status == 'success') { | 603 if (event.status == 'success') { |
| 604 if (event.eventType == 'mount') { | 604 if (event.eventType == 'mount') { |
| 605 // If the mount is not requested, the mount status will not be changed | 605 // If the mount is not requested, the mount status will not be changed |
| 606 // at mountDrive(). Sets it here in such a case. | 606 // at mountDrive(). Sets it here in such a case. |
| 607 var self = this; | 607 var self = this; |
| 608 var timeout = setTimeout(function() { | 608 var timeout = setTimeout(function() { |
| 609 if (self.getDriveStatus() == VolumeManager.DriveStatus.UNMOUNTED) | 609 if (self.getDriveStatus() == VolumeManager.DriveStatus.UNMOUNTED) |
| 610 self.setDriveStatus_(VolumeManager.DriveStatus.MOUNTING); | 610 self.setDriveStatus_(VolumeManager.DriveStatus.MOUNTING); |
| 611 timeout = null; | 611 timeout = null; |
| 612 }, VolumeManager.MOUNTING_DELAY); | 612 }, VolumeManager.MOUNTING_DELAY); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 entry.createReader().readEntries( | 650 entry.createReader().readEntries( |
| 651 callback.bind(null, true), | 651 callback.bind(null, true), |
| 652 callback.bind(null, false)); | 652 callback.bind(null, false)); |
| 653 }, | 653 }, |
| 654 callback.bind(null, false)); | 654 callback.bind(null, false)); |
| 655 }; | 655 }; |
| 656 | 656 |
| 657 /** | 657 /** |
| 658 * Creates string to match mount events with requests. | 658 * Creates string to match mount events with requests. |
| 659 * @param {string} requestType 'mount' | 'unmount'. | 659 * @param {string} requestType 'mount' | 'unmount'. |
| 660 * @param {string} mountType 'device' | 'file' | 'network' | 'drive'. | 660 * @param {string} volumeType 'drive' | 'downloads' | 'removable' | 'archive'. |
| 661 * @param {string} mountOrSourcePath Source path provided by API after | 661 * @param {string} mountOrSourcePath Source path provided by API after |
| 662 * resolving mount request or mountPath for unmount request. | 662 * resolving mount request or mountPath for unmount request. |
| 663 * @return {string} Key for |this.requests_|. | 663 * @return {string} Key for |this.requests_|. |
| 664 * @private | 664 * @private |
| 665 */ | 665 */ |
| 666 VolumeManager.prototype.makeRequestKey_ = function(requestType, | 666 VolumeManager.prototype.makeRequestKey_ = function(requestType, |
| 667 mountType, | 667 volumeType, |
| 668 mountOrSourcePath) { | 668 mountOrSourcePath) { |
| 669 return requestType + ':' + mountType + ':' + mountOrSourcePath; | 669 return requestType + ':' + volumeType + ':' + mountOrSourcePath; |
| 670 }; | 670 }; |
| 671 | 671 |
| 672 | 672 |
| 673 /** | 673 /** |
| 674 * @param {function(string)} successCallback Success callback. | 674 * @param {function(string)} successCallback Success callback. |
| 675 * @param {function(VolumeManager.Error)} errorCallback Error callback. | 675 * @param {function(VolumeManager.Error)} errorCallback Error callback. |
| 676 */ | 676 */ |
| 677 VolumeManager.prototype.mountDrive = function(successCallback, errorCallback) { | 677 VolumeManager.prototype.mountDrive = function(successCallback, errorCallback) { |
| 678 if (this.getDriveStatus() == VolumeManager.DriveStatus.ERROR) { | 678 if (this.getDriveStatus() == VolumeManager.DriveStatus.ERROR) { |
| 679 this.setDriveStatus_(VolumeManager.DriveStatus.UNMOUNTED); | 679 this.setDriveStatus_(VolumeManager.DriveStatus.UNMOUNTED); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 695 }); | 695 }); |
| 696 }; | 696 }; |
| 697 | 697 |
| 698 /** | 698 /** |
| 699 * @param {string} fileUrl File url to the archive file. | 699 * @param {string} fileUrl File url to the archive file. |
| 700 * @param {function(string)} successCallback Success callback. | 700 * @param {function(string)} successCallback Success callback. |
| 701 * @param {function(VolumeManager.Error)} errorCallback Error callback. | 701 * @param {function(VolumeManager.Error)} errorCallback Error callback. |
| 702 */ | 702 */ |
| 703 VolumeManager.prototype.mountArchive = function(fileUrl, successCallback, | 703 VolumeManager.prototype.mountArchive = function(fileUrl, successCallback, |
| 704 errorCallback) { | 704 errorCallback) { |
| 705 this.mount_(fileUrl, 'file', successCallback, errorCallback); | 705 this.mount_(fileUrl, 'archive', successCallback, errorCallback); |
| 706 }; | 706 }; |
| 707 | 707 |
| 708 /** | 708 /** |
| 709 * Unmounts volume. | 709 * Unmounts volume. |
| 710 * @param {string} mountPath Volume mounted path. | 710 * @param {string} mountPath Volume mounted path. |
| 711 * @param {function(string)} successCallback Success callback. | 711 * @param {function(string)} successCallback Success callback. |
| 712 * @param {function(VolumeManager.Error)} errorCallback Error callback. | 712 * @param {function(VolumeManager.Error)} errorCallback Error callback. |
| 713 */ | 713 */ |
| 714 VolumeManager.prototype.unmount = function(mountPath, | 714 VolumeManager.prototype.unmount = function(mountPath, |
| 715 successCallback, | 715 successCallback, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 736 * @param {string} mountPath Volume mounted path. | 736 * @param {string} mountPath Volume mounted path. |
| 737 * @return {VolumeInfo} The data about the volume. | 737 * @return {VolumeInfo} The data about the volume. |
| 738 */ | 738 */ |
| 739 VolumeManager.prototype.getVolumeInfo = function(mountPath) { | 739 VolumeManager.prototype.getVolumeInfo = function(mountPath) { |
| 740 volumeManagerUtil.validateMountPath(mountPath); | 740 volumeManagerUtil.validateMountPath(mountPath); |
| 741 return this.volumeInfoList.find(mountPath); | 741 return this.volumeInfoList.find(mountPath); |
| 742 }; | 742 }; |
| 743 | 743 |
| 744 /** | 744 /** |
| 745 * @param {string} url URL for for |fileBrowserPrivate.addMount|. | 745 * @param {string} url URL for for |fileBrowserPrivate.addMount|. |
| 746 * @param {'drive'|'file'} mountType Mount type for | 746 * @param {'drive'|'archive'} volumeType Volume type for |
| 747 * |fileBrowserPrivate.addMount|. | 747 * |fileBrowserPrivate.addMount|. |
| 748 * @param {function(string)} successCallback Success callback. | 748 * @param {function(string)} successCallback Success callback. |
| 749 * @param {function(VolumeManager.Error)} errorCallback Error callback. | 749 * @param {function(VolumeManager.Error)} errorCallback Error callback. |
| 750 * @private | 750 * @private |
| 751 */ | 751 */ |
| 752 VolumeManager.prototype.mount_ = function(url, mountType, | 752 VolumeManager.prototype.mount_ = function(url, volumeType, |
| 753 successCallback, errorCallback) { | 753 successCallback, errorCallback) { |
| 754 if (this.deferredQueue_) { | 754 if (this.deferredQueue_) { |
| 755 this.deferredQueue_.push(this.mount_.bind(this, | 755 this.deferredQueue_.push(this.mount_.bind(this, |
| 756 url, mountType, successCallback, errorCallback)); | 756 url, volumeType, successCallback, errorCallback)); |
| 757 return; | 757 return; |
| 758 } | 758 } |
| 759 | 759 |
| 760 chrome.fileBrowserPrivate.addMount(url, mountType, {}, | 760 chrome.fileBrowserPrivate.addMount(url, volumeType, {}, |
| 761 function(sourcePath) { | 761 function(sourcePath) { |
| 762 console.info('Mount request: url=' + url + '; mountType=' + mountType + | 762 console.info('Mount request: url=' + url + '; volumeType=' + volumeType + |
| 763 '; sourceUrl=' + sourcePath); | 763 '; sourceUrl=' + sourcePath); |
| 764 var requestKey = this.makeRequestKey_('mount', mountType, sourcePath); | 764 var requestKey = this.makeRequestKey_('mount', volumeType, sourcePath); |
| 765 this.startRequest_(requestKey, successCallback, errorCallback); | 765 this.startRequest_(requestKey, successCallback, errorCallback); |
| 766 }.bind(this)); | 766 }.bind(this)); |
| 767 }; | 767 }; |
| 768 | 768 |
| 769 /** | 769 /** |
| 770 * @param {string} key Key produced by |makeRequestKey_|. | 770 * @param {string} key Key produced by |makeRequestKey_|. |
| 771 * @param {function(string)} successCallback To be called when request finishes | 771 * @param {function(string)} successCallback To be called when request finishes |
| 772 * successfully. | 772 * successfully. |
| 773 * @param {function(VolumeManager.Error)} errorCallback To be called when | 773 * @param {function(VolumeManager.Error)} errorCallback To be called when |
| 774 * request fails. | 774 * request fails. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 callbacks[i].apply(self, args); | 832 callbacks[i].apply(self, args); |
| 833 } | 833 } |
| 834 }; | 834 }; |
| 835 if (status == 'success') { | 835 if (status == 'success') { |
| 836 callEach(request.successCallbacks, this, [opt_mountPath]); | 836 callEach(request.successCallbacks, this, [opt_mountPath]); |
| 837 } else { | 837 } else { |
| 838 volumeManagerUtil.validateError(status); | 838 volumeManagerUtil.validateError(status); |
| 839 callEach(request.errorCallbacks, this, [status]); | 839 callEach(request.errorCallbacks, this, [status]); |
| 840 } | 840 } |
| 841 }; | 841 }; |
| OLD | NEW |