Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: services/catalog/entry.cc

Issue 2684433003: Files required by a service now listed in manifest. (Closed)
Patch Set: Fix build. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/catalog/entry.h ('k') | services/catalog/entry_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/files/file_path.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "services/catalog/public/cpp/manifest_parsing_util.h"
11 #include "services/catalog/store.h" 12 #include "services/catalog/store.h"
12 13
13 namespace catalog { 14 namespace catalog {
14 namespace { 15 namespace {
15 16
16 #if defined(OS_WIN) 17 #if defined(OS_WIN)
17 const char kServiceExecutableExtension[] = ".service.exe"; 18 const char kServiceExecutableExtension[] = ".service.exe";
18 #else 19 #else
19 const char kServiceExecutableExtension[] = ".service"; 20 const char kServiceExecutableExtension[] = ".service";
20 #endif 21 #endif
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 103 }
103 104
104 } // namespace 105 } // namespace
105 106
106 Entry::Entry() {} 107 Entry::Entry() {}
107 Entry::Entry(const std::string& name) 108 Entry::Entry(const std::string& name)
108 : name_(name), 109 : name_(name),
109 display_name_(name) {} 110 display_name_(name) {}
110 Entry::~Entry() {} 111 Entry::~Entry() {}
111 112
112 std::unique_ptr<base::DictionaryValue> Entry::Serialize() const {
113 auto value = base::MakeUnique<base::DictionaryValue>();
114 value->SetString(Store::kNameKey, name_);
115 value->SetString(Store::kDisplayNameKey, display_name_);
116
117 auto specs = base::MakeUnique<base::DictionaryValue>();
118 for (const auto& it : interface_provider_specs_) {
119 auto spec = base::MakeUnique<base::DictionaryValue>();
120
121 auto provides = base::MakeUnique<base::DictionaryValue>();
122 for (const auto& i : it.second.provides) {
123 auto interfaces = base::MakeUnique<base::ListValue>();
124 for (const auto& interface_name : i.second)
125 interfaces->AppendString(interface_name);
126 provides->Set(i.first, std::move(interfaces));
127 }
128 spec->Set(Store::kInterfaceProviderSpecs_ProvidesKey, std::move(provides));
129
130 auto requires = base::MakeUnique<base::DictionaryValue>();
131 for (const auto& i : it.second.requires) {
132 auto capabilities = base::MakeUnique<base::ListValue>();
133 for (const auto& capability : i.second)
134 capabilities->AppendString(capability);
135 requires->Set(i.first, std::move(capabilities));
136 }
137 spec->Set(Store::kInterfaceProviderSpecs_RequiresKey, std::move(requires));
138 specs->Set(it.first, std::move(spec));
139 }
140 value->Set(Store::kInterfaceProviderSpecsKey, std::move(specs));
141 return value;
142 }
143
144 // static 113 // static
145 std::unique_ptr<Entry> Entry::Deserialize(const base::Value& manifest_root) { 114 std::unique_ptr<Entry> Entry::Deserialize(const base::Value& manifest_root) {
146 const base::DictionaryValue* dictionary_value = nullptr; 115 const base::DictionaryValue* dictionary_value = nullptr;
147 if (!manifest_root.GetAsDictionary(&dictionary_value)) 116 if (!manifest_root.GetAsDictionary(&dictionary_value))
148 return nullptr; 117 return nullptr;
149 const base::DictionaryValue& value = *dictionary_value; 118 const base::DictionaryValue& value = *dictionary_value;
150 119
151 auto entry = base::MakeUnique<Entry>(); 120 auto entry = base::MakeUnique<Entry>();
152 121
153 // Name. 122 // Name.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 168
200 service_manager::InterfaceProviderSpec spec; 169 service_manager::InterfaceProviderSpec spec;
201 if (!BuildInterfaceProviderSpec(*spec_value, &spec)) { 170 if (!BuildInterfaceProviderSpec(*spec_value, &spec)) {
202 LOG(ERROR) << "Entry::Deserialize: failed to build InterfaceProvider " 171 LOG(ERROR) << "Entry::Deserialize: failed to build InterfaceProvider "
203 << "spec for key: " << it.key(); 172 << "spec for key: " << it.key();
204 return nullptr; 173 return nullptr;
205 } 174 }
206 entry->AddInterfaceProviderSpec(it.key(), spec); 175 entry->AddInterfaceProviderSpec(it.key(), spec);
207 } 176 }
208 177
178 // Required files.
179 base::Optional<RequiredFileMap> required_files =
180 catalog::RetrieveRequiredFiles(value);
181 DCHECK(required_files);
182 for (const auto& iter : *required_files) {
183 entry->AddRequiredFilePath(iter.first, iter.second);
184 }
185
209 if (value.HasKey(Store::kServicesKey)) { 186 if (value.HasKey(Store::kServicesKey)) {
210 const base::ListValue* services = nullptr; 187 const base::ListValue* services = nullptr;
211 value.GetList(Store::kServicesKey, &services); 188 value.GetList(Store::kServicesKey, &services);
212 for (size_t i = 0; i < services->GetSize(); ++i) { 189 for (size_t i = 0; i < services->GetSize(); ++i) {
213 const base::DictionaryValue* service = nullptr; 190 const base::DictionaryValue* service = nullptr;
214 services->GetDictionary(i, &service); 191 services->GetDictionary(i, &service);
215 std::unique_ptr<Entry> child = Entry::Deserialize(*service); 192 std::unique_ptr<Entry> child = Entry::Deserialize(*service);
216 if (child) { 193 if (child) {
217 child->set_parent(entry.get()); 194 child->set_parent(entry.get());
218 entry->children().emplace_back(std::move(child)); 195 entry->children().emplace_back(std::move(child));
(...skipping 20 matching lines...) Expand all
239 other.display_name_ == display_name_ && 216 other.display_name_ == display_name_ &&
240 other.interface_provider_specs_ == interface_provider_specs_; 217 other.interface_provider_specs_ == interface_provider_specs_;
241 } 218 }
242 219
243 void Entry::AddInterfaceProviderSpec( 220 void Entry::AddInterfaceProviderSpec(
244 const std::string& name, 221 const std::string& name,
245 const service_manager::InterfaceProviderSpec& spec) { 222 const service_manager::InterfaceProviderSpec& spec) {
246 interface_provider_specs_[name] = spec; 223 interface_provider_specs_[name] = spec;
247 } 224 }
248 225
226 void Entry::AddRequiredFilePath(const std::string& name,
227 const base::FilePath& path) {
228 required_file_paths_[name] = path;
229 }
230
249 } // catalog 231 } // catalog
250 232
251 namespace mojo { 233 namespace mojo {
252 234
253 // static 235 // static
254 service_manager::mojom::ResolveResultPtr 236 service_manager::mojom::ResolveResultPtr
255 TypeConverter<service_manager::mojom::ResolveResultPtr, const catalog::Entry*> 237 TypeConverter<service_manager::mojom::ResolveResultPtr, const catalog::Entry*>
256 ::Convert(const catalog::Entry* input) { 238 ::Convert(const catalog::Entry* input) {
257 service_manager::mojom::ResolveResultPtr result; 239 service_manager::mojom::ResolveResultPtr result;
258 if (input) { 240 if (input) {
259 result = service_manager::mojom::ResolveResult::New(); 241 result = service_manager::mojom::ResolveResult::New();
260 result->name = input->name(); 242 result->name = input->name();
261 result->interface_provider_specs = input->interface_provider_specs(); 243 result->interface_provider_specs = input->interface_provider_specs();
262 result->package_path = input->path(); 244 result->package_path = input->path();
263 } 245 }
264 return result; 246 return result;
265 } 247 }
266 248
267 // static 249 // static
268 catalog::mojom::EntryPtr 250 catalog::mojom::EntryPtr
269 TypeConverter<catalog::mojom::EntryPtr, catalog::Entry>::Convert( 251 TypeConverter<catalog::mojom::EntryPtr, catalog::Entry>::Convert(
270 const catalog::Entry& input) { 252 const catalog::Entry& input) {
271 catalog::mojom::EntryPtr result(catalog::mojom::Entry::New()); 253 catalog::mojom::EntryPtr result(catalog::mojom::Entry::New());
272 result->name = input.name(); 254 result->name = input.name();
273 result->display_name = input.display_name(); 255 result->display_name = input.display_name();
274 return result; 256 return result;
275 } 257 }
276 258
277 } // namespace mojo 259 } // namespace mojo
OLDNEW
« no previous file with comments | « services/catalog/entry.h ('k') | services/catalog/entry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698