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 * Scanner of the entries. | 8 * Scanner of the entries. |
9 */ | 9 */ |
10 function ContentScanner() { | 10 function ContentScanner() { |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 * @type {FileFilter} | 436 * @type {FileFilter} |
437 */ | 437 */ |
438 this.fileFilter = fileFilter; | 438 this.fileFilter = fileFilter; |
439 } | 439 } |
440 | 440 |
441 /** | 441 /** |
442 * This class is responsible for scanning directory (or search results), | 442 * This class is responsible for scanning directory (or search results), |
443 * and filling the fileList. Different descendants handle various types of | 443 * and filling the fileList. Different descendants handle various types of |
444 * directory contents shown: basic directory, drive search results, local search | 444 * directory contents shown: basic directory, drive search results, local search |
445 * results. | 445 * results. |
446 * TODO(hidehiko): Remove EventTarget from this. | |
447 * | |
446 * @param {FileListContext} context The file list context. | 448 * @param {FileListContext} context The file list context. |
449 * @param {boolean} isSearch True for search directory contents, otherwise | |
450 * false. | |
451 * @param {DirectoryEntry} directoryEntry The entry of the current directory. | |
452 * @param {DirectoryEntry} lastNonSearchDirectoryEntry The entry of the last | |
453 * non-search directroy. | |
454 * @param {function():ContentScanner} scannerFactory The factory to create | |
455 * ContentScanner instance. | |
447 * @constructor | 456 * @constructor |
448 * @extends {cr.EventTarget} | 457 * @extends {cr.EventTarget} |
449 */ | 458 */ |
450 function DirectoryContents(context) { | 459 function DirectoryContents(context, isSearch, directoryEntry, |
460 lastNonSearchDirectoryEntry, | |
461 scannerFactory) { | |
451 this.context_ = context; | 462 this.context_ = context; |
452 this.fileList_ = context.fileList; | 463 this.fileList_ = context.fileList; |
464 | |
465 this.isSearch_ = isSearch; | |
466 this.directoryEntry_ = directoryEntry; | |
467 this.lastNonSearchDirectoryEntry_ = lastNonSearchDirectoryEntry; | |
468 | |
469 this.scannerFactory_ = scannerFactory; | |
470 this.scanner_ = null; | |
453 this.prefetchMetadataQueue_ = new AsyncUtil.Queue(); | 471 this.prefetchMetadataQueue_ = new AsyncUtil.Queue(); |
454 this.scanCancelled_ = false; | 472 this.scanCancelled_ = false; |
455 this.fileList_.prepareSort = this.prepareSort_.bind(this); | 473 this.fileList_.prepareSort = this.prepareSort_.bind(this); |
456 } | 474 } |
457 | 475 |
458 /** | 476 /** |
459 * DirectoryContents extends cr.EventTarget. | 477 * DirectoryContents extends cr.EventTarget. |
460 */ | 478 */ |
461 DirectoryContents.prototype.__proto__ = cr.EventTarget.prototype; | 479 DirectoryContents.prototype.__proto__ = cr.EventTarget.prototype; |
462 | 480 |
463 /** | 481 /** |
464 * Create the copy of the object, but without scan started. | 482 * Create the copy of the object, but without scan started. |
465 * @return {DirectoryContents} Object copy. | 483 * @return {DirectoryContents} Object copy. |
466 */ | 484 */ |
467 DirectoryContents.prototype.clone = function() { | 485 DirectoryContents.prototype.clone = function() { |
468 return new DirectoryContents(this.context_); | 486 return new DirectoryContents( |
487 this.context_, this.isSearch, this.directoryEntry_, | |
mtomasz
2013/10/01 02:38:12
nit: this.isSearch -> this.isSearch_
hidehiko
2013/10/01 07:38:55
Done.
| |
488 this.lastNonSearchDirectoryEntry_, this.scannerFactory_); | |
469 }; | 489 }; |
470 | 490 |
471 /** | 491 /** |
472 * Use a given fileList instead of the fileList from the context. | 492 * Use a given fileList instead of the fileList from the context. |
473 * @param {Array|cr.ui.ArrayDataModel} fileList The new file list. | 493 * @param {Array|cr.ui.ArrayDataModel} fileList The new file list. |
474 */ | 494 */ |
475 DirectoryContents.prototype.setFileList = function(fileList) { | 495 DirectoryContents.prototype.setFileList = function(fileList) { |
476 this.fileList_ = fileList; | 496 this.fileList_ = fileList; |
477 this.fileList_.prepareSort = this.prepareSort_.bind(this); | 497 this.fileList_.prepareSort = this.prepareSort_.bind(this); |
478 }; | 498 }; |
(...skipping 16 matching lines...) Expand all Loading... | |
495 * @return {boolean} If the scan is active. | 515 * @return {boolean} If the scan is active. |
496 */ | 516 */ |
497 DirectoryContents.prototype.isScanning = function() { | 517 DirectoryContents.prototype.isScanning = function() { |
498 return this.scanner_ || this.prefetchMetadataQueue_.isRunning(); | 518 return this.scanner_ || this.prefetchMetadataQueue_.isRunning(); |
499 }; | 519 }; |
500 | 520 |
501 /** | 521 /** |
502 * @return {boolean} True if search results (drive or local). | 522 * @return {boolean} True if search results (drive or local). |
503 */ | 523 */ |
504 DirectoryContents.prototype.isSearch = function() { | 524 DirectoryContents.prototype.isSearch = function() { |
505 return false; | 525 return this.isSearch_; |
506 }; | 526 }; |
507 | 527 |
508 /** | 528 /** |
509 * @return {DirectoryEntry} A DirectoryEntry for current directory. In case of | 529 * @return {DirectoryEntry} A DirectoryEntry for current directory. In case of |
510 * search -- the top directory from which search is run. | 530 * search -- the top directory from which search is run. |
511 */ | 531 */ |
512 DirectoryContents.prototype.getDirectoryEntry = function() { | 532 DirectoryContents.prototype.getDirectoryEntry = function() { |
513 throw 'Not implemented.'; | 533 return this.directoryEntry_; |
514 }; | 534 }; |
515 | 535 |
516 /** | 536 /** |
517 * @return {DirectoryEntry} A DirectoryEntry for the last non search contents. | 537 * @return {DirectoryEntry} A DirectoryEntry for the last non search contents. |
518 */ | 538 */ |
519 DirectoryContents.prototype.getLastNonSearchDirectoryEntry = function() { | 539 DirectoryContents.prototype.getLastNonSearchDirectoryEntry = function() { |
520 throw 'Not implemented.'; | 540 return this.lastNonSearchDirectoryEntry_; |
521 }; | 541 }; |
522 | 542 |
523 /** | 543 /** |
524 * Start directory scan/search operation. Either 'scan-completed' or | 544 * Start directory scan/search operation. Either 'scan-completed' or |
525 * 'scan-failed' event will be fired upon completion. | 545 * 'scan-failed' event will be fired upon completion. |
526 */ | 546 */ |
527 DirectoryContents.prototype.scan = function() { | 547 DirectoryContents.prototype.scan = function() { |
528 throw 'Not implemented.'; | 548 this.scanner_ = this.scannerFactory_(); |
549 this.scanner_.startScan(this.onNewEntries_.bind(this), | |
550 this.onScanCompleted_.bind(this), | |
551 this.onScanError_.bind(this)); | |
529 }; | 552 }; |
530 | 553 |
531 /** | 554 /** |
532 * Cancels the running scan. | 555 * Cancels the running scan. |
533 */ | 556 */ |
534 DirectoryContents.prototype.cancelScan = function() { | 557 DirectoryContents.prototype.cancelScan = function() { |
535 if (this.scanCancelled_) | 558 if (this.scanCancelled_) |
536 return; | 559 return; |
537 this.scanCancelled_ = true; | 560 this.scanCancelled_ = true; |
538 if (this.scanner_) | 561 if (this.scanner_) |
539 this.scanner_.cancel(); | 562 this.scanner_.cancel(); |
540 | 563 |
541 this.prefetchMetadataQueue_.cancel(); | 564 this.prefetchMetadataQueue_.cancel(); |
542 cr.dispatchSimpleEvent(this, 'scan-cancelled'); | 565 cr.dispatchSimpleEvent(this, 'scan-cancelled'); |
543 }; | 566 }; |
544 | 567 |
545 /** | 568 /** |
546 * Called when the scanning by scanner_ is done. | 569 * Called when the scanning by scanner_ is done. |
547 * @protected | 570 * @private |
548 */ | 571 */ |
549 DirectoryContents.prototype.onScanCompleted = function() { | 572 DirectoryContents.prototype.onScanCompleted_ = function() { |
550 this.scanner_ = null; | 573 this.scanner_ = null; |
551 if (this.scanCancelled_) | 574 if (this.scanCancelled_) |
552 return; | 575 return; |
553 | 576 |
554 this.prefetchMetadataQueue_.run(function(callback) { | 577 this.prefetchMetadataQueue_.run(function(callback) { |
555 cr.dispatchSimpleEvent(this, 'scan-completed'); | 578 cr.dispatchSimpleEvent(this, 'scan-completed'); |
556 if (!this.isSearch() && | 579 if (!this.isSearch() && |
557 this.getDirectoryEntry().fullPath === RootDirectory.DOWNLOADS) | 580 this.getDirectoryEntry().fullPath === RootDirectory.DOWNLOADS) |
558 metrics.recordMediumCount('DownloadsCount', this.fileList_.length); | 581 metrics.recordMediumCount('DownloadsCount', this.fileList_.length); |
559 callback(); | 582 callback(); |
560 }.bind(this)); | 583 }.bind(this)); |
561 }; | 584 }; |
562 | 585 |
563 /** | 586 /** |
564 * Called in case scan has failed. Should send the event. | 587 * Called in case scan has failed. Should send the event. |
565 * @protected | 588 * @private |
566 */ | 589 */ |
567 DirectoryContents.prototype.onScanError = function() { | 590 DirectoryContents.prototype.onScanError_ = function() { |
568 this.scanner_ = null; | 591 this.scanner_ = null; |
569 if (this.scanCancelled_) | 592 if (this.scanCancelled_) |
570 return; | 593 return; |
571 | 594 |
572 this.prefetchMetadataQueue_.run(function(callback) { | 595 this.prefetchMetadataQueue_.run(function(callback) { |
573 cr.dispatchSimpleEvent(this, 'scan-failed'); | 596 cr.dispatchSimpleEvent(this, 'scan-failed'); |
574 callback(); | 597 callback(); |
575 }.bind(this)); | 598 }.bind(this)); |
576 }; | 599 }; |
577 | 600 |
578 /** | 601 /** |
579 * Called when some chunk of entries are read by scanner. | 602 * Called when some chunk of entries are read by scanner. |
580 * @param {Array.<Entry>} entries The list of the scanned entries. | 603 * @param {Array.<Entry>} entries The list of the scanned entries. |
581 * @protected | 604 * @private |
582 */ | 605 */ |
583 DirectoryContents.prototype.onNewEntries = function(entries) { | 606 DirectoryContents.prototype.onNewEntries_ = function(entries) { |
584 if (this.scanCancelled_) | 607 if (this.scanCancelled_) |
585 return; | 608 return; |
586 | 609 |
587 var entriesFiltered = [].filter.call( | 610 var entriesFiltered = [].filter.call( |
588 entries, this.context_.fileFilter.filter.bind(this.context_.fileFilter)); | 611 entries, this.context_.fileFilter.filter.bind(this.context_.fileFilter)); |
589 | 612 |
590 // Because the prefetchMetadata can be slow, throttling by splitting entries | 613 // Because the prefetchMetadata can be slow, throttling by splitting entries |
591 // into smaller chunks to reduce UI latency. | 614 // into smaller chunks to reduce UI latency. |
592 // TODO(hidehiko,mtomasz): This should be handled in MetadataCache. | 615 // TODO(hidehiko,mtomasz): This should be handled in MetadataCache. |
593 var MAX_CHUNK_SIZE = 50; | 616 var MAX_CHUNK_SIZE = 50; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
639 this.context_.metadataCache.get(entries, 'filesystem', callback); | 662 this.context_.metadataCache.get(entries, 'filesystem', callback); |
640 }; | 663 }; |
641 | 664 |
642 /** | 665 /** |
643 * @param {string} name Directory name. | 666 * @param {string} name Directory name. |
644 * @param {function(DirectoryEntry)} successCallback Called on success. | 667 * @param {function(DirectoryEntry)} successCallback Called on success. |
645 * @param {function(FileError)} errorCallback On error. | 668 * @param {function(FileError)} errorCallback On error. |
646 */ | 669 */ |
647 DirectoryContents.prototype.createDirectory = function( | 670 DirectoryContents.prototype.createDirectory = function( |
648 name, successCallback, errorCallback) { | 671 name, successCallback, errorCallback) { |
649 throw 'Not implemented.'; | |
650 }; | |
651 | |
652 | |
653 /** | |
654 * @param {FileListContext} context File list context. | |
655 * @param {DirectoryEntry} entry DirectoryEntry for current directory. | |
656 * @constructor | |
657 * @extends {DirectoryContents} | |
658 */ | |
659 function DirectoryContentsBasic(context, entry) { | |
660 DirectoryContents.call(this, context); | |
661 this.entry_ = entry; | |
662 } | |
663 | |
664 /** | |
665 * Extends DirectoryContents | |
666 */ | |
667 DirectoryContentsBasic.prototype.__proto__ = DirectoryContents.prototype; | |
668 | |
669 /** | |
670 * Create the copy of the object, but without scan started. | |
671 * @return {DirectoryContentsBasic} Object copy. | |
672 */ | |
673 DirectoryContentsBasic.prototype.clone = function() { | |
674 return new DirectoryContentsBasic(this.context_, this.entry_); | |
675 }; | |
676 | |
677 /** | |
678 * @return {DirectoryEntry} DirectoryEntry of the current directory. | |
679 */ | |
680 DirectoryContentsBasic.prototype.getDirectoryEntry = function() { | |
681 return this.entry_; | |
682 }; | |
683 | |
684 /** | |
685 * @return {DirectoryEntry} DirectoryEntry for the currnet entry. | |
686 */ | |
687 DirectoryContentsBasic.prototype.getLastNonSearchDirectoryEntry = function() { | |
688 return this.entry_; | |
689 }; | |
690 | |
691 /** | |
692 * Start directory scan. | |
693 */ | |
694 DirectoryContentsBasic.prototype.scan = function() { | |
695 this.scanner_ = new DirectoryContentScanner(this.entry_); | |
696 this.scanner_.startScan(this.onNewEntries.bind(this), | |
697 this.onScanCompleted.bind(this), | |
698 this.onScanError.bind(this)); | |
699 }; | |
700 | |
701 /** | |
702 * @param {string} name Directory name. | |
703 * @param {function(Entry)} successCallback Called on success. | |
704 * @param {function(FileError)} errorCallback On error. | |
705 */ | |
706 DirectoryContentsBasic.prototype.createDirectory = function( | |
707 name, successCallback, errorCallback) { | |
708 // TODO(hidehiko): createDirectory should not be the part of | 672 // TODO(hidehiko): createDirectory should not be the part of |
709 // DirectoryContent. | 673 // DirectoryContent. |
710 if (!this.entry_) { | 674 if (this.isSearch_ || !this.directoryEntry_) { |
711 errorCallback(util.createFileError(FileError.INVALID_MODIFICATION_ERR)); | 675 errorCallback(util.createFileError(FileError.INVALID_MODIFICATION_ERR)); |
712 return; | 676 return; |
713 } | 677 } |
714 | 678 |
715 var onSuccess = function(newEntry) { | 679 var onSuccess = function(newEntry) { |
716 this.reloadMetadata([newEntry], function() { | 680 this.reloadMetadata([newEntry], function() { |
717 successCallback(newEntry); | 681 successCallback(newEntry); |
718 }); | 682 }); |
719 }; | 683 }; |
720 | 684 |
721 this.entry_.getDirectory(name, {create: true, exclusive: true}, | 685 this.directoryEntry_.getDirectory(name, {create: true, exclusive: true}, |
722 onSuccess.bind(this), errorCallback); | 686 onSuccess.bind(this), errorCallback); |
723 }; | 687 }; |
724 | 688 |
725 /** | 689 /** |
690 * Creates a DirectoryContents instance to show entries in a directory. | |
726 * @param {FileListContext} context File list context. | 691 * @param {FileListContext} context File list context. |
727 * @param {DirectoryEntry} dirEntry Current directory. | 692 * @param {DirectoryEntry} directoryEntry The current directory entry. |
728 * @param {DirectoryEntry} previousDirEntry DirectoryEntry that was current | 693 * @return {DirectoryContents} Created DirectoryContents instance. |
729 * before the search. | |
730 * @param {string} query Search query. | |
731 * @constructor | |
732 * @extends {DirectoryContents} | |
733 */ | 694 */ |
734 function DirectoryContentsDriveSearch(context, | 695 DirectoryContents.createForDirectory = function(context, directoryEntry) { |
735 dirEntry, | 696 return new DirectoryContents( |
736 previousDirEntry, | 697 context, |
737 query) { | 698 false, // Non search. |
738 DirectoryContents.call(this, context); | 699 directoryEntry, |
739 this.directoryEntry_ = dirEntry; | 700 directoryEntry, |
740 this.previousDirectoryEntry_ = previousDirEntry; | 701 function() { |
741 this.query_ = query; | 702 return new DirectoryContentScanner(directoryEntry); |
742 } | 703 }); |
743 | |
744 /** | |
745 * Extends DirectoryContents. | |
746 */ | |
747 DirectoryContentsDriveSearch.prototype.__proto__ = DirectoryContents.prototype; | |
748 | |
749 /** | |
750 * Create the copy of the object, but without scan started. | |
751 * @return {DirectoryContentsBasic} Object copy. | |
752 */ | |
753 DirectoryContentsDriveSearch.prototype.clone = function() { | |
754 return new DirectoryContentsDriveSearch( | |
755 this.context_, this.directoryEntry_, | |
756 this.previousDirectoryEntry_, this.query_); | |
757 }; | 704 }; |
758 | 705 |
759 /** | 706 /** |
760 * @return {boolean} True if this is search results (yes). | 707 * Creates a DirectoryContents instance to show the result of the search on |
708 * Drive File System. | |
709 * @param {FileListContext} context File list context. | |
710 * @param {DirectoryEntry} directoryEntry The current directory entry. | |
711 * @param {DirectoryEntry} previousDirectoryEntry The DirectoryEntry that was | |
712 * current before the search. | |
713 * @param {string} query Search query. | |
714 * @return {DirectoryContents} Created DirectoryContents instance. | |
761 */ | 715 */ |
762 DirectoryContentsDriveSearch.prototype.isSearch = function() { | 716 DirectoryContents.createForDriveSearch = function( |
763 return true; | 717 context, directoryEntry, previousDirectoryEntry, query) { |
718 return new DirectoryContents( | |
719 context, | |
720 true, // Search. | |
721 directoryEntry, | |
722 previousDirectoryEntry, | |
723 function() { | |
724 return new DriveSearchContentScanner(query); | |
725 }); | |
764 }; | 726 }; |
765 | 727 |
766 /** | 728 /** |
767 * @return {DirectoryEntry} A DirectoryEntry for the top directory from which | 729 * Creates a DirectoryContents instance to show the result of the search on |
768 * search is run (i.e. drive root). | 730 * Local File System. |
731 * @param {FileListContext} context File list context. | |
732 * @param {DirectoryEntry} directoryEntry The current directory entry. | |
733 * @param {string} query Search query. | |
734 * @return {DirectoryContents} Created DirectoryContents instance. | |
769 */ | 735 */ |
770 DirectoryContentsDriveSearch.prototype.getDirectoryEntry = function() { | 736 DirectoryContents.createForLocalSearch = function( |
771 return this.directoryEntry_; | 737 context, directoryEntry, query) { |
738 return new DirectoryContents( | |
739 context, | |
740 true, // Search. | |
741 directoryEntry, | |
742 directoryEntry, | |
743 function() { | |
744 return new LocalSearchContentScanner(directoryEntry, query); | |
745 }); | |
772 }; | 746 }; |
773 | 747 |
774 /** | 748 /** |
775 * @return {DirectoryEntry} DirectoryEntry for the directory that was current | 749 * Creates a DirectoryContents instance to show the result of metadata search |
776 * before the search. | 750 * on Drive File System. |
mtomasz
2013/10/01 02:38:12
nit: Please add a new line after the description f
hidehiko
2013/10/01 07:38:55
Done.
| |
751 * @param {FileListContext} context File list context. | |
752 * @param {DirectoryEntry} fakeDirectoryEntry Fake directory entry representing | |
753 * the set of result entries. This serves as a top directory for the | |
754 * search. | |
755 * @param {DirectoryEntry} driveDirectoryEntry Directory for the actual drive. | |
756 * @param {string} query Search query. | |
757 * @param {DriveMetadataSearchContentScanner.SearchType} searchType The type of | |
758 * the search. The scanner will restricts the entries based on the given | |
759 * type. | |
760 * @return {DirectoryContents} Created DirectoryContents instance. | |
777 */ | 761 */ |
778 DirectoryContentsDriveSearch.prototype.getLastNonSearchDirectoryEntry = | 762 DirectoryContents.createForDriveMetadataSearch = function( |
779 function() { | 763 context, fakeDirectoryEntry, driveDirectoryEntry, query, searchType) { |
780 return this.previousDirectoryEntry_; | 764 return new DirectoryContents( |
765 context, | |
766 true, // Search | |
767 fakeDirectoryEntry, | |
768 driveDirectoryEntry, | |
769 function() { | |
770 return new DriveMetadataSearchContentScanner(query, searchType); | |
771 }); | |
781 }; | 772 }; |
782 | |
783 /** | |
784 * Start directory scan. | |
785 */ | |
786 DirectoryContentsDriveSearch.prototype.scan = function() { | |
787 this.scanner_ = new DriveSearchContentScanner(this.query_); | |
788 this.scanner_.startScan(this.onNewEntries.bind(this), | |
789 this.onScanCompleted.bind(this), | |
790 this.onScanError.bind(this)); | |
791 }; | |
792 | |
793 /** | |
794 * @param {FileListContext} context File list context. | |
795 * @param {DirectoryEntry} dirEntry Current directory. | |
796 * @param {string} query Search query. | |
797 * @constructor | |
798 * @extends {DirectoryContents} | |
799 */ | |
800 function DirectoryContentsLocalSearch(context, dirEntry, query) { | |
801 DirectoryContents.call(this, context); | |
802 this.directoryEntry_ = dirEntry; | |
803 this.query_ = query; | |
804 } | |
805 | |
806 /** | |
807 * Extends DirectoryContents | |
808 */ | |
809 DirectoryContentsLocalSearch.prototype.__proto__ = DirectoryContents.prototype; | |
810 | |
811 /** | |
812 * Create the copy of the object, but without scan started. | |
813 * @return {DirectoryContentsBasic} Object copy. | |
814 */ | |
815 DirectoryContentsLocalSearch.prototype.clone = function() { | |
816 return new DirectoryContentsLocalSearch( | |
817 this.context_, this.directoryEntry_, this.query_); | |
818 }; | |
819 | |
820 /** | |
821 * @return {boolean} True if search results (drive or local). | |
822 */ | |
823 DirectoryContentsLocalSearch.prototype.isSearch = function() { | |
824 return true; | |
825 }; | |
826 | |
827 /** | |
828 * @return {DirectoryEntry} A DirectoryEntry for the top directory from which | |
829 * search is run. | |
830 */ | |
831 DirectoryContentsLocalSearch.prototype.getDirectoryEntry = function() { | |
832 return this.directoryEntry_; | |
833 }; | |
834 | |
835 /** | |
836 * @return {DirectoryEntry} DirectoryEntry for current directory (the search is | |
837 * run from the directory that was current before search). | |
838 */ | |
839 DirectoryContentsLocalSearch.prototype.getLastNonSearchDirectoryEntry = | |
840 function() { | |
841 return this.directoryEntry_; | |
842 }; | |
843 | |
844 /** | |
845 * Start directory scan/search operation. Either 'scan-completed' or | |
846 * 'scan-failed' event will be fired upon completion. | |
847 */ | |
848 DirectoryContentsLocalSearch.prototype.scan = function() { | |
849 this.scanner_ = | |
850 new LocalSearchContentScanner(this.directoryEntry_, this.query_); | |
851 this.scanner_.startScan(this.onNewEntries.bind(this), | |
852 this.onScanCompleted.bind(this), | |
853 this.onScanError.bind(this)); | |
854 }; | |
855 | |
856 /** | |
857 * DirectoryContents to list Drive files using searchDriveMetadata(). | |
858 * | |
859 * @param {FileListContext} context File list context. | |
860 * @param {DirectoryEntry} driveDirEntry Directory for actual Drive. | |
861 * @param {DirectoryEntry} fakeDirEntry Fake directory representing the set of | |
862 * result files. This serves as a top directory for this search. | |
863 * @param {string} query Search query to filter the files. | |
864 * @param {DriveMetadataSearchContentScanner.SearchType} searchType | |
865 * Type of search. searchDriveMetadata will restricts the entries based on | |
866 * the given search type. | |
867 * @constructor | |
868 * @extends {DirectoryContents} | |
869 */ | |
870 function DirectoryContentsDriveSearchMetadata(context, | |
871 driveDirEntry, | |
872 fakeDirEntry, | |
873 query, | |
874 searchType) { | |
875 DirectoryContents.call(this, context); | |
876 this.driveDirEntry_ = driveDirEntry; | |
877 this.fakeDirEntry_ = fakeDirEntry; | |
878 this.query_ = query; | |
879 this.searchType_ = searchType; | |
880 } | |
881 | |
882 /** | |
883 * Creates a copy of the object, but without scan started. | |
884 * @return {DirectoryContents} Object copy. | |
885 */ | |
886 DirectoryContentsDriveSearchMetadata.prototype.clone = function() { | |
887 return new DirectoryContentsDriveSearchMetadata( | |
888 this.context_, this.driveDirEntry_, this.fakeDirEntry_, this.query_, | |
889 this.searchType_); | |
890 }; | |
891 | |
892 /** | |
893 * Extends DirectoryContents. | |
894 */ | |
895 DirectoryContentsDriveSearchMetadata.prototype.__proto__ = | |
896 DirectoryContents.prototype; | |
897 | |
898 /** | |
899 * @return {boolean} True if this is search results (yes). | |
900 */ | |
901 DirectoryContentsDriveSearchMetadata.prototype.isSearch = function() { | |
902 return true; | |
903 }; | |
904 | |
905 /** | |
906 * @return {DirectoryEntry} An Entry representing the current contents | |
907 * (i.e. fake root for "Shared with me"). | |
908 */ | |
909 DirectoryContentsDriveSearchMetadata.prototype.getDirectoryEntry = function() { | |
910 return this.fakeDirEntry_; | |
911 }; | |
912 | |
913 /** | |
914 * @return {DirectoryEntry} DirectoryEntry for the directory that was current | |
915 * before the search. | |
916 */ | |
917 DirectoryContentsDriveSearchMetadata.prototype.getLastNonSearchDirectoryEntry = | |
918 function() { | |
919 return this.driveDirEntry_; | |
920 }; | |
921 | |
922 /** | |
923 * Start directory scan/search operation. Either 'scan-completed' or | |
924 * 'scan-failed' event will be fired upon completion. | |
925 */ | |
926 DirectoryContentsDriveSearchMetadata.prototype.scan = function() { | |
927 this.scanner_ = | |
928 new DriveMetadataSearchContentScanner(this.query_, this.searchType_); | |
929 this.scanner_.startScan(this.onNewEntries.bind(this), | |
930 this.onScanCompleted.bind(this), | |
931 this.onScanError.bind(this)); | |
932 }; | |
OLD | NEW |