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}, |
mtomasz
2014/02/04 02:20:12
nit: Could you please file a bug to remove this ar
hirono
2014/02/04 05:53:11
Done. crbug.com/340557.
| |
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 * This class is responsible for scanning directory (or search results), | 408 * This class is responsible for scanning directory (or search results), |
411 * and filling the fileList. Different descendants handle various types of | 409 * and filling the fileList. Different descendants handle various types of |
412 * directory contents shown: basic directory, drive search results, local search | 410 * directory contents shown: basic directory, drive search results, local search |
413 * results. | 411 * results. |
414 * TODO(hidehiko): Remove EventTarget from this. | 412 * TODO(hidehiko): Remove EventTarget from this. |
415 * | 413 * |
416 * @param {FileListContext} context The file list context. | 414 * @param {FileListContext} context The file list context. |
417 * @param {boolean} isSearch True for search directory contents, otherwise | 415 * @param {boolean} isSearch True for search directory contents, otherwise |
418 * false. | 416 * false. |
419 * @param {DirectoryEntry} directoryEntry The entry of the current directory. | 417 * @param {DirectoryEntry} directoryEntry The entry of the current directory. |
420 * @param {DirectoryEntry} lastNonSearchDirectoryEntry The entry of the last | |
421 * non-search directory. | |
422 * @param {function():ContentScanner} scannerFactory The factory to create | 418 * @param {function():ContentScanner} scannerFactory The factory to create |
423 * ContentScanner instance. | 419 * ContentScanner instance. |
424 * @constructor | 420 * @constructor |
425 * @extends {cr.EventTarget} | 421 * @extends {cr.EventTarget} |
426 */ | 422 */ |
427 function DirectoryContents(context, | 423 function DirectoryContents(context, |
428 isSearch, | 424 isSearch, |
429 directoryEntry, | 425 directoryEntry, |
430 lastNonSearchDirectoryEntry, | |
431 scannerFactory) { | 426 scannerFactory) { |
432 this.context_ = context; | 427 this.context_ = context; |
433 this.fileList_ = context.fileList; | 428 this.fileList_ = context.fileList; |
434 | 429 |
435 this.isSearch_ = isSearch; | 430 this.isSearch_ = isSearch; |
436 this.directoryEntry_ = directoryEntry; | 431 this.directoryEntry_ = directoryEntry; |
437 this.lastNonSearchDirectoryEntry_ = lastNonSearchDirectoryEntry; | |
438 | 432 |
439 this.scannerFactory_ = scannerFactory; | 433 this.scannerFactory_ = scannerFactory; |
440 this.scanner_ = null; | 434 this.scanner_ = null; |
441 this.prefetchMetadataQueue_ = new AsyncUtil.Queue(); | 435 this.prefetchMetadataQueue_ = new AsyncUtil.Queue(); |
442 this.scanCancelled_ = false; | 436 this.scanCancelled_ = false; |
443 } | 437 } |
444 | 438 |
445 /** | 439 /** |
446 * DirectoryContents extends cr.EventTarget. | 440 * DirectoryContents extends cr.EventTarget. |
447 */ | 441 */ |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
500 | 494 |
501 /** | 495 /** |
502 * @return {DirectoryEntry} A DirectoryEntry for current directory. In case of | 496 * @return {DirectoryEntry} A DirectoryEntry for current directory. In case of |
503 * search -- the top directory from which search is run. | 497 * search -- the top directory from which search is run. |
504 */ | 498 */ |
505 DirectoryContents.prototype.getDirectoryEntry = function() { | 499 DirectoryContents.prototype.getDirectoryEntry = function() { |
506 return this.directoryEntry_; | 500 return this.directoryEntry_; |
507 }; | 501 }; |
508 | 502 |
509 /** | 503 /** |
510 * @return {DirectoryEntry} A DirectoryEntry for the last non search contents. | |
511 */ | |
512 DirectoryContents.prototype.getLastNonSearchDirectoryEntry = function() { | |
513 return this.lastNonSearchDirectoryEntry_; | |
514 }; | |
515 | |
516 /** | |
517 * Start directory scan/search operation. Either 'scan-completed' or | 504 * Start directory scan/search operation. Either 'scan-completed' or |
518 * 'scan-failed' event will be fired upon completion. | 505 * 'scan-failed' event will be fired upon completion. |
519 */ | 506 */ |
520 DirectoryContents.prototype.scan = function() { | 507 DirectoryContents.prototype.scan = function() { |
521 // TODO(hidehiko,mtomasz): this scan method must be called at most once. | 508 // TODO(hidehiko,mtomasz): this scan method must be called at most once. |
522 // Remove such a limitation. | 509 // Remove such a limitation. |
523 this.scanner_ = this.scannerFactory_(); | 510 this.scanner_ = this.scannerFactory_(); |
mtomasz
2014/02/04 02:20:12
I'm getting a JS error after launching Files app h
hirono
2014/02/04 05:53:11
Thanks for handling it.
This is caused because the
| |
524 this.scanner_.scan(this.onNewEntries_.bind(this), | 511 this.scanner_.scan(this.onNewEntries_.bind(this), |
525 this.onScanCompleted_.bind(this), | 512 this.onScanCompleted_.bind(this), |
526 this.onScanError_.bind(this)); | 513 this.onScanError_.bind(this)); |
527 }; | 514 }; |
528 | 515 |
529 /** | 516 /** |
530 * Cancels the running scan. | 517 * Cancels the running scan. |
531 */ | 518 */ |
532 DirectoryContents.prototype.cancelScan = function() { | 519 DirectoryContents.prototype.cancelScan = function() { |
533 if (this.scanCancelled_) | 520 if (this.scanCancelled_) |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
634 * | 621 * |
635 * @param {FileListContext} context File list context. | 622 * @param {FileListContext} context File list context. |
636 * @param {DirectoryEntry} directoryEntry The current directory entry. | 623 * @param {DirectoryEntry} directoryEntry The current directory entry. |
637 * @return {DirectoryContents} Created DirectoryContents instance. | 624 * @return {DirectoryContents} Created DirectoryContents instance. |
638 */ | 625 */ |
639 DirectoryContents.createForDirectory = function(context, directoryEntry) { | 626 DirectoryContents.createForDirectory = function(context, directoryEntry) { |
640 return new DirectoryContents( | 627 return new DirectoryContents( |
641 context, | 628 context, |
642 false, // Non search. | 629 false, // Non search. |
643 directoryEntry, | 630 directoryEntry, |
644 directoryEntry, | |
645 function() { | 631 function() { |
646 return new DirectoryContentScanner(directoryEntry); | 632 return new DirectoryContentScanner(directoryEntry); |
647 }); | 633 }); |
648 }; | 634 }; |
649 | 635 |
650 /** | 636 /** |
651 * Creates a DirectoryContents instance to show the result of the search on | 637 * Creates a DirectoryContents instance to show the result of the search on |
652 * Drive File System. | 638 * Drive File System. |
653 * | 639 * |
654 * @param {FileListContext} context File list context. | 640 * @param {FileListContext} context File list context. |
655 * @param {DirectoryEntry} directoryEntry The current directory entry. | 641 * @param {DirectoryEntry} directoryEntry The current directory entry. |
656 * @param {DirectoryEntry} previousDirectoryEntry The DirectoryEntry that was | |
657 * current before the search. | |
658 * @param {string} query Search query. | 642 * @param {string} query Search query. |
659 * @return {DirectoryContents} Created DirectoryContents instance. | 643 * @return {DirectoryContents} Created DirectoryContents instance. |
660 */ | 644 */ |
661 DirectoryContents.createForDriveSearch = function( | 645 DirectoryContents.createForDriveSearch = function( |
662 context, directoryEntry, previousDirectoryEntry, query) { | 646 context, directoryEntry, query) { |
663 return new DirectoryContents( | 647 return new DirectoryContents( |
664 context, | 648 context, |
665 true, // Search. | 649 true, // Search. |
666 directoryEntry, | 650 directoryEntry, |
667 previousDirectoryEntry, | |
668 function() { | 651 function() { |
669 return new DriveSearchContentScanner(query); | 652 return new DriveSearchContentScanner(query); |
670 }); | 653 }); |
671 }; | 654 }; |
672 | 655 |
673 /** | 656 /** |
674 * Creates a DirectoryContents instance to show the result of the search on | 657 * Creates a DirectoryContents instance to show the result of the search on |
675 * Local File System. | 658 * Local File System. |
676 * | 659 * |
677 * @param {FileListContext} context File list context. | 660 * @param {FileListContext} context File list context. |
678 * @param {DirectoryEntry} directoryEntry The current directory entry. | 661 * @param {DirectoryEntry} directoryEntry The current directory entry. |
679 * @param {string} query Search query. | 662 * @param {string} query Search query. |
680 * @return {DirectoryContents} Created DirectoryContents instance. | 663 * @return {DirectoryContents} Created DirectoryContents instance. |
681 */ | 664 */ |
682 DirectoryContents.createForLocalSearch = function( | 665 DirectoryContents.createForLocalSearch = function( |
683 context, directoryEntry, query) { | 666 context, directoryEntry, query) { |
684 return new DirectoryContents( | 667 return new DirectoryContents( |
685 context, | 668 context, |
686 true, // Search. | 669 true, // Search. |
687 directoryEntry, | 670 directoryEntry, |
688 directoryEntry, | |
689 function() { | 671 function() { |
690 return new LocalSearchContentScanner(directoryEntry, query); | 672 return new LocalSearchContentScanner(directoryEntry, query); |
691 }); | 673 }); |
692 }; | 674 }; |
693 | 675 |
694 /** | 676 /** |
695 * Creates a DirectoryContents instance to show the result of metadata search | 677 * Creates a DirectoryContents instance to show the result of metadata search |
696 * on Drive File System. | 678 * on Drive File System. |
697 * | 679 * |
698 * @param {FileListContext} context File list context. | 680 * @param {FileListContext} context File list context. |
699 * @param {DirectoryEntry} fakeDirectoryEntry Fake directory entry representing | 681 * @param {DirectoryEntry} fakeDirectoryEntry Fake directory entry representing |
700 * the set of result entries. This serves as a top directory for the | 682 * the set of result entries. This serves as a top directory for the |
701 * search. | 683 * search. |
702 * @param {DirectoryEntry} driveDirectoryEntry Directory for the actual drive. | |
703 * @param {string} query Search query. | |
704 * @param {DriveMetadataSearchContentScanner.SearchType} searchType The type of | 684 * @param {DriveMetadataSearchContentScanner.SearchType} searchType The type of |
705 * the search. The scanner will restricts the entries based on the given | 685 * the search. The scanner will restricts the entries based on the given |
706 * type. | 686 * type. |
707 * @return {DirectoryContents} Created DirectoryContents instance. | 687 * @return {DirectoryContents} Created DirectoryContents instance. |
708 */ | 688 */ |
709 DirectoryContents.createForDriveMetadataSearch = function( | 689 DirectoryContents.createForDriveMetadataSearch = function( |
710 context, fakeDirectoryEntry, driveDirectoryEntry, query, searchType) { | 690 context, fakeDirectoryEntry, searchType) { |
711 return new DirectoryContents( | 691 return new DirectoryContents( |
712 context, | 692 context, |
713 true, // Search | 693 true, // Search |
714 fakeDirectoryEntry, | 694 fakeDirectoryEntry, |
715 driveDirectoryEntry, | |
716 function() { | 695 function() { |
717 return new DriveMetadataSearchContentScanner(query, searchType); | 696 return new DriveMetadataSearchContentScanner(searchType); |
718 }); | 697 }); |
719 }; | 698 }; |
OLD | NEW |