Commit 9aa07cbc authored by Satoshi Niwa's avatar Satoshi Niwa Committed by Commit Bot

Refactoring around DirectoryModel.createDirectoryContents_()

- Split createDirectoryContents_ into 2 functions
  isSearchDirectory() and createScannerFactory()
- Removed all DirectoryContents.createFor*() functions.

Bug: 1126742
Test: trybot
Change-Id: I11c697952bdc275bc398f1e329feb359cfc95559
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2421848
Commit-Queue: Satoshi Niwa <niwa@chromium.org>
Auto-Submit: Satoshi Niwa <niwa@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarNaoki Fukino <fukino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810048}
parent 07d82ba6
...@@ -1000,139 +1000,4 @@ class DirectoryContents extends cr.EventTarget { ...@@ -1000,139 +1000,4 @@ class DirectoryContents extends cr.EventTarget {
.get(entries, this.context_.prefetchPropertyNames) .get(entries, this.context_.prefetchPropertyNames)
.then(callback); .then(callback);
} }
/**
* Creates a DirectoryContents instance to show entries in a directory.
*
* @param {FileListContext} context File list context.
* @param {DirectoryEntry|FilesAppDirEntry} directoryEntry The current
* directory entry.
* @return {DirectoryContents} Created DirectoryContents instance.
*/
static createForDirectory(context, directoryEntry) {
return new DirectoryContents(
context,
false, // Non search.
directoryEntry, () => {
return new DirectoryContentScanner(directoryEntry);
});
}
/**
* Creates a DirectoryContents instance to show the result of the search on
* Drive File System.
*
* @param {FileListContext} context File list context.
* @param {DirectoryEntry} directoryEntry The current directory entry.
* @param {string} query Search query.
* @return {DirectoryContents} Created DirectoryContents instance.
*/
static createForDriveSearch(context, directoryEntry, query) {
return new DirectoryContents(
context,
true, // Search.
directoryEntry, () => {
return new DriveSearchContentScanner(query);
});
}
/**
* Creates a DirectoryContents instance to show the result of the search on
* Local File System.
*
* @param {FileListContext} context File list context.
* @param {DirectoryEntry} directoryEntry The current directory entry.
* @param {string} query Search query.
* @return {DirectoryContents} Created DirectoryContents instance.
*/
static createForLocalSearch(context, directoryEntry, query) {
return new DirectoryContents(
context,
true, // Search.
directoryEntry, () => {
return new LocalSearchContentScanner(directoryEntry, query);
});
}
/**
* Creates a DirectoryContents instance to show the result of metadata search
* on Drive File System.
*
* @param {FileListContext} context File list context.
* @param {!FakeEntry} fakeDirectoryEntry Fake directory entry representing
* the set of result entries. This serves as a top directory for the
* search.
* @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.
*/
static createForDriveMetadataSearch(context, fakeDirectoryEntry, searchType) {
return new DirectoryContents(
context,
true, // Search
fakeDirectoryEntry, () => {
return new DriveMetadataSearchContentScanner(searchType);
});
}
/**
* Creates a DirectoryContents instance to show the mixed recent files.
*
* @param {FileListContext} context File list context.
* @param {!FakeEntry} recentRootEntry Fake directory entry representing the
* root of recent files.
* @param {string} query Search query.
* @return {DirectoryContents} Created DirectoryContents instance.
*/
static createForRecent(context, recentRootEntry, query) {
return new DirectoryContents(context, true, recentRootEntry, () => {
return new RecentContentScanner(
query, recentRootEntry.sourceRestriction,
recentRootEntry.recentFileType);
});
}
/**
* Creates a DirectoryContents instance to show the flatten media views.
*
* @param {FileListContext} context File list context.
* @param {!DirectoryEntry} rootEntry Root directory entry representing the
* root of each media view volume.
* @return {DirectoryContents} Created DirectoryContents instance.
*/
static createForMediaView(context, rootEntry) {
return new DirectoryContents(context, true, rootEntry, () => {
return new MediaViewContentScanner(rootEntry);
});
}
/**
* Creates a DirectoryContents instance to show the sshfs crostini files.
*
* @param {FileListContext} context File list context.
* @param {!FakeEntry} crostiniRootEntry Fake directory entry representing the
* root of recent files.
* @return {DirectoryContents} Created DirectoryContents instance.
*/
static createForCrostiniMounter(context, crostiniRootEntry) {
return new DirectoryContents(context, true, crostiniRootEntry, () => {
return new CrostiniMounter();
});
}
/**
* Creates an empty DirectoryContents instance to show the Google Drive
* placeholder that never completes loading.
*
* @param {FileListContext} context File list context.
* @param {!FakeEntry} rootEntry Fake directory entry representing the fake
* root of Google Drive.
* @return {DirectoryContents} Created DirectoryContents instance.
*/
static createForFakeDrive(context, rootEntry) {
return new DirectoryContents(context, true, rootEntry, () => {
return new ContentScanner();
});
}
} }
...@@ -57,8 +57,11 @@ class DirectoryModel extends cr.EventTarget { ...@@ -57,8 +57,11 @@ class DirectoryModel extends cr.EventTarget {
this.currentFileListContext_ = this.currentFileListContext_ =
new FileListContext(fileFilter, metadataModel, volumeManager); new FileListContext(fileFilter, metadataModel, volumeManager);
this.currentDirContents_ = DirectoryContents.createForDirectory( this.currentDirContents_ =
this.currentFileListContext_, null); new DirectoryContents(this.currentFileListContext_, false, null, () => {
return new DirectoryContentScanner(null);
});
/** /**
* Empty file list which is used as a dummy for inactive view of file list. * Empty file list which is used as a dummy for inactive view of file list.
* @private {!FileListModel} * @private {!FileListModel}
...@@ -1291,15 +1294,46 @@ class DirectoryModel extends cr.EventTarget { ...@@ -1291,15 +1294,46 @@ class DirectoryModel extends cr.EventTarget {
} }
/** /**
* Creates directory contents for the entry and query. * Returns true if directory search should be used for the entry and query.
* *
* @param {FileListContext} context File list context. * @param {!DirectoryEntry|!FilesAppEntry} entry Directory entry.
* @param {!DirectoryEntry|!FilesAppEntry} entry Current directory.
* @param {string=} opt_query Search query string. * @param {string=} opt_query Search query string.
* @return {DirectoryContents} Directory contents. * @return {boolean} True if directory search should be used for the entry
* @private * and query.
*/ */
createDirectoryContents_(context, entry, opt_query) { isSearchDirectory(entry, opt_query) {
if (util.isRecentRootType(entry.rootType) ||
entry.rootType == VolumeManagerCommon.RootType.CROSTINI ||
entry.rootType == VolumeManagerCommon.RootType.DRIVE_FAKE_ROOT) {
return true;
}
if (entry.rootType == VolumeManagerCommon.RootType.MY_FILES) {
return false;
}
const query = (opt_query || '').trimLeft();
if (query) {
return true;
}
const locationInfo = this.volumeManager_.getLocationInfo(entry);
if (locationInfo &&
(locationInfo.rootType == VolumeManagerCommon.RootType.MEDIA_VIEW ||
locationInfo.isSpecialSearchRoot)) {
return true;
}
return false;
}
/**
* Creates scanner factory for the entry and query.
*
* @param {!DirectoryEntry|!FilesAppEntry} entry Directory entry.
* @param {string=} opt_query Search query string.
* @return {function():ContentScanner} The factory to create ContentScanner
* instance.
*/
createScannerFactory(entry, opt_query) {
const query = (opt_query || '').trimLeft(); const query = (opt_query || '').trimLeft();
const locationInfo = this.volumeManager_.getLocationInfo(entry); const locationInfo = this.volumeManager_.getLocationInfo(entry);
const canUseDriveSearch = const canUseDriveSearch =
...@@ -1308,42 +1342,49 @@ class DirectoryModel extends cr.EventTarget { ...@@ -1308,42 +1342,49 @@ class DirectoryModel extends cr.EventTarget {
(locationInfo && locationInfo.isDriveBased); (locationInfo && locationInfo.isDriveBased);
if (util.isRecentRootType(entry.rootType)) { if (util.isRecentRootType(entry.rootType)) {
return DirectoryContents.createForRecent( return () => {
context, /** @type {!FakeEntry} */ (entry), query); const fakeEntry = /** @type {!FakeEntry} */ (entry);
return new RecentContentScanner(
query, fakeEntry.sourceRestriction, fakeEntry.recentFileType);
};
} }
if (entry.rootType == VolumeManagerCommon.RootType.CROSTINI) { if (entry.rootType == VolumeManagerCommon.RootType.CROSTINI) {
return DirectoryContents.createForCrostiniMounter( return () => {
context, /** @type {!FakeEntry} */ (entry)); return new CrostiniMounter();
};
} }
if (entry.rootType == VolumeManagerCommon.RootType.MY_FILES) { if (entry.rootType == VolumeManagerCommon.RootType.MY_FILES) {
return DirectoryContents.createForDirectory( return () => {
context, /** @type {!FilesAppDirEntry} */ (entry)); return new DirectoryContentScanner(
/** @type {!FilesAppDirEntry} */ (entry));
};
} }
if (entry.rootType == VolumeManagerCommon.RootType.DRIVE_FAKE_ROOT) { if (entry.rootType == VolumeManagerCommon.RootType.DRIVE_FAKE_ROOT) {
return DirectoryContents.createForFakeDrive( return () => {
context, /** @type {!FakeEntry} */ (entry)); return new ContentScanner();
};
} }
if (query && canUseDriveSearch) { if (query && canUseDriveSearch) {
// Drive search. // Drive search.
return DirectoryContents.createForDriveSearch( return () => {
context, /** @type {!DirectoryEntry} */ (entry), query); return new DriveSearchContentScanner(query);
};
} }
if (query) { if (query) {
// Local search. // Local search for local files and DocumentsProvider files.
return DirectoryContents.createForLocalSearch( return () => {
context, /** @type {!DirectoryEntry} */ (entry), query); return new LocalSearchContentScanner(
} /** @type {!DirectoryEntry} */ (entry), query);
};
if (!locationInfo) {
return null;
} }
if (locationInfo &&
if (locationInfo.rootType == VolumeManagerCommon.RootType.MEDIA_VIEW) { locationInfo.rootType == VolumeManagerCommon.RootType.MEDIA_VIEW) {
return DirectoryContents.createForMediaView( return () => {
context, /** @type {!DirectoryEntry} */ (entry)); return new MediaViewContentScanner(
/** @type {!DirectoryEntry} */ (entry));
};
} }
if (locationInfo && locationInfo.isSpecialSearchRoot) {
if (locationInfo.isSpecialSearchRoot) {
// Drive special search. // Drive special search.
let searchType; let searchType;
switch (locationInfo.rootType) { switch (locationInfo.rootType) {
...@@ -1363,13 +1404,30 @@ class DirectoryModel extends cr.EventTarget { ...@@ -1363,13 +1404,30 @@ class DirectoryModel extends cr.EventTarget {
// Unknown special search entry. // Unknown special search entry.
throw new Error('Unknown special search type.'); throw new Error('Unknown special search type.');
} }
return DirectoryContents.createForDriveMetadataSearch( return () => {
context, return new DriveMetadataSearchContentScanner(searchType);
/** @type {!FakeEntry} */ (entry), searchType); };
} }
// Local fetch or search. // Local fetch or search.
return DirectoryContents.createForDirectory( return () => {
context, /** @type {!DirectoryEntry} */ (entry)); return new DirectoryContentScanner(
/** @type {!DirectoryEntry} */ (entry));
};
}
/**
* Creates directory contents for the entry and query.
*
* @param {FileListContext} context File list context.
* @param {!DirectoryEntry|!FilesAppDirEntry} entry Current directory.
* @param {string=} opt_query Search query string.
* @return {DirectoryContents} Directory contents.
* @private
*/
createDirectoryContents_(context, entry, opt_query) {
const isSearch = this.isSearchDirectory(entry, opt_query);
const scannerFactory = this.createScannerFactory(entry, opt_query);
return new DirectoryContents(context, isSearch, entry, scannerFactory);
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment