diff options
author | mtomasz <mtomasz@chromium.org> | 2015-11-15 04:11:21 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-15 12:12:12 +0000 |
commit | 4c70fc9c006c7d5a3099cac3842cef8b411d2a49 (patch) | |
tree | edb348637c36016d78fb2bd7c47a9de416165b8d /storage | |
parent | b77e5bbb09cacac678ca2b1f36a4280d65519cd6 (diff) | |
download | chromium_src-4c70fc9c006c7d5a3099cac3842cef8b411d2a49.zip chromium_src-4c70fc9c006c7d5a3099cac3842cef8b411d2a49.tar.gz chromium_src-4c70fc9c006c7d5a3099cac3842cef8b411d2a49.tar.bz2 |
Do not call stat() when reading directories via File API.
It's very heavy, and on the JavaScript side the metadata is discarded
anyway, and another call is used to obtain it.
TEST=All existing tests should pass. Tested manually with MTP and
chrome://quota-internals, then filesystem://.../isolated in the browser.
BUG=None
Review URL: https://codereview.chromium.org/1432403003
Cr-Commit-Position: refs/heads/master@{#359768}
Diffstat (limited to 'storage')
5 files changed, 56 insertions, 24 deletions
diff --git a/storage/browser/fileapi/async_file_util_adapter.cc b/storage/browser/fileapi/async_file_util_adapter.cc index ed8f84f..0de0f61 100644 --- a/storage/browser/fileapi/async_file_util_adapter.cc +++ b/storage/browser/fileapi/async_file_util_adapter.cc @@ -116,8 +116,6 @@ void ReadDirectoryHelper(FileSystemFileUtil* file_util, DirectoryEntry entry; entry.is_directory = file_enum->IsDirectory(); entry.name = VirtualPath::BaseName(current).value(); - entry.size = file_enum->Size(); - entry.last_modified_time = file_enum->LastModifiedTime(); entries.push_back(entry); if (entries.size() == kResultChunkSize) { diff --git a/storage/browser/fileapi/file_system_dir_url_request_job.cc b/storage/browser/fileapi/file_system_dir_url_request_job.cc index 4236fec..ac2118a 100644 --- a/storage/browser/fileapi/file_system_dir_url_request_job.cc +++ b/storage/browser/fileapi/file_system_dir_url_request_job.cc @@ -143,15 +143,52 @@ void FileSystemDirURLRequestJob::DidReadDirectory( data_.append(net::GetDirectoryListingHeader(title)); } - typedef std::vector<DirectoryEntry>::const_iterator EntryIterator; - for (EntryIterator it = entries.begin(); it != entries.end(); ++it) { - const base::string16& name = base::FilePath(it->name).LossyDisplayName(); - data_.append(net::GetDirectoryListingEntry( - name, std::string(), it->is_directory, it->size, - it->last_modified_time)); - } + entries_.insert(entries_.end(), entries.begin(), entries.end()); if (!has_more) { + if (entries_.size()) { + GetMetadata(0); + } else { + set_expected_content_size(data_.size()); + NotifyHeadersComplete(); + } + } +} + +void FileSystemDirURLRequestJob::GetMetadata(size_t index) { + const DirectoryEntry& entry = entries_[index]; + const FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( + url_.origin(), url_.type(), + url_.path().Append(base::FilePath(entry.name))); + DCHECK(url.is_valid()); + file_system_context_->operation_runner()->GetMetadata( + url, + base::Bind(&FileSystemDirURLRequestJob::DidGetMetadata, this, index)); +} + +void FileSystemDirURLRequestJob::DidGetMetadata( + size_t index, + base::File::Error result, + const base::File::Info& file_info) { + if (result != base::File::FILE_OK) { + int rv = net::ERR_FILE_NOT_FOUND; + if (result == base::File::FILE_ERROR_INVALID_URL) + rv = net::ERR_INVALID_URL; + NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); + } + + if (!request_) + return; + + const DirectoryEntry& entry = entries_[index]; + const base::string16& name = base::FilePath(entry.name).LossyDisplayName(); + data_.append(net::GetDirectoryListingEntry(name, std::string(), + entry.is_directory, file_info.size, + file_info.last_modified)); + + if (index < entries_.size() - 1) { + GetMetadata(index + 1); + } else { set_expected_content_size(data_.size()); NotifyHeadersComplete(); } diff --git a/storage/browser/fileapi/file_system_dir_url_request_job.h b/storage/browser/fileapi/file_system_dir_url_request_job.h index 0163535..01bd372 100644 --- a/storage/browser/fileapi/file_system_dir_url_request_job.h +++ b/storage/browser/fileapi/file_system_dir_url_request_job.h @@ -51,6 +51,14 @@ class STORAGE_EXPORT FileSystemDirURLRequestJob : public net::URLRequestJob { const std::vector<DirectoryEntry>& entries, bool has_more); + // Reads metadata for the |index|-th entry in the directory. Must be called + // after |entries_| is filled. + void GetMetadata(size_t index); + void DidGetMetadata(size_t index, + base::File::Error result, + const base::File::Info& file_info); + + std::vector<DirectoryEntry> entries_; std::string data_; FileSystemURL url_; const std::string storage_domain_; diff --git a/storage/common/fileapi/directory_entry.cc b/storage/common/fileapi/directory_entry.cc index 477ede8..f972745 100644 --- a/storage/common/fileapi/directory_entry.cc +++ b/storage/common/fileapi/directory_entry.cc @@ -6,16 +6,10 @@ namespace storage { -DirectoryEntry::DirectoryEntry() : is_directory(false), size(0) {} +DirectoryEntry::DirectoryEntry() : is_directory(false) {} -DirectoryEntry::DirectoryEntry(const std::string& name, - DirectoryEntryType type, - int64 size, - const base::Time& last_modified_time) +DirectoryEntry::DirectoryEntry(const std::string& name, DirectoryEntryType type) : name(base::FilePath::FromUTF8Unsafe(name).value()), - is_directory(type == DIRECTORY), - size(size), - last_modified_time(last_modified_time) { -} + is_directory(type == DIRECTORY) {} } // namespace storage diff --git a/storage/common/fileapi/directory_entry.h b/storage/common/fileapi/directory_entry.h index 1b06828..fab7fae 100644 --- a/storage/common/fileapi/directory_entry.h +++ b/storage/common/fileapi/directory_entry.h @@ -22,15 +22,10 @@ struct STORAGE_COMMON_EXPORT DirectoryEntry { }; DirectoryEntry(); - DirectoryEntry(const std::string& name, - DirectoryEntryType type, - int64 size, - const base::Time& last_modified_time); + DirectoryEntry(const std::string& name, DirectoryEntryType type); base::FilePath::StringType name; bool is_directory; - int64 size; - base::Time last_modified_time; }; } // namespace storage |