Commit a9235f61 authored by Zentaro Kavanagh's avatar Zentaro Kavanagh Committed by Commit Bot

smb_client: Filter out redundant requests from FSP

- Large numbers of redundant requests are degrading the performance
  of the SMB FSP
- This CL short circuits those requests while separately we can try
  to eliminate their root cause
- This filters out 2 types of requests
  1) Empty requests. These requests should never even be made since
     they are requests that explicitly ask for no information.
  2) Thumbnail only requests. We never have thumbnail data and always
     provide a hardcoded response.
- By short circuiting them here we can prevent them being sent to
  the service and incuring any network operations.

BUG=chromium:867200,chromium:587231
TEST=build and test

Change-Id: Ibb9eaaa175660106dd6a169781cc2ce4a83dafea
Reviewed-on: https://chromium-review.googlesource.com/1156989Reviewed-by: default avatarMay Lippert <maybelle@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Commit-Queue: Zentaro Kavanagh <zentaro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579516}
parent 89bc721d
......@@ -23,6 +23,8 @@ namespace chromeos {
namespace {
using file_system_provider::ProvidedFileSystemInterface;
// This is a bogus data URI.
// The Files app will attempt to download a whole image to create a thumbnail
// any time you visit a folder. A bug (crbug.com/548050) tracks not doing that
......@@ -38,7 +40,12 @@ constexpr uint32_t kReadDirectoryInitialBatchSize = 64;
// Maximum number of entries to send at a time for read directory,
constexpr uint32_t kReadDirectoryMaxBatchSize = 2048;
using file_system_provider::ProvidedFileSystemInterface;
constexpr ProvidedFileSystemInterface::MetadataFieldMask kRequestableFields =
ProvidedFileSystemInterface::MetadataField::METADATA_FIELD_IS_DIRECTORY |
ProvidedFileSystemInterface::MetadataField::METADATA_FIELD_NAME |
ProvidedFileSystemInterface::MetadataField::METADATA_FIELD_SIZE |
ProvidedFileSystemInterface::MetadataField::
METADATA_FIELD_MODIFICATION_TIME;
bool RequestedIsDirectory(
ProvidedFileSystemInterface::MetadataFieldMask fields) {
......@@ -67,6 +74,12 @@ bool RequestedThumbnail(ProvidedFileSystemInterface::MetadataFieldMask fields) {
ProvidedFileSystemInterface::MetadataField::METADATA_FIELD_THUMBNAIL;
}
bool IsRedundantRequest(ProvidedFileSystemInterface::MetadataFieldMask fields) {
// If there isn't at least 1 requestable field there is no point doing a
// network request.
return (fields & kRequestableFields) == 0;
}
// Metrics recording.
void RecordReadDirectoryCount(int count) {
UMA_HISTOGRAM_COUNTS_100000("NativeSmbFileShare.ReadDirectoryCount", count);
......@@ -170,6 +183,10 @@ AbortCallback SmbFileSystem::GetMetadata(
const base::FilePath& entry_path,
ProvidedFileSystemInterface::MetadataFieldMask fields,
ProvidedFileSystemInterface::GetMetadataCallback callback) {
if (IsRedundantRequest(fields)) {
return HandleSyncRedundantGetMetadata(fields, std::move(callback));
}
auto reply =
base::BindOnce(&SmbFileSystem::HandleRequestGetMetadataEntryCallback,
AsWeakPtr(), fields, callback);
......@@ -601,6 +618,22 @@ void SmbFileSystem::HandleContinueCopyCallback(
std::move(callback).Run(TranslateToFileError(error));
}
AbortCallback SmbFileSystem::HandleSyncRedundantGetMetadata(
ProvidedFileSystemInterface::MetadataFieldMask fields,
ProvidedFileSystemInterface::GetMetadataCallback callback) {
auto metadata = std::make_unique<file_system_provider::EntryMetadata>();
// The fields could be empty or have one or both of thumbnail and metadata.
// We completely ignore metadata, but populate the bogus URI for the
// thumbnail.
if (RequestedThumbnail(fields)) {
metadata->thumbnail = std::make_unique<std::string>(kUnknownImageDataUri);
}
std::move(callback).Run(std::move(metadata), base::File::FILE_OK);
return CreateAbortCallback();
}
void SmbFileSystem::HandleRequestGetMetadataEntryCallback(
ProvidedFileSystemInterface::MetadataFieldMask fields,
ProvidedFileSystemInterface::GetMetadataCallback callback,
......
......@@ -215,6 +215,10 @@ class SmbFileSystem : public file_system_provider::ProvidedFileSystemInterface,
smbprovider::ErrorType error,
const smbprovider::DirectoryEntryListProto& entries) const;
file_system_provider::AbortCallback HandleSyncRedundantGetMetadata(
ProvidedFileSystemInterface::MetadataFieldMask fields,
ProvidedFileSystemInterface::GetMetadataCallback callback);
void HandleRequestGetMetadataEntryCallback(
ProvidedFileSystemInterface::MetadataFieldMask fields,
ProvidedFileSystemInterface::GetMetadataCallback callback,
......
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