| 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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 DirectoryContentsBasic.prototype.createDirectory = function( | 473 DirectoryContentsBasic.prototype.createDirectory = function( |
| 474 name, successCallback, errorCallback) { | 474 name, successCallback, errorCallback) { |
| 475 var onSuccess = function(newEntry) { | 475 var onSuccess = function(newEntry) { |
| 476 this.prefetchMetadata([newEntry], function() {successCallback(newEntry);}); | 476 this.prefetchMetadata([newEntry], function() {successCallback(newEntry);}); |
| 477 } | 477 } |
| 478 | 478 |
| 479 this.entry_.getDirectory(name, {create: true, exclusive: true}, | 479 this.entry_.getDirectory(name, {create: true, exclusive: true}, |
| 480 onSuccess.bind(this), errorCallback); | 480 onSuccess.bind(this), errorCallback); |
| 481 }; | 481 }; |
| 482 | 482 |
| 483 /** |
| 484 * Delay to be used for gdata search scan. |
| 485 * The goal is to reduce the number of server requests when user is typing the |
| 486 * query. |
| 487 */ |
| 488 DirectoryContentsGDataSearch.SCAN_DELAY = 200; |
| 483 | 489 |
| 484 /** | 490 /** |
| 485 * @constructor | 491 * @constructor |
| 486 * @extends {DirectoryContents} | 492 * @extends {DirectoryContents} |
| 487 * @param {FileListContext} context File list context. | 493 * @param {FileListContext} context File list context. |
| 488 * @param {DirectoryEntry} dirEntry Current directory. | 494 * @param {DirectoryEntry} dirEntry Current directory. |
| 489 * @param {string} query Search query. | 495 * @param {string} query Search query. |
| 490 */ | 496 */ |
| 491 function DirectoryContentsGDataSearch(context, dirEntry, query) { | 497 function DirectoryContentsGDataSearch(context, dirEntry, query) { |
| 492 DirectoryContents.call(this, context); | 498 DirectoryContents.call(this, context); |
| 493 this.query_ = query; | 499 this.query_ = query; |
| 494 this.directoryEntry_ = dirEntry; | 500 this.directoryEntry_ = dirEntry; |
| 501 this.nextFeed_ = ''; |
| 502 this.done_ = false; |
| 495 } | 503 } |
| 496 | 504 |
| 497 /** | 505 /** |
| 498 * Extends DirectoryContents. | 506 * Extends DirectoryContents. |
| 499 */ | 507 */ |
| 500 DirectoryContentsGDataSearch.prototype.__proto__ = DirectoryContents.prototype; | 508 DirectoryContentsGDataSearch.prototype.__proto__ = DirectoryContents.prototype; |
| 501 | 509 |
| 502 /** | 510 /** |
| 503 * Create the copy of the object, but without scan started. | 511 * Create the copy of the object, but without scan started. |
| 504 * @return {DirectoryContentsBasic} Object copy. | 512 * @return {DirectoryContentsBasic} Object copy. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 526 * @return {string} The path. | 534 * @return {string} The path. |
| 527 */ | 535 */ |
| 528 DirectoryContentsGDataSearch.prototype.getPath = function() { | 536 DirectoryContentsGDataSearch.prototype.getPath = function() { |
| 529 return this.directoryEntry_.fullPath; | 537 return this.directoryEntry_.fullPath; |
| 530 }; | 538 }; |
| 531 | 539 |
| 532 /** | 540 /** |
| 533 * Start directory scan. | 541 * Start directory scan. |
| 534 */ | 542 */ |
| 535 DirectoryContentsGDataSearch.prototype.scan = function() { | 543 DirectoryContentsGDataSearch.prototype.scan = function() { |
| 536 chrome.fileBrowserPrivate.searchGData(this.query_, | 544 // Let's give another search a chance to cancel us before we begin. |
| 537 this.onNewEntries.bind(this)); | 545 setTimeout(this.readNextChunk.bind(this), |
| 546 DirectoryContentsGDataSearch.SCAN_DELAY); |
| 538 }; | 547 }; |
| 539 | 548 |
| 540 /** | 549 /** |
| 541 * All the results are read in one chunk, so when we try to read second chunk, | 550 * All the results are read in one chunk, so when we try to read second chunk, |
| 542 * it means we're done. | 551 * it means we're done. |
| 543 */ | 552 */ |
| 544 DirectoryContentsGDataSearch.prototype.readNextChunk = function() { | 553 DirectoryContentsGDataSearch.prototype.readNextChunk = function() { |
| 545 this.onCompleted(); | 554 if (this.scanCancelled_) |
| 555 return; |
| 556 |
| 557 if (this.done_) { |
| 558 this.onCompleted(); |
| 559 return; |
| 560 } |
| 561 |
| 562 var searchCallback = (function(entries, nextFeed) { |
| 563 // TODO(tbarzic): Improve error handling. |
| 564 if (!entries) { |
| 565 console.log('Drive search encountered an error'); |
| 566 this.onCompleted(); |
| 567 return; |
| 568 } |
| 569 this.done_ = (nextFeed == ''); |
| 570 this.nextFeed_ = nextFeed; |
| 571 this.onNewEntries(entries); |
| 572 }).bind(this); |
| 573 |
| 574 chrome.fileBrowserPrivate.searchGData(this.query_, |
| 575 this.nextFeed_, |
| 576 searchCallback); |
| 546 }; | 577 }; |
| 547 | 578 |
| 548 | 579 |
| 549 /** | 580 /** |
| 550 * @constructor | 581 * @constructor |
| 551 * @extends {DirectoryContents} | 582 * @extends {DirectoryContents} |
| 552 * @param {FileListContext} context File list context. | 583 * @param {FileListContext} context File list context. |
| 553 * @param {DirectoryEntry} dirEntry Current directory. | 584 * @param {DirectoryEntry} dirEntry Current directory. |
| 554 * @param {string} query Search query. | 585 * @param {string} query Search query. |
| 555 */ | 586 */ |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 | 681 |
| 651 getNextChunk(); | 682 getNextChunk(); |
| 652 }; | 683 }; |
| 653 | 684 |
| 654 var getNextChunk = function() { | 685 var getNextChunk = function() { |
| 655 reader.readEntries(onChunkComplete, self.onError.bind(self)); | 686 reader.readEntries(onChunkComplete, self.onError.bind(self)); |
| 656 }; | 687 }; |
| 657 | 688 |
| 658 getNextChunk(); | 689 getNextChunk(); |
| 659 }; | 690 }; |
| OLD | NEW |