Commit 6573295f authored by Bailey Berro's avatar Bailey Berro Committed by Commit Bot

Add overloaded GetProvidedFileSystemInfoList function.

This change adds an overloaded GetProvidedFileSystemInfoList() method
that takes a ProviderId as a parameter, and returns a vector containing
only FileSystemInfo entries for a specific Provider.

This change also modifies the FileSystemProvider API to use this new
function to reduce code duplication.

Bug: chromium:757625
Change-Id: I5426f6768f12a3347aa8b196d2c1804b4f1ed01d
Reviewed-on: https://chromium-review.googlesource.com/986943
Commit-Queue: Bailey Berro <baileyberro@chromium.org>
Reviewed-by: default avatarNaoki Fukino <fukino@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548134}
parent 6cd83218
...@@ -186,29 +186,27 @@ ExtensionFunction::ResponseAction FileSystemProviderGetAllFunction::Run() { ...@@ -186,29 +186,27 @@ ExtensionFunction::ResponseAction FileSystemProviderGetAllFunction::Run() {
Service::Get(Profile::FromBrowserContext(browser_context())); Service::Get(Profile::FromBrowserContext(browser_context()));
DCHECK(service); DCHECK(service);
ProviderId provider_id = ProviderId::CreateFromExtensionId(extension_id());
const std::vector<ProvidedFileSystemInfo> file_systems = const std::vector<ProvidedFileSystemInfo> file_systems =
service->GetProvidedFileSystemInfoList(); service->GetProvidedFileSystemInfoList(provider_id);
std::vector<FileSystemInfo> items; std::vector<FileSystemInfo> items;
ProviderId provider_id = ProviderId::CreateFromExtensionId(extension_id());
for (const auto& file_system_info : file_systems) { for (const auto& file_system_info : file_systems) {
if (file_system_info.provider_id() == provider_id) { FileSystemInfo item;
FileSystemInfo item;
chromeos::file_system_provider::ProvidedFileSystemInterface* const
chromeos::file_system_provider::ProvidedFileSystemInterface* const file_system = service->GetProvidedFileSystem(
file_system = file_system_info.provider_id(), file_system_info.file_system_id());
service->GetProvidedFileSystem(file_system_info.provider_id(),
file_system_info.file_system_id()); DCHECK(file_system);
DCHECK(file_system);
FillFileSystemInfo(
FillFileSystemInfo(file_system_info, file_system_info,
file_system_info.watchable() file_system_info.watchable() ? *file_system->GetWatchers() : Watchers(),
? *file_system->GetWatchers() file_system->GetOpenedFiles(), &item);
: Watchers(),
file_system->GetOpenedFiles(), &item); items.push_back(std::move(item));
items.push_back(std::move(item));
}
} }
return RespondNow( return RespondNow(
......
...@@ -275,6 +275,23 @@ std::vector<ProvidedFileSystemInfo> Service::GetProvidedFileSystemInfoList() { ...@@ -275,6 +275,23 @@ std::vector<ProvidedFileSystemInfo> Service::GetProvidedFileSystemInfoList() {
return result; return result;
} }
std::vector<ProvidedFileSystemInfo> Service::GetProvidedFileSystemInfoList(
const ProviderId& provider_id) {
DCHECK(thread_checker_.CalledOnValidThread());
const std::vector<ProvidedFileSystemInfo> full_list =
GetProvidedFileSystemInfoList();
std::vector<ProvidedFileSystemInfo> filtered_list;
for (const auto& file_system : full_list) {
if (file_system.provider_id() == provider_id) {
filtered_list.push_back(file_system);
}
}
return filtered_list;
}
ProvidedFileSystemInterface* Service::GetProvidedFileSystem( ProvidedFileSystemInterface* Service::GetProvidedFileSystem(
const ProviderId& provider_id, const ProviderId& provider_id,
const std::string& file_system_id) { const std::string& file_system_id) {
......
...@@ -111,6 +111,11 @@ class Service : public KeyedService, ...@@ -111,6 +111,11 @@ class Service : public KeyedService,
// items are copied. // items are copied.
std::vector<ProvidedFileSystemInfo> GetProvidedFileSystemInfoList(); std::vector<ProvidedFileSystemInfo> GetProvidedFileSystemInfoList();
// Returns a list of information of the currently provided file systems for
// |provider_id|. All items are copied.
std::vector<ProvidedFileSystemInfo> GetProvidedFileSystemInfoList(
const ProviderId& provider_id);
// Returns an immutable map of all registered providers. // Returns an immutable map of all registered providers.
const ProviderMap& GetProviders() const; const ProviderMap& GetProviders() const;
......
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