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

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

Issue 2684433003: Files required by a service now listed in manifest. (Closed)
Patch Set: Removed unused method in apk_assets 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
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 RequiredFileMap required_files;
180 catalog::PopulateRequiredFiles(value, &required_files);
181 for (const auto& iter : required_files) {
182 entry->AddRequiredFileDescritor(iter.first, iter.second);
dcheng 2017/02/15 08:05:27 The naming also feels a little unusual: there's no
Jay Civelli 2017/02/15 19:53:47 You are right, especially since everything else us
183 }
184
209 if (value.HasKey(Store::kServicesKey)) { 185 if (value.HasKey(Store::kServicesKey)) {
210 const base::ListValue* services = nullptr; 186 const base::ListValue* services = nullptr;
211 value.GetList(Store::kServicesKey, &services); 187 value.GetList(Store::kServicesKey, &services);
212 for (size_t i = 0; i < services->GetSize(); ++i) { 188 for (size_t i = 0; i < services->GetSize(); ++i) {
213 const base::DictionaryValue* service = nullptr; 189 const base::DictionaryValue* service = nullptr;
214 services->GetDictionary(i, &service); 190 services->GetDictionary(i, &service);
215 std::unique_ptr<Entry> child = Entry::Deserialize(*service); 191 std::unique_ptr<Entry> child = Entry::Deserialize(*service);
216 if (child) { 192 if (child) {
217 child->set_parent(entry.get()); 193 child->set_parent(entry.get());
218 entry->children().emplace_back(std::move(child)); 194 entry->children().emplace_back(std::move(child));
(...skipping 20 matching lines...) Expand all
239 other.display_name_ == display_name_ && 215 other.display_name_ == display_name_ &&
240 other.interface_provider_specs_ == interface_provider_specs_; 216 other.interface_provider_specs_ == interface_provider_specs_;
241 } 217 }
242 218
243 void Entry::AddInterfaceProviderSpec( 219 void Entry::AddInterfaceProviderSpec(
244 const std::string& name, 220 const std::string& name,
245 const service_manager::InterfaceProviderSpec& spec) { 221 const service_manager::InterfaceProviderSpec& spec) {
246 interface_provider_specs_[name] = spec; 222 interface_provider_specs_[name] = spec;
247 } 223 }
248 224
225 void Entry::AddRequiredFileDescritor(const std::string& name,
226 const std::string& path) {
227 required_file_paths_[name] = path;
228 }
229
249 } // catalog 230 } // catalog
250 231
251 namespace mojo { 232 namespace mojo {
252 233
253 // static 234 // static
254 service_manager::mojom::ResolveResultPtr 235 service_manager::mojom::ResolveResultPtr
255 TypeConverter<service_manager::mojom::ResolveResultPtr, const catalog::Entry*> 236 TypeConverter<service_manager::mojom::ResolveResultPtr, const catalog::Entry*>
256 ::Convert(const catalog::Entry* input) { 237 ::Convert(const catalog::Entry* input) {
257 service_manager::mojom::ResolveResultPtr result; 238 service_manager::mojom::ResolveResultPtr result;
258 if (input) { 239 if (input) {
259 result = service_manager::mojom::ResolveResult::New(); 240 result = service_manager::mojom::ResolveResult::New();
260 result->name = input->name(); 241 result->name = input->name();
261 result->interface_provider_specs = input->interface_provider_specs(); 242 result->interface_provider_specs = input->interface_provider_specs();
262 result->package_path = input->path(); 243 result->package_path = input->path();
263 } 244 }
264 return result; 245 return result;
265 } 246 }
266 247
267 // static 248 // static
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698