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 /** | 5 /** |
6 * Type of a root directory. | 6 * Type of a root directory. |
7 * @enum | 7 * @enum |
8 */ | 8 */ |
9 var RootType = { | 9 var RootType = { |
10 DOWNLOADS: 'downloads', | 10 DOWNLOADS: 'downloads', |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 DirectoryContentsBasic.prototype.createDirectory = function( | 521 DirectoryContentsBasic.prototype.createDirectory = function( |
522 name, successCallback, errorCallback) { | 522 name, successCallback, errorCallback) { |
523 var onSuccess = function(newEntry) { | 523 var onSuccess = function(newEntry) { |
524 this.prefetchMetadata([newEntry], function() {successCallback(newEntry);}); | 524 this.prefetchMetadata([newEntry], function() {successCallback(newEntry);}); |
525 } | 525 } |
526 | 526 |
527 this.entry_.getDirectory(name, {create: true, exclusive: true}, | 527 this.entry_.getDirectory(name, {create: true, exclusive: true}, |
528 onSuccess.bind(this), errorCallback); | 528 onSuccess.bind(this), errorCallback); |
529 }; | 529 }; |
530 | 530 |
| 531 /** |
| 532 * Delay to be used for gdata search scan. |
| 533 * The goal is to reduce the number of server requests when user is typing the |
| 534 * query. |
| 535 */ |
| 536 DirectoryContentsGDataSearch.SCAN_DELAY = 200; |
| 537 |
| 538 /** |
| 539 * Number of results at which we stop the search. |
| 540 * Note that max number of shown results is MAX_RESULTS + search feed size. |
| 541 */ |
| 542 DirectoryContentsGDataSearch.MAX_RESULTS = 999; |
531 | 543 |
532 /** | 544 /** |
533 * @constructor | 545 * @constructor |
534 * @extends {DirectoryContents} | 546 * @extends {DirectoryContents} |
535 * @param {FileListContext} context File list context. | 547 * @param {FileListContext} context File list context. |
536 * @param {DirectoryEntry} dirEntry Current directory. | 548 * @param {DirectoryEntry} dirEntry Current directory. |
537 * @param {string} query Search query. | 549 * @param {string} query Search query. |
538 */ | 550 */ |
539 function DirectoryContentsGDataSearch(context, dirEntry, query) { | 551 function DirectoryContentsGDataSearch(context, dirEntry, query) { |
540 DirectoryContents.call(this, context); | 552 DirectoryContents.call(this, context); |
541 this.query_ = query; | 553 this.query_ = query; |
542 this.directoryEntry_ = dirEntry; | 554 this.directoryEntry_ = dirEntry; |
| 555 this.nextFeed_ = ''; |
| 556 this.done_ = false; |
| 557 this.fetchedResultsNum_ = 0; |
543 } | 558 } |
544 | 559 |
545 /** | 560 /** |
546 * Extends DirectoryContents. | 561 * Extends DirectoryContents. |
547 */ | 562 */ |
548 DirectoryContentsGDataSearch.prototype.__proto__ = DirectoryContents.prototype; | 563 DirectoryContentsGDataSearch.prototype.__proto__ = DirectoryContents.prototype; |
549 | 564 |
550 /** | 565 /** |
551 * Create the copy of the object, but without scan started. | 566 * Create the copy of the object, but without scan started. |
552 * @return {DirectoryContentsBasic} Object copy. | 567 * @return {DirectoryContentsBasic} Object copy. |
(...skipping 21 matching lines...) Expand all Loading... |
574 * @return {string} The path. | 589 * @return {string} The path. |
575 */ | 590 */ |
576 DirectoryContentsGDataSearch.prototype.getPath = function() { | 591 DirectoryContentsGDataSearch.prototype.getPath = function() { |
577 return this.directoryEntry_.fullPath; | 592 return this.directoryEntry_.fullPath; |
578 }; | 593 }; |
579 | 594 |
580 /** | 595 /** |
581 * Start directory scan. | 596 * Start directory scan. |
582 */ | 597 */ |
583 DirectoryContentsGDataSearch.prototype.scan = function() { | 598 DirectoryContentsGDataSearch.prototype.scan = function() { |
584 chrome.fileBrowserPrivate.searchGData(this.query_, | 599 // Let's give another search a chance to cancel us before we begin. |
585 this.onNewEntries.bind(this)); | 600 setTimeout(this.readNextChunk.bind(this), |
| 601 DirectoryContentsGDataSearch.SCAN_DELAY); |
586 }; | 602 }; |
587 | 603 |
588 /** | 604 /** |
589 * All the results are read in one chunk, so when we try to read second chunk, | 605 * All the results are read in one chunk, so when we try to read second chunk, |
590 * it means we're done. | 606 * it means we're done. |
591 */ | 607 */ |
592 DirectoryContentsGDataSearch.prototype.readNextChunk = function() { | 608 DirectoryContentsGDataSearch.prototype.readNextChunk = function() { |
593 this.onCompleted(); | 609 if (this.scanCancelled_) |
| 610 return; |
| 611 |
| 612 if (this.done_) { |
| 613 this.onCompleted(); |
| 614 return; |
| 615 } |
| 616 |
| 617 var searchCallback = (function(entries, nextFeed) { |
| 618 // TODO(tbarzic): Improve error handling. |
| 619 if (!entries) { |
| 620 console.log('Drive search encountered an error'); |
| 621 this.onCompleted(); |
| 622 return; |
| 623 } |
| 624 this.nextFeed_ = nextFeed; |
| 625 this.fetchedResultsNum_ += entries.length; |
| 626 if (this.fetchedResultsNum_ >= DirectoryContentsGDataSearch.MAX_RESULTS) |
| 627 this.nextFeed_ = ''; |
| 628 |
| 629 this.done_ = (this.nextFeed_ == ''); |
| 630 this.onNewEntries(entries); |
| 631 }).bind(this); |
| 632 |
| 633 chrome.fileBrowserPrivate.searchGData(this.query_, |
| 634 this.nextFeed_, |
| 635 searchCallback); |
594 }; | 636 }; |
595 | 637 |
596 | 638 |
597 /** | 639 /** |
598 * @constructor | 640 * @constructor |
599 * @extends {DirectoryContents} | 641 * @extends {DirectoryContents} |
600 * @param {FileListContext} context File list context. | 642 * @param {FileListContext} context File list context. |
601 * @param {DirectoryEntry} dirEntry Current directory. | 643 * @param {DirectoryEntry} dirEntry Current directory. |
602 * @param {string} query Search query. | 644 * @param {string} query Search query. |
603 */ | 645 */ |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 | 747 |
706 getNextChunk(); | 748 getNextChunk(); |
707 }; | 749 }; |
708 | 750 |
709 /** | 751 /** |
710 * Empty. | 752 * Empty. |
711 */ | 753 */ |
712 DirectoryContentsLocalSearch.prototype.readNextChunk = function() { | 754 DirectoryContentsLocalSearch.prototype.readNextChunk = function() { |
713 this.onCompleted(); | 755 this.onCompleted(); |
714 }; | 756 }; |
OLD | NEW |