Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: chrome/browser/resources/file_manager/background/js/volume_manager.js

Issue 181203002: Get rid of mountPath dependency in Files app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased + cleaned up. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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(hidehiko): The connection status should be migrated in to
hirono 2014/03/03 01:58:23 nit: Over 80 characters?
mtomasz 2014/03/03 02:18:54 Done.
566 } 565 // 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 case 'unmount':
hirono 2014/03/03 01:58:23 nit: Please insert a line before #576.
mtomasz 2014/03/03 02:18:54 Done.
577 var volumeId = event.volumeMetadata.volumeId;
578 var status = event.status;
579 if (status === util.VolumeError.PATH_UNMOUNTED) {
580 console.warn('Volume already unmounted: ', volumeId);
581 status = 'success';
582 }
583 var requestKey = this.makeRequestKey_('unmount', volumeId);
584 var requested = requestKey in this.requests_;
585 var volumeInfoIndex =
586 this.volumeInfoList.findIndex(volumeId);
587 var volumeInfo = volumeInfoIndex !== -1 ?
588 this.volumeInfoList.item(volumeInfoIndex) : null;
589 if (event.status === 'success' && !requested && volumeInfo) {
590 console.warn('Mounted volume without a request: ' + volumeId);
591 var e = new Event('externally-unmounted');
592 e.volumeInfo = volumeInfo;
593 this.dispatchEvent(e);
594 }
595
596 this.finishRequest_(requestKey, status);
597 if (event.status === 'success')
598 this.volumeInfoList.remove(event.volumeMetadata.volumeId);
572 callback(); 599 callback();
573 } 600 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 } 601 }
599 }.bind(this)); 602 }.bind(this));
600 }; 603 };
601 604
602 /** 605 /**
603 * Creates string to match mount events with requests. 606 * Creates string to match mount events with requests.
604 * @param {string} requestType 'mount' | 'unmount'. TODO(hidehiko): Replace by 607 * @param {string} requestType 'mount' | 'unmount'. TODO(hidehiko): Replace by
605 * enum. 608 * enum.
606 * @param {string} argument Argument describing the request, eg. source file 609 * @param {string} argument Argument describing the request, eg. source file
607 * path of the archive to be mounted, or a volumeId for unmounting. 610 * path of the archive to be mounted, or a volumeId for unmounting.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 entry.fullPath.indexOf('/other/') === 0) { 702 entry.fullPath.indexOf('/other/') === 0) {
700 rootType = RootType.DRIVE_OTHER; 703 rootType = RootType.DRIVE_OTHER;
701 isReadOnly = true; 704 isReadOnly = true;
702 isRootEntry = entry.fullPath === '/other'; 705 isRootEntry = entry.fullPath === '/other';
703 } else { 706 } else {
704 // Accessing Drive files outside of /drive/root and /drive/other is not 707 // Accessing Drive files outside of /drive/root and /drive/other is not
705 // allowed, but can happen. Therefore returning null. 708 // allowed, but can happen. Therefore returning null.
706 return null; 709 return null;
707 } 710 }
708 } else { 711 } else {
709 // Otherwise, root path is same with a mount path of the volume.
710 switch (volumeInfo.volumeType) { 712 switch (volumeInfo.volumeType) {
711 case util.VolumeType.DOWNLOADS: 713 case util.VolumeType.DOWNLOADS:
712 rootType = RootType.DOWNLOADS; 714 rootType = RootType.DOWNLOADS;
713 break; 715 break;
714 case util.VolumeType.REMOVABLE: 716 case util.VolumeType.REMOVABLE:
715 rootType = RootType.REMOVABLE; 717 rootType = RootType.REMOVABLE;
716 break; 718 break;
717 case util.VolumeType.ARCHIVE: 719 case util.VolumeType.ARCHIVE:
718 rootType = RootType.ARCHIVE; 720 rootType = RootType.ARCHIVE;
719 break; 721 break;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 this.isDriveBased; 868 this.isDriveBased;
867 869
868 /** 870 /**
869 * Whether the entry is read only or not. 871 * Whether the entry is read only or not.
870 * @type {boolean} 872 * @type {boolean}
871 */ 873 */
872 this.isReadOnly = isReadOnly; 874 this.isReadOnly = isReadOnly;
873 875
874 Object.freeze(this); 876 Object.freeze(this);
875 } 877 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698