*/
DirectoryContentScanner.prototype.scan = function(
entriesCallback, successCallback, errorCallback) {
- if (!this.entry_ ||
- (util.isFakeEntry(this.entry_) &&
- this.entry_.rootType === RootType.DRIVE)) {
+ if (!this.entry_ || util.isFakeEntry(this.entry_)) {
// If entry is not specified or a fake, we cannot read it.
errorCallback(util.createDOMError(
util.FileError.INVALID_MODIFICATION_ERR));
/**
* Scanner of the entries for the metadata search on Drive File System.
- * @param {string} query The query of the search.
* @param {DriveMetadataSearchContentScanner.SearchType} searchType The option
* of the search.
* @constructor
* @extends {ContentScanner}
*/
-function DriveMetadataSearchContentScanner(query, searchType) {
+function DriveMetadataSearchContentScanner(searchType) {
ContentScanner.call(this);
- this.query_ = query;
this.searchType_ = searchType;
}
DriveMetadataSearchContentScanner.prototype.scan = function(
entriesCallback, successCallback, errorCallback) {
chrome.fileBrowserPrivate.searchDriveMetadata(
- {query: this.query_, types: this.searchType_, maxResults: 500},
+ {query: '', types: this.searchType_, maxResults: 500},
function(results) {
if (this.cancelled_) {
errorCallback(util.createDOMError(util.FileError.ABORT_ERR));
* @param {boolean} isSearch True for search directory contents, otherwise
* false.
* @param {DirectoryEntry} directoryEntry The entry of the current directory.
- * @param {DirectoryEntry} lastNonSearchDirectoryEntry The entry of the last
- * non-search directory.
* @param {function():ContentScanner} scannerFactory The factory to create
* ContentScanner instance.
* @constructor
* @extends {cr.EventTarget}
*/
-function DirectoryContents(context, isSearch, directoryEntry,
- lastNonSearchDirectoryEntry,
+function DirectoryContents(context,
+ isSearch,
+ directoryEntry,
scannerFactory) {
this.context_ = context;
this.fileList_ = context.fileList;
this.isSearch_ = isSearch;
this.directoryEntry_ = directoryEntry;
- this.lastNonSearchDirectoryEntry_ = lastNonSearchDirectoryEntry;
this.scannerFactory_ = scannerFactory;
this.scanner_ = null;
*/
DirectoryContents.prototype.clone = function() {
return new DirectoryContents(
- this.context_, this.isSearch_, this.directoryEntry_,
- this.lastNonSearchDirectoryEntry_, this.scannerFactory_);
+ this.context_,
+ this.isSearch_,
+ this.directoryEntry_,
+ this.scannerFactory_);
};
/**
};
/**
- * @return {DirectoryEntry} A DirectoryEntry for the last non search contents.
- */
-DirectoryContents.prototype.getLastNonSearchDirectoryEntry = function() {
- return this.lastNonSearchDirectoryEntry_;
-};
-
-/**
* Start directory scan/search operation. Either 'scan-completed' or
* 'scan-failed' event will be fired upon completion.
*/
DirectoryContents.prototype.scan = function() {
+ /**
+ * Invoked when the scanning is completed successfully.
+ * @this {DirectoryContents}
+ */
+ function completionCallback() {
+ this.onScanFinished_();
+ this.onScanCompleted_();
+ }
+
+ /**
+ * Invoked when the scanning is finished but is not completed due to error.
+ * @this {DirectoryContents}
+ */
+ function errorCallback() {
+ this.onScanFinished_();
+ this.onScanError_();
+ }
+
// TODO(hidehiko,mtomasz): this scan method must be called at most once.
// Remove such a limitation.
this.scanner_ = this.scannerFactory_();
this.scanner_.scan(this.onNewEntries_.bind(this),
- this.onScanCompleted_.bind(this),
- this.onScanError_.bind(this));
+ completionCallback.bind(this),
+ errorCallback.bind(this));
};
/**
if (this.scanner_)
this.scanner_.cancel();
+ this.onScanFinished_();
+
this.prefetchMetadataQueue_.cancel();
cr.dispatchSimpleEvent(this, 'scan-cancelled');
};
/**
- * Called when the scanning by scanner_ is done.
+ * Called when the scanning by scanner_ is done, even when the scanning is
+ * succeeded or failed. This is called before completion (or error) callback.
+ *
* @private
*/
-DirectoryContents.prototype.onScanCompleted_ = function() {
+DirectoryContents.prototype.onScanFinished_ = function() {
this.scanner_ = null;
+
+ this.prefetchMetadataQueue_.run(function(callback) {
+ // TODO(yoshiki): Here we should fire the update event of changed
+ // items. Currently we have a method this.fileList_.updateIndex() to
+ // fire an event, but this method takes only 1 argument and invokes sort
+ // one by one. It is obviously time wasting. Instead, we call sort
+ // directory.
+ // In future, we should implement a good method like updateIndexes and
+ // use it here.
+ var status = this.fileList_.sortStatus;
+ if (status)
+ this.fileList_.sort(status.field, status.direction);
+
+ callback();
+ }.bind(this));
+};
+
+/**
+ * Called when the scanning by scanner_ is succeeded.
+ * @private
+ */
+DirectoryContents.prototype.onScanCompleted_ = function() {
if (this.scanCancelled_)
return;
this.prefetchMetadataQueue_.run(function(callback) {
// Call callback first, so isScanning() returns false in the event handlers.
callback();
+
cr.dispatchSimpleEvent(this, 'scan-completed');
}.bind(this));
};
* @private
*/
DirectoryContents.prototype.onScanError_ = function() {
- this.scanner_ = null;
if (this.scanCancelled_)
return;
return;
}
- // TODO(yoshiki): Here we should fire the update event of changed
- // items. Currently we have a method this.fileList_.updateIndex() to
- // fire an event, but this method takes only 1 argument and invokes sort
- // one by one. It is obviously time wasting. Instead, we call sort
- // directory.
- // In future, we should implement a good method like updateIndexes and
- // use it here.
- var status = this.fileList_.sortStatus;
- this.fileList_.sort(status.field, status.direction);
-
cr.dispatchSimpleEvent(this, 'scan-updated');
callback();
}.bind(this));
* @param {function(Object)} callback Callback on done.
*/
DirectoryContents.prototype.prefetchMetadata = function(entries, callback) {
- this.context_.metadataCache.get(entries, 'filesystem', callback);
-};
-
-/**
- * @param {Array.<Entry>} entries Files.
- * @param {function(Object)} callback Callback on done.
- */
-DirectoryContents.prototype.reloadMetadata = function(entries, callback) {
- this.context_.metadataCache.clear(entries, '*');
- this.context_.metadataCache.get(entries, 'filesystem', callback);
-};
-
-/**
- * @param {string} name Directory name.
- * @param {function(DirectoryEntry)} successCallback Called on success.
- * @param {function(FileError)} errorCallback On error.
- */
-DirectoryContents.prototype.createDirectory = function(
- name, successCallback, errorCallback) {
- // TODO(hidehiko): createDirectory should not be the part of
- // DirectoryContent.
- if (this.isSearch_ || !this.directoryEntry_) {
- errorCallback(util.createDOMError(
- util.FileError.INVALID_MODIFICATION_ERR));
- return;
- }
-
- var onSuccess = function(newEntry) {
- this.reloadMetadata([newEntry], function() {
- successCallback(newEntry);
- });
- };
-
- this.directoryEntry_.getDirectory(name, {create: true, exclusive: true},
- onSuccess.bind(this), errorCallback);
+ this.context_.metadataCache.get(entries, 'filesystem|drive', callback);
};
/**
context,
false, // Non search.
directoryEntry,
- directoryEntry,
function() {
return new DirectoryContentScanner(directoryEntry);
});
*
* @param {FileListContext} context File list context.
* @param {DirectoryEntry} directoryEntry The current directory entry.
- * @param {DirectoryEntry} previousDirectoryEntry The DirectoryEntry that was
- * current before the search.
* @param {string} query Search query.
* @return {DirectoryContents} Created DirectoryContents instance.
*/
DirectoryContents.createForDriveSearch = function(
- context, directoryEntry, previousDirectoryEntry, query) {
+ context, directoryEntry, query) {
return new DirectoryContents(
context,
true, // Search.
directoryEntry,
- previousDirectoryEntry,
function() {
return new DriveSearchContentScanner(query);
});
context,
true, // Search.
directoryEntry,
- directoryEntry,
function() {
return new LocalSearchContentScanner(directoryEntry, query);
});
* @param {DirectoryEntry} fakeDirectoryEntry Fake directory entry representing
* the set of result entries. This serves as a top directory for the
* search.
- * @param {DirectoryEntry} driveDirectoryEntry Directory for the actual drive.
- * @param {string} query Search query.
* @param {DriveMetadataSearchContentScanner.SearchType} searchType The type of
* the search. The scanner will restricts the entries based on the given
* type.
* @return {DirectoryContents} Created DirectoryContents instance.
*/
DirectoryContents.createForDriveMetadataSearch = function(
- context, fakeDirectoryEntry, driveDirectoryEntry, query, searchType) {
+ context, fakeDirectoryEntry, searchType) {
return new DirectoryContents(
context,
true, // Search
fakeDirectoryEntry,
- driveDirectoryEntry,
function() {
- return new DriveMetadataSearchContentScanner(query, searchType);
+ return new DriveMetadataSearchContentScanner(searchType);
});
};