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