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

Unified Diff: chrome/browser/resources/file_manager/js/directory_contents.js

Issue 10634020: [FileManager] Do drive search incrementally (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
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);
};

Powered by Google App Engine
This is Rietveld 408576698