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