*/
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));
};
/**
+ * Array data model that can replace its item.
+ * @param {Array} array Array to be used internal.
+ */
+function ReplacableArrayDataModel(array) {
+ cr.ui.ArrayDataModel.call(this, array);
+}
+
+ReplacableArrayDataModel.prototype = {
+ __proto__: cr.ui.ArrayDataModel.prototype
+};
+
+/**
+ * Replace the contents of item and publish a 'change' event.
+ * If the old item is not found in the list, the new item is just ignored.
+ * @param {*} oldItem Old item.
+ * @param {*} newItem New item.
+ */
+ReplacableArrayDataModel.prototype.replaceItem = function(oldItem, newItem) {
+ var index = this.indexOf(oldItem);
+ if (index >= 0) {
+ this.array_[this.indexes_[index]] = newItem;
+ this.updateIndex(index);
+ }
+};
+
+/**
* A context of DirectoryContents.
* TODO(yoshiki): remove this. crbug.com/224869.
*
/**
* @type {cr.ui.ArrayDataModel}
*/
- this.fileList = new cr.ui.ArrayDataModel([]);
+ this.fileList = new ReplacableArrayDataModel([]);
/**
* @type {MetadataCache}
* @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.
*/
* @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);
});
};