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/service_manager/public/cpp/names.h" | 19 #include "services/service_manager/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 const std::string& package_name_override) { | 26 const std::string& package_name_override) { |
27 // TODO(beng): think more about how this should be done for exe targets. | 27 // TODO(beng): think more about how this should be done for exe targets. |
28 std::string type = shell::GetNameType(name); | 28 std::string type = service_manager::GetNameType(name); |
29 std::string path = shell::GetNamePath(name); | 29 std::string path = service_manager::GetNamePath(name); |
30 if (type == shell::kNameType_Service) { | 30 if (type == service_manager::kNameType_Service) { |
31 std::string package_name; | 31 std::string package_name; |
32 if (package_name_override.empty()) | 32 if (package_name_override.empty()) |
33 package_name = path; | 33 package_name = path; |
34 else | 34 else |
35 package_name = package_name_override; | 35 package_name = package_name_override; |
36 return package_dir.AppendASCII(kPackagesDirName).AppendASCII( | 36 return package_dir.AppendASCII(kPackagesDirName).AppendASCII( |
37 package_name + "/manifest.json"); | 37 package_name + "/manifest.json"); |
38 } | 38 } |
39 if (type == shell::kNameType_Exe) | 39 if (type == service_manager::kNameType_Exe) |
40 return package_dir.AppendASCII(path + "_manifest.json"); | 40 return package_dir.AppendASCII(path + "_manifest.json"); |
41 return base::FilePath(); | 41 return base::FilePath(); |
42 } | 42 } |
43 | 43 |
44 base::FilePath GetExecutablePath(const base::FilePath& package_dir, | 44 base::FilePath GetExecutablePath(const base::FilePath& package_dir, |
45 const std::string& name) { | 45 const std::string& name) { |
46 std::string type = shell::GetNameType(name); | 46 std::string type = service_manager::GetNameType(name); |
47 if (type == shell::kNameType_Service) { | 47 if (type == service_manager::kNameType_Service) { |
48 // It's still a mojo: URL, use the default mapping scheme. | 48 // It's still a mojo: URL, use the default mapping scheme. |
49 const std::string host = shell::GetNamePath(name); | 49 const std::string host = service_manager::GetNamePath(name); |
50 return package_dir.AppendASCII(host + "/" + host + ".library"); | 50 return package_dir.AppendASCII(host + "/" + host + ".library"); |
51 } | 51 } |
52 if (type == shell::kNameType_Exe) { | 52 if (type == service_manager::kNameType_Exe) { |
53 #if defined OS_WIN | 53 #if defined OS_WIN |
54 std::string extension = ".exe"; | 54 std::string extension = ".exe"; |
55 #else | 55 #else |
56 std::string extension; | 56 std::string extension; |
57 #endif | 57 #endif |
58 return package_dir.AppendASCII(shell::GetNamePath(name) + extension); | 58 return package_dir.AppendASCII(service_manager::GetNamePath(name) + |
| 59 extension); |
59 } | 60 } |
60 return base::FilePath(); | 61 return base::FilePath(); |
61 } | 62 } |
62 | 63 |
63 std::unique_ptr<Entry> ProcessManifest( | 64 std::unique_ptr<Entry> ProcessManifest( |
64 std::unique_ptr<base::Value> manifest_root, | 65 std::unique_ptr<base::Value> manifest_root, |
65 const base::FilePath& package_dir) { | 66 const base::FilePath& package_dir) { |
66 // Manifest was malformed or did not exist. | 67 // Manifest was malformed or did not exist. |
67 if (!manifest_root) | 68 if (!manifest_root) |
68 return nullptr; | 69 return nullptr; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 return entry; | 150 return entry; |
150 } | 151 } |
151 | 152 |
152 void AddEntryToCache(EntryCache* cache, std::unique_ptr<Entry> entry) { | 153 void AddEntryToCache(EntryCache* cache, std::unique_ptr<Entry> entry) { |
153 std::vector<std::unique_ptr<Entry>> children = entry->TakeChildren(); | 154 std::vector<std::unique_ptr<Entry>> children = entry->TakeChildren(); |
154 for (auto& child : children) | 155 for (auto& child : children) |
155 AddEntryToCache(cache, std::move(child)); | 156 AddEntryToCache(cache, std::move(child)); |
156 (*cache)[entry->name()] = std::move(entry); | 157 (*cache)[entry->name()] = std::move(entry); |
157 } | 158 } |
158 | 159 |
159 void DoNothing(shell::mojom::ResolveResultPtr) {} | 160 void DoNothing(service_manager::mojom::ResolveResultPtr) {} |
160 | 161 |
161 } // namespace | 162 } // namespace |
162 | 163 |
163 // A sequenced task runner is used to guarantee requests are serviced in the | 164 // A sequenced task runner is used to guarantee requests are serviced in the |
164 // order requested. To do otherwise means we may run callbacks in an | 165 // order requested. To do otherwise means we may run callbacks in an |
165 // unpredictable order, leading to flake. | 166 // unpredictable order, leading to flake. |
166 Reader::Reader(base::SequencedWorkerPool* worker_pool, | 167 Reader::Reader(base::SequencedWorkerPool* worker_pool, |
167 ManifestProvider* manifest_provider) | 168 ManifestProvider* manifest_provider) |
168 : Reader(manifest_provider) { | 169 : Reader(manifest_provider) { |
169 file_task_runner_ = worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( | 170 file_task_runner_ = worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 : manifest_provider_(manifest_provider), weak_factory_(this) { | 245 : manifest_provider_(manifest_provider), weak_factory_(this) { |
245 PathService::Get(base::DIR_MODULE, &system_package_dir_); | 246 PathService::Get(base::DIR_MODULE, &system_package_dir_); |
246 } | 247 } |
247 | 248 |
248 void Reader::OnReadManifest( | 249 void Reader::OnReadManifest( |
249 EntryCache* cache, | 250 EntryCache* cache, |
250 const CreateEntryForNameCallback& entry_created_callback, | 251 const CreateEntryForNameCallback& entry_created_callback, |
251 std::unique_ptr<Entry> entry) { | 252 std::unique_ptr<Entry> entry) { |
252 if (!entry) | 253 if (!entry) |
253 return; | 254 return; |
254 shell::mojom::ResolveResultPtr result = | 255 service_manager::mojom::ResolveResultPtr result = |
255 shell::mojom::ResolveResult::From(*entry); | 256 service_manager::mojom::ResolveResult::From(*entry); |
256 AddEntryToCache(cache, std::move(entry)); | 257 AddEntryToCache(cache, std::move(entry)); |
257 entry_created_callback.Run(std::move(result)); | 258 entry_created_callback.Run(std::move(result)); |
258 } | 259 } |
259 | 260 |
260 } // namespace catalog | 261 } // namespace catalog |
OLD | NEW |