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/entry.h" | 5 #include "services/catalog/entry.h" |
6 | 6 |
7 #include "base/files/file_path.h" | |
8 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
9 #include "base/path_service.h" | |
10 #include "base/values.h" | 8 #include "base/values.h" |
11 #include "services/catalog/store.h" | 9 #include "services/catalog/store.h" |
12 | 10 |
| 11 |
13 namespace catalog { | 12 namespace catalog { |
14 namespace { | 13 namespace { |
15 | 14 |
16 #if defined(OS_WIN) | |
17 const char kServiceExecutableExtension[] = ".service.exe"; | |
18 #else | |
19 const char kServiceExecutableExtension[] = ".service"; | |
20 #endif | |
21 | |
22 bool ReadStringSet(const base::ListValue& list_value, | 15 bool ReadStringSet(const base::ListValue& list_value, |
23 std::set<std::string>* string_set) { | 16 std::set<std::string>* string_set) { |
24 DCHECK(string_set); | 17 DCHECK(string_set); |
25 for (const auto& value_value : list_value) { | 18 for (const auto& value_value : list_value) { |
26 std::string value; | 19 std::string value; |
27 if (!value_value->GetAsString(&value)) { | 20 if (!value_value->GetAsString(&value)) { |
28 LOG(ERROR) << "Entry::Deserialize: list member must be a string"; | 21 LOG(ERROR) << "Entry::Deserialize: list member must be a string"; |
29 return false; | 22 return false; |
30 } | 23 } |
31 string_set->insert(value); | 24 string_set->insert(value); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 requires->Set(i.first, std::move(capabilities)); | 128 requires->Set(i.first, std::move(capabilities)); |
136 } | 129 } |
137 spec->Set(Store::kInterfaceProviderSpecs_RequiresKey, std::move(requires)); | 130 spec->Set(Store::kInterfaceProviderSpecs_RequiresKey, std::move(requires)); |
138 specs->Set(it.first, std::move(spec)); | 131 specs->Set(it.first, std::move(spec)); |
139 } | 132 } |
140 value->Set(Store::kInterfaceProviderSpecsKey, std::move(specs)); | 133 value->Set(Store::kInterfaceProviderSpecsKey, std::move(specs)); |
141 return value; | 134 return value; |
142 } | 135 } |
143 | 136 |
144 // static | 137 // static |
145 std::unique_ptr<Entry> Entry::Deserialize(const base::Value& manifest_root) { | 138 std::unique_ptr<Entry> Entry::Deserialize(const base::DictionaryValue& value) { |
146 const base::DictionaryValue* dictionary_value = nullptr; | |
147 if (!manifest_root.GetAsDictionary(&dictionary_value)) | |
148 return nullptr; | |
149 const base::DictionaryValue& value = *dictionary_value; | |
150 | |
151 auto entry = base::MakeUnique<Entry>(); | 139 auto entry = base::MakeUnique<Entry>(); |
152 | 140 |
153 // Name. | 141 // Name. |
154 std::string name; | 142 std::string name; |
155 if (!value.GetString(Store::kNameKey, &name)) { | 143 if (!value.GetString(Store::kNameKey, &name)) { |
156 LOG(ERROR) << "Entry::Deserialize: dictionary has no " | 144 LOG(ERROR) << "Entry::Deserialize: dictionary has no " |
157 << Store::kNameKey << " key"; | 145 << Store::kNameKey << " key"; |
158 return nullptr; | 146 return nullptr; |
159 } | 147 } |
160 if (name.empty()) { | 148 if (name.empty()) { |
161 LOG(ERROR) << "Entry::Deserialize: empty service name."; | 149 LOG(ERROR) << "Entry::Deserialize: empty service name."; |
162 return nullptr; | 150 return nullptr; |
163 } | 151 } |
164 entry->set_name(name); | 152 entry->set_name(name); |
165 | 153 |
166 // By default we assume a standalone service executable. The catalog may | |
167 // override this layer based on configuration external to the service's own | |
168 // manifest. | |
169 base::FilePath module_path; | |
170 base::PathService::Get(base::DIR_MODULE, &module_path); | |
171 entry->set_path(module_path.AppendASCII(name + kServiceExecutableExtension)); | |
172 | |
173 // Human-readable name. | 154 // Human-readable name. |
174 std::string display_name; | 155 std::string display_name; |
175 if (!value.GetString(Store::kDisplayNameKey, &display_name)) { | 156 if (!value.GetString(Store::kDisplayNameKey, &display_name)) { |
176 LOG(ERROR) << "Entry::Deserialize: dictionary has no " | 157 LOG(ERROR) << "Entry::Deserialize: dictionary has no " |
177 << Store::kDisplayNameKey << " key"; | 158 << Store::kDisplayNameKey << " key"; |
178 return nullptr; | 159 return nullptr; |
179 } | 160 } |
180 entry->set_display_name(display_name); | 161 entry->set_display_name(display_name); |
181 | 162 |
182 // InterfaceProvider specs. | 163 // InterfaceProvider specs. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 catalog::mojom::EntryPtr | 249 catalog::mojom::EntryPtr |
269 TypeConverter<catalog::mojom::EntryPtr, catalog::Entry>::Convert( | 250 TypeConverter<catalog::mojom::EntryPtr, catalog::Entry>::Convert( |
270 const catalog::Entry& input) { | 251 const catalog::Entry& input) { |
271 catalog::mojom::EntryPtr result(catalog::mojom::Entry::New()); | 252 catalog::mojom::EntryPtr result(catalog::mojom::Entry::New()); |
272 result->name = input.name(); | 253 result->name = input.name(); |
273 result->display_name = input.display_name(); | 254 result->display_name = input.display_name(); |
274 return result; | 255 return result; |
275 } | 256 } |
276 | 257 |
277 } // namespace mojo | 258 } // namespace mojo |
OLD | NEW |