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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 254 |
255 var reader = entry.createReader(); | 255 var reader = entry.createReader(); |
256 reader.readEntries(onSuccess, onError); | 256 reader.readEntries(onSuccess, onError); |
257 }.bind(this); | 257 }.bind(this); |
258 | 258 |
259 processEntry(this.entry_); | 259 processEntry(this.entry_); |
260 }; | 260 }; |
261 | 261 |
262 /** | 262 /** |
263 * Scanner of the entries for the metadata search on Drive File System. | 263 * Scanner of the entries for the metadata search on Drive File System. |
264 * @param {string} query The query of the search. | |
265 * @param {DriveMetadataSearchContentScanner.SearchType} searchType The option | 264 * @param {DriveMetadataSearchContentScanner.SearchType} searchType The option |
266 * of the search. | 265 * of the search. |
267 * @constructor | 266 * @constructor |
268 * @extends {ContentScanner} | 267 * @extends {ContentScanner} |
269 */ | 268 */ |
270 function DriveMetadataSearchContentScanner(query, searchType) { | 269 function DriveMetadataSearchContentScanner(searchType) { |
271 ContentScanner.call(this); | 270 ContentScanner.call(this); |
272 this.query_ = query; | |
273 this.searchType_ = searchType; | 271 this.searchType_ = searchType; |
274 } | 272 } |
275 | 273 |
276 /** | 274 /** |
277 * Extends ContentScanner. | 275 * Extends ContentScanner. |
278 */ | 276 */ |
279 DriveMetadataSearchContentScanner.prototype.__proto__ = | 277 DriveMetadataSearchContentScanner.prototype.__proto__ = |
280 ContentScanner.prototype; | 278 ContentScanner.prototype; |
281 | 279 |
282 /** | 280 /** |
283 * The search types on the Drive File System. | 281 * The search types on the Drive File System. |
284 * @enum {string} | 282 * @enum {string} |
285 */ | 283 */ |
286 DriveMetadataSearchContentScanner.SearchType = Object.freeze({ | 284 DriveMetadataSearchContentScanner.SearchType = Object.freeze({ |
287 SEARCH_ALL: 'ALL', | 285 SEARCH_ALL: 'ALL', |
288 SEARCH_SHARED_WITH_ME: 'SHARED_WITH_ME', | 286 SEARCH_SHARED_WITH_ME: 'SHARED_WITH_ME', |
289 SEARCH_RECENT_FILES: 'EXCLUDE_DIRECTORIES', | 287 SEARCH_RECENT_FILES: 'EXCLUDE_DIRECTORIES', |
290 SEARCH_OFFLINE: 'OFFLINE' | 288 SEARCH_OFFLINE: 'OFFLINE' |
291 }); | 289 }); |
292 | 290 |
293 /** | 291 /** |
294 * Starts to metadata-search on Drive File System. | 292 * Starts to metadata-search on Drive File System. |
295 * @override | 293 * @override |
296 */ | 294 */ |
297 DriveMetadataSearchContentScanner.prototype.scan = function( | 295 DriveMetadataSearchContentScanner.prototype.scan = function( |
298 entriesCallback, successCallback, errorCallback) { | 296 entriesCallback, successCallback, errorCallback) { |
299 chrome.fileBrowserPrivate.searchDriveMetadata( | 297 chrome.fileBrowserPrivate.searchDriveMetadata( |
300 {query: this.query_, types: this.searchType_, maxResults: 500}, | 298 {query: '', types: this.searchType_, maxResults: 500}, |
301 function(results) { | 299 function(results) { |
302 if (this.cancelled_) { | 300 if (this.cancelled_) { |
303 errorCallback(util.createDOMError(util.FileError.ABORT_ERR)); | 301 errorCallback(util.createDOMError(util.FileError.ABORT_ERR)); |
304 return; | 302 return; |
305 } | 303 } |
306 | 304 |
307 if (!results) { | 305 if (!results) { |
308 console.error('Drive search encountered an error.'); | 306 console.error('Drive search encountered an error.'); |
309 errorCallback(util.createDOMError( | 307 errorCallback(util.createDOMError( |
310 util.FileError.INVALID_MODIFICATION_ERR)); | 308 util.FileError.INVALID_MODIFICATION_ERR)); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 * This class is responsible for scanning directory (or search results), | 457 * This class is responsible for scanning directory (or search results), |
460 * and filling the fileList. Different descendants handle various types of | 458 * and filling the fileList. Different descendants handle various types of |
461 * directory contents shown: basic directory, drive search results, local search | 459 * directory contents shown: basic directory, drive search results, local search |
462 * results. | 460 * results. |
463 * TODO(hidehiko): Remove EventTarget from this. | 461 * TODO(hidehiko): Remove EventTarget from this. |
464 * | 462 * |
465 * @param {FileListContext} context The file list context. | 463 * @param {FileListContext} context The file list context. |
466 * @param {boolean} isSearch True for search directory contents, otherwise | 464 * @param {boolean} isSearch True for search directory contents, otherwise |
467 * false. | 465 * false. |
468 * @param {DirectoryEntry} directoryEntry The entry of the current directory. | 466 * @param {DirectoryEntry} directoryEntry The entry of the current directory. |
469 * @param {DirectoryEntry} lastNonSearchDirectoryEntry The entry of the last | |
470 * non-search directory. | |
471 * @param {function():ContentScanner} scannerFactory The factory to create | 467 * @param {function():ContentScanner} scannerFactory The factory to create |
472 * ContentScanner instance. | 468 * ContentScanner instance. |
473 * @constructor | 469 * @constructor |
474 * @extends {cr.EventTarget} | 470 * @extends {cr.EventTarget} |
475 */ | 471 */ |
476 function DirectoryContents(context, | 472 function DirectoryContents(context, |
477 isSearch, | 473 isSearch, |
478 directoryEntry, | 474 directoryEntry, |
479 lastNonSearchDirectoryEntry, | |
480 scannerFactory) { | 475 scannerFactory) { |
481 this.context_ = context; | 476 this.context_ = context; |
482 this.fileList_ = context.fileList; | 477 this.fileList_ = context.fileList; |
483 | 478 |
484 this.isSearch_ = isSearch; | 479 this.isSearch_ = isSearch; |
485 this.directoryEntry_ = directoryEntry; | 480 this.directoryEntry_ = directoryEntry; |
486 this.lastNonSearchDirectoryEntry_ = lastNonSearchDirectoryEntry; | |
487 | 481 |
488 this.scannerFactory_ = scannerFactory; | 482 this.scannerFactory_ = scannerFactory; |
489 this.scanner_ = null; | 483 this.scanner_ = null; |
490 this.prefetchMetadataQueue_ = new AsyncUtil.Queue(); | 484 this.prefetchMetadataQueue_ = new AsyncUtil.Queue(); |
491 this.scanCancelled_ = false; | 485 this.scanCancelled_ = false; |
492 } | 486 } |
493 | 487 |
494 /** | 488 /** |
495 * DirectoryContents extends cr.EventTarget. | 489 * DirectoryContents extends cr.EventTarget. |
496 */ | 490 */ |
497 DirectoryContents.prototype.__proto__ = cr.EventTarget.prototype; | 491 DirectoryContents.prototype.__proto__ = cr.EventTarget.prototype; |
498 | 492 |
499 /** | 493 /** |
500 * Create the copy of the object, but without scan started. | 494 * Create the copy of the object, but without scan started. |
501 * @return {DirectoryContents} Object copy. | 495 * @return {DirectoryContents} Object copy. |
502 */ | 496 */ |
503 DirectoryContents.prototype.clone = function() { | 497 DirectoryContents.prototype.clone = function() { |
504 return new DirectoryContents( | 498 return new DirectoryContents( |
505 this.context_, this.isSearch_, this.directoryEntry_, | 499 this.context_, |
506 this.lastNonSearchDirectoryEntry_, this.scannerFactory_); | 500 this.isSearch_, |
| 501 this.directoryEntry_, |
| 502 this.scannerFactory_); |
507 }; | 503 }; |
508 | 504 |
509 /** | 505 /** |
510 * Use a given fileList instead of the fileList from the context. | 506 * Use a given fileList instead of the fileList from the context. |
511 * @param {Array|cr.ui.ArrayDataModel} fileList The new file list. | 507 * @param {Array|cr.ui.ArrayDataModel} fileList The new file list. |
512 */ | 508 */ |
513 DirectoryContents.prototype.setFileList = function(fileList) { | 509 DirectoryContents.prototype.setFileList = function(fileList) { |
514 if (fileList instanceof cr.ui.ArrayDataModel) | 510 if (fileList instanceof cr.ui.ArrayDataModel) |
515 this.fileList_ = fileList; | 511 this.fileList_ = fileList; |
516 else | 512 else |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 | 545 |
550 /** | 546 /** |
551 * @return {DirectoryEntry} A DirectoryEntry for current directory. In case of | 547 * @return {DirectoryEntry} A DirectoryEntry for current directory. In case of |
552 * search -- the top directory from which search is run. | 548 * search -- the top directory from which search is run. |
553 */ | 549 */ |
554 DirectoryContents.prototype.getDirectoryEntry = function() { | 550 DirectoryContents.prototype.getDirectoryEntry = function() { |
555 return this.directoryEntry_; | 551 return this.directoryEntry_; |
556 }; | 552 }; |
557 | 553 |
558 /** | 554 /** |
559 * @return {DirectoryEntry} A DirectoryEntry for the last non search contents. | |
560 */ | |
561 DirectoryContents.prototype.getLastNonSearchDirectoryEntry = function() { | |
562 return this.lastNonSearchDirectoryEntry_; | |
563 }; | |
564 | |
565 /** | |
566 * Start directory scan/search operation. Either 'scan-completed' or | 555 * Start directory scan/search operation. Either 'scan-completed' or |
567 * 'scan-failed' event will be fired upon completion. | 556 * 'scan-failed' event will be fired upon completion. |
568 */ | 557 */ |
569 DirectoryContents.prototype.scan = function() { | 558 DirectoryContents.prototype.scan = function() { |
570 // TODO(hidehiko,mtomasz): this scan method must be called at most once. | 559 // TODO(hidehiko,mtomasz): this scan method must be called at most once. |
571 // Remove such a limitation. | 560 // Remove such a limitation. |
572 this.scanner_ = this.scannerFactory_(); | 561 this.scanner_ = this.scannerFactory_(); |
573 this.scanner_.scan(this.onNewEntries_.bind(this), | 562 this.scanner_.scan(this.onNewEntries_.bind(this), |
574 this.onScanCompleted_.bind(this), | 563 this.onScanCompleted_.bind(this), |
575 this.onScanError_.bind(this)); | 564 this.onScanError_.bind(this)); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 * | 672 * |
684 * @param {FileListContext} context File list context. | 673 * @param {FileListContext} context File list context. |
685 * @param {DirectoryEntry} directoryEntry The current directory entry. | 674 * @param {DirectoryEntry} directoryEntry The current directory entry. |
686 * @return {DirectoryContents} Created DirectoryContents instance. | 675 * @return {DirectoryContents} Created DirectoryContents instance. |
687 */ | 676 */ |
688 DirectoryContents.createForDirectory = function(context, directoryEntry) { | 677 DirectoryContents.createForDirectory = function(context, directoryEntry) { |
689 return new DirectoryContents( | 678 return new DirectoryContents( |
690 context, | 679 context, |
691 false, // Non search. | 680 false, // Non search. |
692 directoryEntry, | 681 directoryEntry, |
693 directoryEntry, | |
694 function() { | 682 function() { |
695 return new DirectoryContentScanner(directoryEntry); | 683 return new DirectoryContentScanner(directoryEntry); |
696 }); | 684 }); |
697 }; | 685 }; |
698 | 686 |
699 /** | 687 /** |
700 * Creates a DirectoryContents instance to show the result of the search on | 688 * Creates a DirectoryContents instance to show the result of the search on |
701 * Drive File System. | 689 * Drive File System. |
702 * | 690 * |
703 * @param {FileListContext} context File list context. | 691 * @param {FileListContext} context File list context. |
704 * @param {DirectoryEntry} directoryEntry The current directory entry. | 692 * @param {DirectoryEntry} directoryEntry The current directory entry. |
705 * @param {DirectoryEntry} previousDirectoryEntry The DirectoryEntry that was | |
706 * current before the search. | |
707 * @param {string} query Search query. | 693 * @param {string} query Search query. |
708 * @return {DirectoryContents} Created DirectoryContents instance. | 694 * @return {DirectoryContents} Created DirectoryContents instance. |
709 */ | 695 */ |
710 DirectoryContents.createForDriveSearch = function( | 696 DirectoryContents.createForDriveSearch = function( |
711 context, directoryEntry, previousDirectoryEntry, query) { | 697 context, directoryEntry, query) { |
712 return new DirectoryContents( | 698 return new DirectoryContents( |
713 context, | 699 context, |
714 true, // Search. | 700 true, // Search. |
715 directoryEntry, | 701 directoryEntry, |
716 previousDirectoryEntry, | |
717 function() { | 702 function() { |
718 return new DriveSearchContentScanner(query); | 703 return new DriveSearchContentScanner(query); |
719 }); | 704 }); |
720 }; | 705 }; |
721 | 706 |
722 /** | 707 /** |
723 * Creates a DirectoryContents instance to show the result of the search on | 708 * Creates a DirectoryContents instance to show the result of the search on |
724 * Local File System. | 709 * Local File System. |
725 * | 710 * |
726 * @param {FileListContext} context File list context. | 711 * @param {FileListContext} context File list context. |
727 * @param {DirectoryEntry} directoryEntry The current directory entry. | 712 * @param {DirectoryEntry} directoryEntry The current directory entry. |
728 * @param {string} query Search query. | 713 * @param {string} query Search query. |
729 * @return {DirectoryContents} Created DirectoryContents instance. | 714 * @return {DirectoryContents} Created DirectoryContents instance. |
730 */ | 715 */ |
731 DirectoryContents.createForLocalSearch = function( | 716 DirectoryContents.createForLocalSearch = function( |
732 context, directoryEntry, query) { | 717 context, directoryEntry, query) { |
733 return new DirectoryContents( | 718 return new DirectoryContents( |
734 context, | 719 context, |
735 true, // Search. | 720 true, // Search. |
736 directoryEntry, | 721 directoryEntry, |
737 directoryEntry, | |
738 function() { | 722 function() { |
739 return new LocalSearchContentScanner(directoryEntry, query); | 723 return new LocalSearchContentScanner(directoryEntry, query); |
740 }); | 724 }); |
741 }; | 725 }; |
742 | 726 |
743 /** | 727 /** |
744 * Creates a DirectoryContents instance to show the result of metadata search | 728 * Creates a DirectoryContents instance to show the result of metadata search |
745 * on Drive File System. | 729 * on Drive File System. |
746 * | 730 * |
747 * @param {FileListContext} context File list context. | 731 * @param {FileListContext} context File list context. |
748 * @param {DirectoryEntry} fakeDirectoryEntry Fake directory entry representing | 732 * @param {DirectoryEntry} fakeDirectoryEntry Fake directory entry representing |
749 * the set of result entries. This serves as a top directory for the | 733 * the set of result entries. This serves as a top directory for the |
750 * search. | 734 * search. |
751 * @param {DirectoryEntry} driveDirectoryEntry Directory for the actual drive. | |
752 * @param {string} query Search query. | |
753 * @param {DriveMetadataSearchContentScanner.SearchType} searchType The type of | 735 * @param {DriveMetadataSearchContentScanner.SearchType} searchType The type of |
754 * the search. The scanner will restricts the entries based on the given | 736 * the search. The scanner will restricts the entries based on the given |
755 * type. | 737 * type. |
756 * @return {DirectoryContents} Created DirectoryContents instance. | 738 * @return {DirectoryContents} Created DirectoryContents instance. |
757 */ | 739 */ |
758 DirectoryContents.createForDriveMetadataSearch = function( | 740 DirectoryContents.createForDriveMetadataSearch = function( |
759 context, fakeDirectoryEntry, driveDirectoryEntry, query, searchType) { | 741 context, fakeDirectoryEntry, searchType) { |
760 return new DirectoryContents( | 742 return new DirectoryContents( |
761 context, | 743 context, |
762 true, // Search | 744 true, // Search |
763 fakeDirectoryEntry, | 745 fakeDirectoryEntry, |
764 driveDirectoryEntry, | |
765 function() { | 746 function() { |
766 return new DriveMetadataSearchContentScanner(query, searchType); | 747 return new DriveMetadataSearchContentScanner(searchType); |
767 }); | 748 }); |
768 }; | 749 }; |
OLD | NEW |