| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "services/catalog/reader.h" | 5 #include "services/catalog/reader.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_enumerator.h" | 8 #include "base/files/file_enumerator.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
| 11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/task_runner_util.h" | 14 #include "base/task_runner_util.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "services/catalog/constants.h" | 16 #include "services/catalog/constants.h" |
| 17 #include "services/catalog/entry.h" | 17 #include "services/catalog/entry.h" |
| 18 #include "services/catalog/manifest_provider.h" | 18 #include "services/catalog/manifest_provider.h" |
| 19 #include "services/shell/public/cpp/names.h" | 19 #include "services/shell/public/cpp/names.h" |
| 20 | 20 |
| 21 namespace catalog { | 21 namespace catalog { |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 base::FilePath GetManifestPath(const base::FilePath& package_dir, | 24 base::FilePath GetManifestPath(const base::FilePath& package_dir, |
| 25 const std::string& name) { | 25 const std::string& name) { |
| 26 // TODO(beng): think more about how this should be done for exe targets. | 26 // TODO(beng): think more about how this should be done for exe targets. |
| 27 std::string type = shell::GetNameType(name); | 27 std::string type = shell::GetNameType(name); |
| 28 std::string path = shell::GetNamePath(name); | 28 std::string path = shell::GetNamePath(name); |
| 29 if (type == shell::kNameType_Mojo) { | 29 if (type == shell::kNameType_Mojo) { |
| 30 return package_dir.AppendASCII(kMojoApplicationsDirName).AppendASCII( | 30 return package_dir.AppendASCII(kPackagesDirName).AppendASCII( |
| 31 path + "/manifest.json"); | 31 path + "/manifest.json"); |
| 32 } | 32 } |
| 33 if (type == shell::kNameType_Exe) | 33 if (type == shell::kNameType_Exe) |
| 34 return package_dir.AppendASCII(path + "_manifest.json"); | 34 return package_dir.AppendASCII(path + "_manifest.json"); |
| 35 return base::FilePath(); | 35 return base::FilePath(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 | 38 |
| 39 base::FilePath GetExecutablePath(const base::FilePath& package_dir, | 39 base::FilePath GetExecutablePath(const base::FilePath& package_dir, |
| 40 const std::string& name) { | 40 const std::string& name) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 original_thread_task_runner->PostTask(FROM_HERE, read_complete_closure); | 120 original_thread_task_runner->PostTask(FROM_HERE, read_complete_closure); |
| 121 } | 121 } |
| 122 | 122 |
| 123 std::unique_ptr<Entry> ReadManifest(const base::FilePath& package_dir, | 123 std::unique_ptr<Entry> ReadManifest(const base::FilePath& package_dir, |
| 124 const std::string& mojo_name) { | 124 const std::string& mojo_name) { |
| 125 std::unique_ptr<Entry> entry = CreateEntryForManifestAt( | 125 std::unique_ptr<Entry> entry = CreateEntryForManifestAt( |
| 126 GetManifestPath(package_dir, mojo_name), package_dir); | 126 GetManifestPath(package_dir, mojo_name), package_dir); |
| 127 if (!entry) { | 127 if (!entry) { |
| 128 entry.reset(new Entry(mojo_name)); | 128 entry.reset(new Entry(mojo_name)); |
| 129 entry->set_path(GetExecutablePath( | 129 entry->set_path(GetExecutablePath( |
| 130 package_dir.AppendASCII(kMojoApplicationsDirName), mojo_name)); | 130 package_dir.AppendASCII(kPackagesDirName), mojo_name)); |
| 131 } | 131 } |
| 132 return entry; | 132 return entry; |
| 133 } | 133 } |
| 134 | 134 |
| 135 void AddEntryToCache(EntryCache* cache, std::unique_ptr<Entry> entry) { | 135 void AddEntryToCache(EntryCache* cache, std::unique_ptr<Entry> entry) { |
| 136 for (auto* child : entry->services()) | 136 for (auto* child : entry->services()) |
| 137 AddEntryToCache(cache, base::WrapUnique(child)); | 137 AddEntryToCache(cache, base::WrapUnique(child)); |
| 138 (*cache)[entry->name()] = std::move(entry); | 138 (*cache)[entry->name()] = std::move(entry); |
| 139 } | 139 } |
| 140 | 140 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 EntryCache* cache, | 207 EntryCache* cache, |
| 208 const CreateEntryForNameCallback& entry_created_callback, | 208 const CreateEntryForNameCallback& entry_created_callback, |
| 209 std::unique_ptr<Entry> entry) { | 209 std::unique_ptr<Entry> entry) { |
| 210 shell::mojom::ResolveResultPtr result = | 210 shell::mojom::ResolveResultPtr result = |
| 211 shell::mojom::ResolveResult::From(*entry); | 211 shell::mojom::ResolveResult::From(*entry); |
| 212 AddEntryToCache(cache, std::move(entry)); | 212 AddEntryToCache(cache, std::move(entry)); |
| 213 entry_created_callback.Run(std::move(result)); | 213 entry_created_callback.Run(std::move(result)); |
| 214 } | 214 } |
| 215 | 215 |
| 216 } // namespace catalog | 216 } // namespace catalog |
| OLD | NEW |