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

Side by Side 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: rebase Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 * @constructor 6 * @constructor
7 * @param {MetadataCache} metadataCache Metadata cache service. 7 * @param {MetadataCache} metadataCache Metadata cache service.
8 * @param {cr.ui.ArrayDataModel} fileList The file list. 8 * @param {cr.ui.ArrayDataModel} fileList The file list.
9 * @param {boolean} showHidden If files starting with '.' are shown. 9 * @param {boolean} showHidden If files starting with '.' are shown.
10 */ 10 */
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 DirectoryContentsBasic.prototype.createDirectory = function( 347 DirectoryContentsBasic.prototype.createDirectory = function(
348 name, successCallback, errorCallback) { 348 name, successCallback, errorCallback) {
349 var onSuccess = function(newEntry) { 349 var onSuccess = function(newEntry) {
350 this.prefetchMetadata([newEntry], function() {successCallback(newEntry);}); 350 this.prefetchMetadata([newEntry], function() {successCallback(newEntry);});
351 } 351 }
352 352
353 this.entry_.getDirectory(name, {create: true, exclusive: true}, 353 this.entry_.getDirectory(name, {create: true, exclusive: true},
354 onSuccess.bind(this), errorCallback); 354 onSuccess.bind(this), errorCallback);
355 }; 355 };
356 356
357 /**
358 * Delay to be used for gdata search scan.
359 * The goal is to reduce the number of server requests when user is typing the
360 * query.
361 */
362 DirectoryContentsGDataSearch.SCAN_DELAY = 200;
363
364 /**
365 * Number of results at which we stop the search.
366 * Note that max number of shown results is MAX_RESULTS + search feed size.
367 */
368 DirectoryContentsGDataSearch.MAX_RESULTS = 999;
357 369
358 /** 370 /**
359 * @constructor 371 * @constructor
360 * @extends {DirectoryContents} 372 * @extends {DirectoryContents}
361 * @param {FileListContext} context File list context. 373 * @param {FileListContext} context File list context.
362 * @param {DirectoryEntry} dirEntry Current directory. 374 * @param {DirectoryEntry} dirEntry Current directory.
363 * @param {string} query Search query. 375 * @param {string} query Search query.
364 */ 376 */
365 function DirectoryContentsGDataSearch(context, dirEntry, query) { 377 function DirectoryContentsGDataSearch(context, dirEntry, query) {
366 DirectoryContents.call(this, context); 378 DirectoryContents.call(this, context);
367 this.query_ = query; 379 this.query_ = query;
368 this.directoryEntry_ = dirEntry; 380 this.directoryEntry_ = dirEntry;
381 this.nextFeed_ = '';
382 this.done_ = false;
383 this.fetchedResultsNum_ = 0;
369 } 384 }
370 385
371 /** 386 /**
372 * Extends DirectoryContents. 387 * Extends DirectoryContents.
373 */ 388 */
374 DirectoryContentsGDataSearch.prototype.__proto__ = DirectoryContents.prototype; 389 DirectoryContentsGDataSearch.prototype.__proto__ = DirectoryContents.prototype;
375 390
376 /** 391 /**
377 * Create the copy of the object, but without scan started. 392 * Create the copy of the object, but without scan started.
378 * @return {DirectoryContentsBasic} Object copy. 393 * @return {DirectoryContentsBasic} Object copy.
(...skipping 21 matching lines...) Expand all
400 * @return {string} The path. 415 * @return {string} The path.
401 */ 416 */
402 DirectoryContentsGDataSearch.prototype.getPath = function() { 417 DirectoryContentsGDataSearch.prototype.getPath = function() {
403 return this.directoryEntry_.fullPath; 418 return this.directoryEntry_.fullPath;
404 }; 419 };
405 420
406 /** 421 /**
407 * Start directory scan. 422 * Start directory scan.
408 */ 423 */
409 DirectoryContentsGDataSearch.prototype.scan = function() { 424 DirectoryContentsGDataSearch.prototype.scan = function() {
410 chrome.fileBrowserPrivate.searchGData(this.query_, 425 // Let's give another search a chance to cancel us before we begin.
411 this.onNewEntries.bind(this)); 426 setTimeout(this.readNextChunk.bind(this),
427 DirectoryContentsGDataSearch.SCAN_DELAY);
412 }; 428 };
413 429
414 /** 430 /**
415 * All the results are read in one chunk, so when we try to read second chunk, 431 * All the results are read in one chunk, so when we try to read second chunk,
416 * it means we're done. 432 * it means we're done.
417 */ 433 */
418 DirectoryContentsGDataSearch.prototype.readNextChunk = function() { 434 DirectoryContentsGDataSearch.prototype.readNextChunk = function() {
419 this.onCompleted(); 435 if (this.scanCancelled_)
436 return;
437
438 if (this.done_) {
439 this.onCompleted();
440 return;
441 }
442
443 var searchCallback = (function(entries, nextFeed) {
444 // TODO(tbarzic): Improve error handling.
445 if (!entries) {
446 console.log('Drive search encountered an error');
447 this.onCompleted();
448 return;
449 }
450 this.nextFeed_ = nextFeed;
451 this.fetchedResultsNum_ += entries.length;
452 if (this.fetchedResultsNum_ >= DirectoryContentsGDataSearch.MAX_RESULTS)
453 this.nextFeed_ = '';
454
455 this.done_ = (this.nextFeed_ == '');
456 this.onNewEntries(entries);
457 }).bind(this);
458
459 chrome.fileBrowserPrivate.searchGData(this.query_,
460 this.nextFeed_,
461 searchCallback);
420 }; 462 };
421 463
422 464
423 /** 465 /**
424 * @constructor 466 * @constructor
425 * @extends {DirectoryContents} 467 * @extends {DirectoryContents}
426 * @param {FileListContext} context File list context. 468 * @param {FileListContext} context File list context.
427 * @param {DirectoryEntry} dirEntry Current directory. 469 * @param {DirectoryEntry} dirEntry Current directory.
428 * @param {string} query Search query. 470 * @param {string} query Search query.
429 */ 471 */
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 }; 572 };
531 573
532 getNextChunk(); 574 getNextChunk();
533 }; 575 };
534 576
535 /** 577 /**
536 * We get results for each directory in one go in scanDirectory_. 578 * We get results for each directory in one go in scanDirectory_.
537 */ 579 */
538 DirectoryContentsLocalSearch.prototype.readNextChunk = function() { 580 DirectoryContentsLocalSearch.prototype.readNextChunk = function() {
539 }; 581 };
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/mock_gdata_file_system.h ('k') | chrome/browser/resources/file_manager/js/directory_model.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698