Chromium Code Reviews| Index: chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root_map.cc |
| diff --git a/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root_map.cc b/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root_map.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6a0d8a639ae353afa025b24e100326ec696e5a9f |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root_map.cc |
| @@ -0,0 +1,60 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root_map.h" |
| + |
| +#include "base/memory/ptr_util.h" |
| +#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root.h" |
| +#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" |
| + |
| +namespace arc { |
| + |
| +namespace { |
| + |
| +struct DocumentsProviderSpec { |
| + const char* authority; |
| + const char* root_document_id; |
| +}; |
| + |
| +// List of allowed documents providers for production. |
| +constexpr DocumentsProviderSpec kDocumentsProviderWhitelist[] = { |
| + {"com.android.providers.media.documents", "images_root"}, |
| + {"com.android.providers.media.documents", "videos_root"}, |
| + {"com.android.providers.media.documents", "audio_root"}, |
| +}; |
| + |
| +} // namespace |
| + |
| +ArcDocumentsProviderRootMap::ArcDocumentsProviderRootMap() { |
| + for (auto spec : kDocumentsProviderWhitelist) { |
| + map_[Key(spec.authority, spec.root_document_id)] = |
| + base::MakeUnique<ArcDocumentsProviderRoot>(spec.authority, |
| + spec.root_document_id); |
| + } |
| +} |
| + |
| +ArcDocumentsProviderRootMap::~ArcDocumentsProviderRootMap() = default; |
| + |
| +ArcDocumentsProviderRoot* ArcDocumentsProviderRootMap::Lookup( |
| + const std::string& authority, |
| + const std::string& root_document_id) { |
| + auto iter = map_.find(std::make_pair(authority, root_document_id)); |
|
Luis Héctor Chávez
2016/12/14 20:53:50
nit: does it work with s/std::make_pair/Key/?
Shuhei Takahashi
2016/12/15 02:37:55
Done.
|
| + if (iter == map_.end()) { |
|
Luis Héctor Chávez
2016/12/14 20:53:50
nit: elide braces. Same in L54.
Shuhei Takahashi
2016/12/15 02:37:55
Done.
|
| + return nullptr; |
| + } |
| + return iter->second.get(); |
| +} |
| + |
| +ArcDocumentsProviderRoot* ArcDocumentsProviderRootMap::ParseAndLookup( |
| + const storage::FileSystemURL& url, |
| + base::FilePath* path) { |
| + std::string authority; |
| + std::string root_document_id; |
| + if (!ParseDocumentsProviderUrl(url, &authority, &root_document_id, path)) { |
| + return nullptr; |
| + } |
| + return Lookup(authority, root_document_id); |
| +} |
| + |
| +} // namespace arc |