Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root_map.h" | |
| 6 | |
| 7 #include "base/memory/ptr_util.h" | |
| 8 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root.h" | |
| 9 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" | |
| 10 | |
| 11 namespace arc { | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 struct DocumentsProviderSpec { | |
| 16 const char* authority; | |
| 17 const char* root_document_id; | |
| 18 }; | |
| 19 | |
| 20 // List of allowed documents providers for production. | |
| 21 constexpr DocumentsProviderSpec kDocumentsProviderWhitelist[] = { | |
| 22 {"com.android.providers.media.documents", "images_root"}, | |
| 23 {"com.android.providers.media.documents", "videos_root"}, | |
| 24 {"com.android.providers.media.documents", "audio_root"}, | |
| 25 }; | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 ArcDocumentsProviderRootMap::ArcDocumentsProviderRootMap() { | |
| 30 for (auto spec : kDocumentsProviderWhitelist) { | |
| 31 map_[Key(spec.authority, spec.root_document_id)] = | |
| 32 base::MakeUnique<ArcDocumentsProviderRoot>(spec.authority, | |
| 33 spec.root_document_id); | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 ArcDocumentsProviderRootMap::~ArcDocumentsProviderRootMap() = default; | |
| 38 | |
| 39 ArcDocumentsProviderRoot* ArcDocumentsProviderRootMap::Lookup( | |
| 40 const std::string& authority, | |
| 41 const std::string& root_document_id) { | |
| 42 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.
| |
| 43 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.
| |
| 44 return nullptr; | |
| 45 } | |
| 46 return iter->second.get(); | |
| 47 } | |
| 48 | |
| 49 ArcDocumentsProviderRoot* ArcDocumentsProviderRootMap::ParseAndLookup( | |
| 50 const storage::FileSystemURL& url, | |
| 51 base::FilePath* path) { | |
| 52 std::string authority; | |
| 53 std::string root_document_id; | |
| 54 if (!ParseDocumentsProviderUrl(url, &authority, &root_document_id, path)) { | |
| 55 return nullptr; | |
| 56 } | |
| 57 return Lookup(authority, root_document_id); | |
| 58 } | |
| 59 | |
| 60 } // namespace arc | |
| OLD | NEW |