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

Side by Side Diff: chrome/browser/resources/file_manager/js/directory_contents.js

Issue 25263003: Refactor DirectoryContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/resources/file_manager/js/directory_model.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 * Scanner of the entries. 8 * Scanner of the entries.
9 * @constructor 9 * @constructor
10 */ 10 */
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.
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
59 * completion.
60 * @param {function()} successCallback Called when the scan is completed
61 * successfully.
62 * @param {function(FileError)} errorCallback Called an error occurs.
63 * @override 57 * @override
64 */ 58 */
65 DirectoryContentScanner.prototype.scan = function( 59 DirectoryContentScanner.prototype.scan = function(
66 entriesCallback, successCallback, errorCallback) { 60 entriesCallback, successCallback, errorCallback) {
67 if (!this.entry_ || this.entry_ === DirectoryModel.fakeDriveEntry_) { 61 if (!this.entry_ || this.entry_ === DirectoryModel.fakeDriveEntry_) {
68 // If entry is not specified or a fake, we cannot read it. 62 // If entry is not specified or a fake, we cannot read it.
69 errorCallback(util.createFileError(FileError.INVALID_MODIFICATION_ERR)); 63 errorCallback(util.createFileError(FileError.INVALID_MODIFICATION_ERR));
70 return; 64 return;
71 } 65 }
72 66
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 /** 117 /**
124 * Maximum number of results which is shown on the search. 118 * Maximum number of results which is shown on the search.
125 * @type {number} 119 * @type {number}
126 * @private 120 * @private
127 * @const 121 * @const
128 */ 122 */
129 DriveSearchContentScanner.MAX_RESULTS_ = 100; 123 DriveSearchContentScanner.MAX_RESULTS_ = 100;
130 124
131 /** 125 /**
132 * Starts to search on Drive File System. 126 * Starts to search on Drive File System.
133 * @param {function(Array.<Entry>)} entriesCallback Called when some chunk of
134 * entries are read. This can be called a couple of times until the
135 * completion.
136 * @param {function()} successCallback Called when the scan is completed
137 * successfully.
138 * @param {function(FileError)} errorCallback Called an error occurs.
139 * @override 127 * @override
140 */ 128 */
141 DriveSearchContentScanner.prototype.scan = function( 129 DriveSearchContentScanner.prototype.scan = function(
142 entriesCallback, successCallback, errorCallback) { 130 entriesCallback, successCallback, errorCallback) {
143 var numReadEntries = 0; 131 var numReadEntries = 0;
144 var readEntries = function(nextFeed) { 132 var readEntries = function(nextFeed) {
145 chrome.fileBrowserPrivate.searchDrive( 133 chrome.fileBrowserPrivate.searchDrive(
146 {query: this.query_, nextFeed: nextFeed}, 134 {query: this.query_, nextFeed: nextFeed},
147 function(entries, nextFeed) { 135 function(entries, nextFeed) {
148 if (this.cancelled_) { 136 if (this.cancelled_) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 this.query_ = query.toLowerCase(); 192 this.query_ = query.toLowerCase();
205 } 193 }
206 194
207 /** 195 /**
208 * Extedns ContentScanner. 196 * Extedns ContentScanner.
209 */ 197 */
210 LocalSearchContentScanner.prototype.__proto__ = ContentScanner.prototype; 198 LocalSearchContentScanner.prototype.__proto__ = ContentScanner.prototype;
211 199
212 /** 200 /**
213 * Starts the file name search. 201 * Starts the file name search.
214 * @param {function(Array.<Entry>)} entriesCallback Called when some chunk of
215 * entries are read. This can be called a couple of times until the
216 * completion.
217 * @param {function()} successCallback Called when the scan is completed
218 * successfully.
219 * @param {function(FileError)} errorCallback Called an error occurs.
220 * @override 202 * @override
221 */ 203 */
222 LocalSearchContentScanner.prototype.scan = function( 204 LocalSearchContentScanner.prototype.scan = function(
223 entriesCallback, successCallback, errorCallback) { 205 entriesCallback, successCallback, errorCallback) {
224 var numRunningTasks = 0; 206 var numRunningTasks = 0;
225 var error = null; 207 var error = null;
226 var maybeRunCallback = function() { 208 var maybeRunCallback = function() {
227 if (numRunningTasks === 0) { 209 if (numRunningTasks === 0) {
228 if (this.cancelled_) 210 if (this.cancelled_)
229 errorCallback(util.createFileError(FileError.ABORT_ERR)); 211 errorCallback(util.createFileError(FileError.ABORT_ERR));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 */ 282 */
301 DriveMetadataSearchContentScanner.SearchType = Object.freeze({ 283 DriveMetadataSearchContentScanner.SearchType = Object.freeze({
302 SEARCH_ALL: 'ALL', 284 SEARCH_ALL: 'ALL',
303 SEARCH_SHARED_WITH_ME: 'SHARED_WITH_ME', 285 SEARCH_SHARED_WITH_ME: 'SHARED_WITH_ME',
304 SEARCH_RECENT_FILES: 'EXCLUDE_DIRECTORIES', 286 SEARCH_RECENT_FILES: 'EXCLUDE_DIRECTORIES',
305 SEARCH_OFFLINE: 'OFFLINE' 287 SEARCH_OFFLINE: 'OFFLINE'
306 }); 288 });
307 289
308 /** 290 /**
309 * Starts to metadata-search on Drive File System. 291 * Starts to metadata-search on Drive File System.
310 * @param {function(Array.<Entry>)} entriesCallback Called when some chunk of
311 * entries are read. This can be called a couple of times until the
312 * completion.
313 * @param {function()} successCallback Called when the scan is completed
314 * successfully.
315 * @param {function(FileError)} errorCallback Called an error occurs.
316 * @override 292 * @override
317 */ 293 */
318 DriveMetadataSearchContentScanner.prototype.scan = function( 294 DriveMetadataSearchContentScanner.prototype.scan = function(
319 entriesCallback, successCallback, errorCallback) { 295 entriesCallback, successCallback, errorCallback) {
320 chrome.fileBrowserPrivate.searchDriveMetadata( 296 chrome.fileBrowserPrivate.searchDriveMetadata(
321 {query: this.query_, types: this.searchType_, maxResults: 500}, 297 {query: this.query_, types: this.searchType_, maxResults: 500},
322 function(results) { 298 function(results) {
323 if (this.cancelled_) { 299 if (this.cancelled_) {
324 errorCallback(util.createFileError(FileError.ABORT_ERR)); 300 errorCallback(util.createFileError(FileError.ABORT_ERR));
325 return; 301 return;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 * @type {FileFilter} 424 * @type {FileFilter}
449 */ 425 */
450 this.fileFilter = fileFilter; 426 this.fileFilter = fileFilter;
451 } 427 }
452 428
453 /** 429 /**
454 * This class is responsible for scanning directory (or search results), 430 * This class is responsible for scanning directory (or search results),
455 * and filling the fileList. Different descendants handle various types of 431 * and filling the fileList. Different descendants handle various types of
456 * directory contents shown: basic directory, drive search results, local search 432 * directory contents shown: basic directory, drive search results, local search
457 * results. 433 * results.
434 * TODO(hidehiko): Remove EventTarget from this.
435 *
458 * @param {FileListContext} context The file list context. 436 * @param {FileListContext} context The file list context.
437 * @param {boolean} isSearch True for search directory contents, otherwise
438 * false.
439 * @param {DirectoryEntry} directoryEntry The entry of the current directory.
440 * @param {DirectoryEntry} lastNonSearchDirectoryEntry The entry of the last
441 * non-search directroy.
442 * @param {function():ContentScanner} scannerFactory The factory to create
443 * ContentScanner instance.
459 * @constructor 444 * @constructor
460 * @extends {cr.EventTarget} 445 * @extends {cr.EventTarget}
461 */ 446 */
462 function DirectoryContents(context) { 447 function DirectoryContents(context, isSearch, directoryEntry,
448 lastNonSearchDirectoryEntry,
449 scannerFactory) {
463 this.context_ = context; 450 this.context_ = context;
464 this.fileList_ = context.fileList; 451 this.fileList_ = context.fileList;
452
453 this.isSearch_ = isSearch;
454 this.directoryEntry_ = directoryEntry;
455 this.lastNonSearchDirectoryEntry_ = lastNonSearchDirectoryEntry;
456
457 this.scannerFactory_ = scannerFactory;
458 this.scanner_ = null;
465 this.prefetchMetadataQueue_ = new AsyncUtil.Queue(); 459 this.prefetchMetadataQueue_ = new AsyncUtil.Queue();
466 this.scanCancelled_ = false; 460 this.scanCancelled_ = false;
467 this.fileList_.prepareSort = this.prepareSort_.bind(this); 461 this.fileList_.prepareSort = this.prepareSort_.bind(this);
468 } 462 }
469 463
470 /** 464 /**
471 * DirectoryContents extends cr.EventTarget. 465 * DirectoryContents extends cr.EventTarget.
472 */ 466 */
473 DirectoryContents.prototype.__proto__ = cr.EventTarget.prototype; 467 DirectoryContents.prototype.__proto__ = cr.EventTarget.prototype;
474 468
475 /** 469 /**
476 * Create the copy of the object, but without scan started. 470 * Create the copy of the object, but without scan started.
477 * @return {DirectoryContents} Object copy. 471 * @return {DirectoryContents} Object copy.
478 */ 472 */
479 DirectoryContents.prototype.clone = function() { 473 DirectoryContents.prototype.clone = function() {
480 return new DirectoryContents(this.context_); 474 return new DirectoryContents(
475 this.context_, this.isSearch_, this.directoryEntry_,
476 this.lastNonSearchDirectoryEntry_, this.scannerFactory_);
481 }; 477 };
482 478
483 /** 479 /**
484 * Use a given fileList instead of the fileList from the context. 480 * Use a given fileList instead of the fileList from the context.
485 * @param {Array|cr.ui.ArrayDataModel} fileList The new file list. 481 * @param {Array|cr.ui.ArrayDataModel} fileList The new file list.
486 */ 482 */
487 DirectoryContents.prototype.setFileList = function(fileList) { 483 DirectoryContents.prototype.setFileList = function(fileList) {
488 this.fileList_ = fileList; 484 this.fileList_ = fileList;
489 this.fileList_.prepareSort = this.prepareSort_.bind(this); 485 this.fileList_.prepareSort = this.prepareSort_.bind(this);
490 }; 486 };
(...skipping 16 matching lines...) Expand all
507 * @return {boolean} If the scan is active. 503 * @return {boolean} If the scan is active.
508 */ 504 */
509 DirectoryContents.prototype.isScanning = function() { 505 DirectoryContents.prototype.isScanning = function() {
510 return this.scanner_ || this.prefetchMetadataQueue_.isRunning(); 506 return this.scanner_ || this.prefetchMetadataQueue_.isRunning();
511 }; 507 };
512 508
513 /** 509 /**
514 * @return {boolean} True if search results (drive or local). 510 * @return {boolean} True if search results (drive or local).
515 */ 511 */
516 DirectoryContents.prototype.isSearch = function() { 512 DirectoryContents.prototype.isSearch = function() {
517 return false; 513 return this.isSearch_;
518 }; 514 };
519 515
520 /** 516 /**
521 * @return {DirectoryEntry} A DirectoryEntry for current directory. In case of 517 * @return {DirectoryEntry} A DirectoryEntry for current directory. In case of
522 * search -- the top directory from which search is run. 518 * search -- the top directory from which search is run.
523 */ 519 */
524 DirectoryContents.prototype.getDirectoryEntry = function() { 520 DirectoryContents.prototype.getDirectoryEntry = function() {
525 throw 'Not implemented.'; 521 return this.directoryEntry_;
526 }; 522 };
527 523
528 /** 524 /**
529 * @return {DirectoryEntry} A DirectoryEntry for the last non search contents. 525 * @return {DirectoryEntry} A DirectoryEntry for the last non search contents.
530 */ 526 */
531 DirectoryContents.prototype.getLastNonSearchDirectoryEntry = function() { 527 DirectoryContents.prototype.getLastNonSearchDirectoryEntry = function() {
532 throw 'Not implemented.'; 528 return this.lastNonSearchDirectoryEntry_;
533 }; 529 };
534 530
535 /** 531 /**
536 * Start directory scan/search operation. Either 'scan-completed' or 532 * Start directory scan/search operation. Either 'scan-completed' or
537 * 'scan-failed' event will be fired upon completion. 533 * 'scan-failed' event will be fired upon completion.
538 */ 534 */
539 DirectoryContents.prototype.scan = function() { 535 DirectoryContents.prototype.scan = function() {
540 throw 'Not implemented.'; 536 // TODO(hidehiko,mtomasz): this scan method must be called at most once.
537 // Remove such a limitation.
538 this.scanner_ = this.scannerFactory_();
539 this.scanner_.scan(this.onNewEntries_.bind(this),
540 this.onScanCompleted_.bind(this),
541 this.onScanError_.bind(this));
541 }; 542 };
542 543
543 /** 544 /**
544 * Cancels the running scan. 545 * Cancels the running scan.
545 */ 546 */
546 DirectoryContents.prototype.cancelScan = function() { 547 DirectoryContents.prototype.cancelScan = function() {
547 if (this.scanCancelled_) 548 if (this.scanCancelled_)
548 return; 549 return;
549 this.scanCancelled_ = true; 550 this.scanCancelled_ = true;
550 if (this.scanner_) 551 if (this.scanner_)
551 this.scanner_.cancel(); 552 this.scanner_.cancel();
552 553
553 this.prefetchMetadataQueue_.cancel(); 554 this.prefetchMetadataQueue_.cancel();
554 cr.dispatchSimpleEvent(this, 'scan-cancelled'); 555 cr.dispatchSimpleEvent(this, 'scan-cancelled');
555 }; 556 };
556 557
557 /** 558 /**
558 * Called when the scanning by scanner_ is done. 559 * Called when the scanning by scanner_ is done.
559 * @protected 560 * @private
560 */ 561 */
561 DirectoryContents.prototype.onScanCompleted = function() { 562 DirectoryContents.prototype.onScanCompleted_ = function() {
562 this.scanner_ = null; 563 this.scanner_ = null;
563 if (this.scanCancelled_) 564 if (this.scanCancelled_)
564 return; 565 return;
565 566
566 this.prefetchMetadataQueue_.run(function(callback) { 567 this.prefetchMetadataQueue_.run(function(callback) {
567 cr.dispatchSimpleEvent(this, 'scan-completed'); 568 cr.dispatchSimpleEvent(this, 'scan-completed');
568 if (!this.isSearch() && 569 if (!this.isSearch() &&
569 this.getDirectoryEntry().fullPath === RootDirectory.DOWNLOADS) 570 this.getDirectoryEntry().fullPath === RootDirectory.DOWNLOADS)
570 metrics.recordMediumCount('DownloadsCount', this.fileList_.length); 571 metrics.recordMediumCount('DownloadsCount', this.fileList_.length);
571 callback(); 572 callback();
572 }.bind(this)); 573 }.bind(this));
573 }; 574 };
574 575
575 /** 576 /**
576 * Called in case scan has failed. Should send the event. 577 * Called in case scan has failed. Should send the event.
577 * @protected 578 * @private
578 */ 579 */
579 DirectoryContents.prototype.onScanError = function() { 580 DirectoryContents.prototype.onScanError_ = function() {
580 this.scanner_ = null; 581 this.scanner_ = null;
581 if (this.scanCancelled_) 582 if (this.scanCancelled_)
582 return; 583 return;
583 584
584 this.prefetchMetadataQueue_.run(function(callback) { 585 this.prefetchMetadataQueue_.run(function(callback) {
585 cr.dispatchSimpleEvent(this, 'scan-failed'); 586 cr.dispatchSimpleEvent(this, 'scan-failed');
586 callback(); 587 callback();
587 }.bind(this)); 588 }.bind(this));
588 }; 589 };
589 590
590 /** 591 /**
591 * Called when some chunk of entries are read by scanner. 592 * Called when some chunk of entries are read by scanner.
592 * @param {Array.<Entry>} entries The list of the scanned entries. 593 * @param {Array.<Entry>} entries The list of the scanned entries.
593 * @protected 594 * @private
594 */ 595 */
595 DirectoryContents.prototype.onNewEntries = function(entries) { 596 DirectoryContents.prototype.onNewEntries_ = function(entries) {
596 if (this.scanCancelled_) 597 if (this.scanCancelled_)
597 return; 598 return;
598 599
599 var entriesFiltered = [].filter.call( 600 var entriesFiltered = [].filter.call(
600 entries, this.context_.fileFilter.filter.bind(this.context_.fileFilter)); 601 entries, this.context_.fileFilter.filter.bind(this.context_.fileFilter));
601 602
602 // Because the prefetchMetadata can be slow, throttling by splitting entries 603 // Because the prefetchMetadata can be slow, throttling by splitting entries
603 // into smaller chunks to reduce UI latency. 604 // into smaller chunks to reduce UI latency.
604 // TODO(hidehiko,mtomasz): This should be handled in MetadataCache. 605 // TODO(hidehiko,mtomasz): This should be handled in MetadataCache.
605 var MAX_CHUNK_SIZE = 50; 606 var MAX_CHUNK_SIZE = 50;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 this.context_.metadataCache.get(entries, 'filesystem', callback); 652 this.context_.metadataCache.get(entries, 'filesystem', callback);
652 }; 653 };
653 654
654 /** 655 /**
655 * @param {string} name Directory name. 656 * @param {string} name Directory name.
656 * @param {function(DirectoryEntry)} successCallback Called on success. 657 * @param {function(DirectoryEntry)} successCallback Called on success.
657 * @param {function(FileError)} errorCallback On error. 658 * @param {function(FileError)} errorCallback On error.
658 */ 659 */
659 DirectoryContents.prototype.createDirectory = function( 660 DirectoryContents.prototype.createDirectory = function(
660 name, successCallback, errorCallback) { 661 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 662 // TODO(hidehiko): createDirectory should not be the part of
723 // DirectoryContent. 663 // DirectoryContent.
724 if (!this.entry_) { 664 if (this.isSearch_ || !this.directoryEntry_) {
725 errorCallback(util.createFileError(FileError.INVALID_MODIFICATION_ERR)); 665 errorCallback(util.createFileError(FileError.INVALID_MODIFICATION_ERR));
726 return; 666 return;
727 } 667 }
728 668
729 var onSuccess = function(newEntry) { 669 var onSuccess = function(newEntry) {
730 this.reloadMetadata([newEntry], function() { 670 this.reloadMetadata([newEntry], function() {
731 successCallback(newEntry); 671 successCallback(newEntry);
732 }); 672 });
733 }; 673 };
734 674
735 this.entry_.getDirectory(name, {create: true, exclusive: true}, 675 this.directoryEntry_.getDirectory(name, {create: true, exclusive: true},
736 onSuccess.bind(this), errorCallback); 676 onSuccess.bind(this), errorCallback);
737 }; 677 };
738 678
739 /** 679 /**
680 * Creates a DirectoryContents instance to show entries in a directory.
681 *
740 * @param {FileListContext} context File list context. 682 * @param {FileListContext} context File list context.
741 * @param {DirectoryEntry} dirEntry Current directory. 683 * @param {DirectoryEntry} directoryEntry The current directory entry.
742 * @param {DirectoryEntry} previousDirEntry DirectoryEntry that was current 684 * @return {DirectoryContents} Created DirectoryContents instance.
743 * before the search.
744 * @param {string} query Search query.
745 * @constructor
746 * @extends {DirectoryContents}
747 */ 685 */
748 function DirectoryContentsDriveSearch(context, 686 DirectoryContents.createForDirectory = function(context, directoryEntry) {
749 dirEntry, 687 return new DirectoryContents(
750 previousDirEntry, 688 context,
751 query) { 689 false, // Non search.
752 DirectoryContents.call(this, context); 690 directoryEntry,
753 this.directoryEntry_ = dirEntry; 691 directoryEntry,
754 this.previousDirectoryEntry_ = previousDirEntry; 692 function() {
755 this.query_ = query; 693 return new DirectoryContentScanner(directoryEntry);
756 } 694 });
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 }; 695 };
772 696
773 /** 697 /**
774 * @return {boolean} True if this is search results (yes). 698 * Creates a DirectoryContents instance to show the result of the search on
699 * Drive File System.
700 *
701 * @param {FileListContext} context File list context.
702 * @param {DirectoryEntry} directoryEntry The current directory entry.
703 * @param {DirectoryEntry} previousDirectoryEntry The DirectoryEntry that was
704 * current before the search.
705 * @param {string} query Search query.
706 * @return {DirectoryContents} Created DirectoryContents instance.
775 */ 707 */
776 DirectoryContentsDriveSearch.prototype.isSearch = function() { 708 DirectoryContents.createForDriveSearch = function(
777 return true; 709 context, directoryEntry, previousDirectoryEntry, query) {
710 return new DirectoryContents(
711 context,
712 true, // Search.
713 directoryEntry,
714 previousDirectoryEntry,
715 function() {
716 return new DriveSearchContentScanner(query);
717 });
778 }; 718 };
779 719
780 /** 720 /**
781 * @return {DirectoryEntry} A DirectoryEntry for the top directory from which 721 * Creates a DirectoryContents instance to show the result of the search on
782 * search is run (i.e. drive root). 722 * Local File System.
723 *
724 * @param {FileListContext} context File list context.
725 * @param {DirectoryEntry} directoryEntry The current directory entry.
726 * @param {string} query Search query.
727 * @return {DirectoryContents} Created DirectoryContents instance.
783 */ 728 */
784 DirectoryContentsDriveSearch.prototype.getDirectoryEntry = function() { 729 DirectoryContents.createForLocalSearch = function(
785 return this.directoryEntry_; 730 context, directoryEntry, query) {
731 return new DirectoryContents(
732 context,
733 true, // Search.
734 directoryEntry,
735 directoryEntry,
736 function() {
737 return new LocalSearchContentScanner(directoryEntry, query);
738 });
786 }; 739 };
787 740
788 /** 741 /**
789 * @return {DirectoryEntry} DirectoryEntry for the directory that was current 742 * Creates a DirectoryContents instance to show the result of metadata search
790 * before the search. 743 * 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 * 744 *
873 * @param {FileListContext} context File list context. 745 * @param {FileListContext} context File list context.
874 * @param {DirectoryEntry} driveDirEntry Directory for actual Drive. 746 * @param {DirectoryEntry} fakeDirectoryEntry Fake directory entry representing
875 * @param {DirectoryEntry} fakeDirEntry Fake directory representing the set of 747 * 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. 748 * search.
877 * @param {string} query Search query to filter the files. 749 * @param {DirectoryEntry} driveDirectoryEntry Directory for the actual drive.
878 * @param {DriveMetadataSearchContentScanner.SearchType} searchType 750 * @param {string} query Search query.
879 * Type of search. searchDriveMetadata will restricts the entries based on 751 * @param {DriveMetadataSearchContentScanner.SearchType} searchType The type of
880 * the given search type. 752 * the search. The scanner will restricts the entries based on the given
881 * @constructor 753 * type.
882 * @extends {DirectoryContents} 754 * @return {DirectoryContents} Created DirectoryContents instance.
883 */ 755 */
884 function DirectoryContentsDriveSearchMetadata(context, 756 DirectoryContents.createForDriveMetadataSearch = function(
885 driveDirEntry, 757 context, fakeDirectoryEntry, driveDirectoryEntry, query, searchType) {
886 fakeDirEntry, 758 return new DirectoryContents(
887 query, 759 context,
888 searchType) { 760 true, // Search
889 DirectoryContents.call(this, context); 761 fakeDirectoryEntry,
890 this.driveDirEntry_ = driveDirEntry; 762 driveDirectoryEntry,
891 this.fakeDirEntry_ = fakeDirEntry; 763 function() {
892 this.query_ = query; 764 return new DriveMetadataSearchContentScanner(query, searchType);
893 this.searchType_ = searchType; 765 });
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 }; 766 };
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 };
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/file_manager/js/directory_model.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698