| Index: chrome/browser/resources/file_manager/js/directory_contents.js
|
| diff --git a/chrome/browser/resources/file_manager/js/directory_contents.js b/chrome/browser/resources/file_manager/js/directory_contents.js
|
| index 904fc565aa076532e977ab653668f4e11b47a25f..07df6fda9430a010644a1b796e23bd572e7472d3 100644
|
| --- a/chrome/browser/resources/file_manager/js/directory_contents.js
|
| +++ b/chrome/browser/resources/file_manager/js/directory_contents.js
|
| @@ -480,6 +480,12 @@ DirectoryContentsBasic.prototype.createDirectory = function(
|
| onSuccess.bind(this), errorCallback);
|
| };
|
|
|
| +/**
|
| + * Delay to be used for gdata search scan.
|
| + * The goal is to reduce the number of server requests when user is typing the
|
| + * query.
|
| + */
|
| +DirectoryContentsGDataSearch.SCAN_DELAY = 200;
|
|
|
| /**
|
| * @constructor
|
| @@ -492,6 +498,8 @@ function DirectoryContentsGDataSearch(context, dirEntry, query) {
|
| DirectoryContents.call(this, context);
|
| this.query_ = query;
|
| this.directoryEntry_ = dirEntry;
|
| + this.nextFeed_ = '';
|
| + this.done_ = false;
|
| }
|
|
|
| /**
|
| @@ -533,8 +541,9 @@ DirectoryContentsGDataSearch.prototype.getPath = function() {
|
| * Start directory scan.
|
| */
|
| DirectoryContentsGDataSearch.prototype.scan = function() {
|
| - chrome.fileBrowserPrivate.searchGData(this.query_,
|
| - this.onNewEntries.bind(this));
|
| + // Let's give another search a chance to cancel us before we begin.
|
| + setTimeout(this.readNextChunk.bind(this),
|
| + DirectoryContentsGDataSearch.SCAN_DELAY);
|
| };
|
|
|
| /**
|
| @@ -542,7 +551,29 @@ DirectoryContentsGDataSearch.prototype.scan = function() {
|
| * it means we're done.
|
| */
|
| DirectoryContentsGDataSearch.prototype.readNextChunk = function() {
|
| - this.onCompleted();
|
| + if (this.scanCancelled_)
|
| + return;
|
| +
|
| + if (this.done_) {
|
| + this.onCompleted();
|
| + return;
|
| + }
|
| +
|
| + var searchCallback = (function(entries, nextFeed) {
|
| + // TODO(tbarzic): Improve error handling.
|
| + if (!entries) {
|
| + console.log('Drive search encountered an error');
|
| + this.onCompleted();
|
| + return;
|
| + }
|
| + this.done_ = (nextFeed == '');
|
| + this.nextFeed_ = nextFeed;
|
| + this.onNewEntries(entries);
|
| + }).bind(this);
|
| +
|
| + chrome.fileBrowserPrivate.searchGData(this.query_,
|
| + this.nextFeed_,
|
| + searchCallback);
|
| };
|
|
|
|
|
|
|