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

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

Issue 1882423004: Move shell service to toplevel shell namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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/values.h" 7 #include "base/values.h"
8 #include "mojo/util/filename_util.h" 8 #include "mojo/util/filename_util.h"
9 #include "services/catalog/store.h" 9 #include "services/catalog/store.h"
10 #include "services/shell/public/cpp/names.h" 10 #include "services/shell/public/cpp/names.h"
11 #include "url/gurl.h" 11 #include "url/gurl.h"
12 12
13 namespace catalog { 13 namespace catalog {
14 namespace { 14 namespace {
15 15
16 mojo::CapabilitySpec BuildCapabilitiesV0( 16 shell::CapabilitySpec BuildCapabilitiesV0(const base::DictionaryValue& value) {
17 const base::DictionaryValue& value) { 17 shell::CapabilitySpec capabilities;
18 mojo::CapabilitySpec capabilities;
19 base::DictionaryValue::Iterator it(value); 18 base::DictionaryValue::Iterator it(value);
20 for (; !it.IsAtEnd(); it.Advance()) { 19 for (; !it.IsAtEnd(); it.Advance()) {
21 const base::ListValue* values = nullptr; 20 const base::ListValue* values = nullptr;
22 CHECK(it.value().GetAsList(&values)); 21 CHECK(it.value().GetAsList(&values));
23 mojo::CapabilityRequest spec; 22 shell::CapabilityRequest spec;
24 for (auto i = values->begin(); i != values->end(); ++i) { 23 for (auto i = values->begin(); i != values->end(); ++i) {
25 mojo::Interface interface_name; 24 shell::Interface interface_name;
26 const base::Value* v = *i; 25 const base::Value* v = *i;
27 CHECK(v->GetAsString(&interface_name)); 26 CHECK(v->GetAsString(&interface_name));
28 spec.interfaces.insert(interface_name); 27 spec.interfaces.insert(interface_name);
29 } 28 }
30 capabilities.required[it.key()] = spec; 29 capabilities.required[it.key()] = spec;
31 } 30 }
32 return capabilities; 31 return capabilities;
33 } 32 }
34 33
35 void ReadStringSet(const base::ListValue& list_value, 34 void ReadStringSet(const base::ListValue& list_value,
(...skipping 17 matching lines...) Expand all
53 void ReadStringSetFromDictionary(const base::DictionaryValue& dictionary, 52 void ReadStringSetFromDictionary(const base::DictionaryValue& dictionary,
54 const std::string& key, 53 const std::string& key,
55 std::set<std::string>* string_set) { 54 std::set<std::string>* string_set) {
56 const base::ListValue* list_value = nullptr; 55 const base::ListValue* list_value = nullptr;
57 if (dictionary.HasKey(key)) 56 if (dictionary.HasKey(key))
58 CHECK(dictionary.GetList(key, &list_value)); 57 CHECK(dictionary.GetList(key, &list_value));
59 if (list_value) 58 if (list_value)
60 ReadStringSet(*list_value, string_set); 59 ReadStringSet(*list_value, string_set);
61 } 60 }
62 61
63 mojo::CapabilitySpec BuildCapabilitiesV1( 62 shell::CapabilitySpec BuildCapabilitiesV1(const base::DictionaryValue& value) {
64 const base::DictionaryValue& value) { 63 shell::CapabilitySpec capabilities;
65 mojo::CapabilitySpec capabilities;
66 64
67 const base::DictionaryValue* provided_value = nullptr; 65 const base::DictionaryValue* provided_value = nullptr;
68 if (value.HasKey(Store::kCapabilities_ProvidedKey)) { 66 if (value.HasKey(Store::kCapabilities_ProvidedKey)) {
69 CHECK(value.GetDictionary(Store::kCapabilities_ProvidedKey, 67 CHECK(value.GetDictionary(Store::kCapabilities_ProvidedKey,
70 &provided_value)); 68 &provided_value));
71 } 69 }
72 if (provided_value) { 70 if (provided_value) {
73 mojo::CapabilityRequest provided; 71 shell::CapabilityRequest provided;
74 base::DictionaryValue::Iterator it(*provided_value); 72 base::DictionaryValue::Iterator it(*provided_value);
75 for(; !it.IsAtEnd(); it.Advance()) { 73 for(; !it.IsAtEnd(); it.Advance()) {
76 mojo::Interfaces interfaces; 74 shell::Interfaces interfaces;
77 ReadStringSetFromValue(it.value(), &interfaces); 75 ReadStringSetFromValue(it.value(), &interfaces);
78 capabilities.provided[it.key()] = interfaces; 76 capabilities.provided[it.key()] = interfaces;
79 } 77 }
80 } 78 }
81 79
82 const base::DictionaryValue* required_value = nullptr; 80 const base::DictionaryValue* required_value = nullptr;
83 if (value.HasKey(Store::kCapabilities_RequiredKey)) { 81 if (value.HasKey(Store::kCapabilities_RequiredKey)) {
84 CHECK(value.GetDictionary(Store::kCapabilities_RequiredKey, 82 CHECK(value.GetDictionary(Store::kCapabilities_RequiredKey,
85 &required_value)); 83 &required_value));
86 } 84 }
87 if (required_value) { 85 if (required_value) {
88 base::DictionaryValue::Iterator it(*required_value); 86 base::DictionaryValue::Iterator it(*required_value);
89 for (; !it.IsAtEnd(); it.Advance()) { 87 for (; !it.IsAtEnd(); it.Advance()) {
90 mojo::CapabilityRequest spec; 88 shell::CapabilityRequest spec;
91 const base::DictionaryValue* entry_value = nullptr; 89 const base::DictionaryValue* entry_value = nullptr;
92 CHECK(it.value().GetAsDictionary(&entry_value)); 90 CHECK(it.value().GetAsDictionary(&entry_value));
93 ReadStringSetFromDictionary( 91 ReadStringSetFromDictionary(
94 *entry_value, Store::kCapabilities_ClassesKey, &spec.classes); 92 *entry_value, Store::kCapabilities_ClassesKey, &spec.classes);
95 ReadStringSetFromDictionary( 93 ReadStringSetFromDictionary(
96 *entry_value, Store::kCapabilities_InterfacesKey, &spec.interfaces); 94 *entry_value, Store::kCapabilities_InterfacesKey, &spec.interfaces);
97 capabilities.required[it.key()] = spec; 95 capabilities.required[it.key()] = spec;
98 } 96 }
99 } 97 }
100 return capabilities; 98 return capabilities;
101 } 99 }
102 100
103 } // namespace 101 } // namespace
104 102
105 Entry::Entry() {} 103 Entry::Entry() {}
106 Entry::Entry(const std::string& name) 104 Entry::Entry(const std::string& name)
107 : name_(name), 105 : name_(name), qualifier_(shell::GetNamePath(name)), display_name_(name) {}
108 qualifier_(mojo::GetNamePath(name)),
109 display_name_(name) {}
110 Entry::Entry(const Entry& other) = default; 106 Entry::Entry(const Entry& other) = default;
111 Entry::~Entry() {} 107 Entry::~Entry() {}
112 108
113 scoped_ptr<base::DictionaryValue> Entry::Serialize() const { 109 scoped_ptr<base::DictionaryValue> Entry::Serialize() const {
114 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); 110 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue);
115 value->SetInteger(Store::kManifestVersionKey, 1); 111 value->SetInteger(Store::kManifestVersionKey, 1);
116 value->SetString(Store::kNameKey, name_); 112 value->SetString(Store::kNameKey, name_);
117 value->SetString(Store::kDisplayNameKey, display_name_); 113 value->SetString(Store::kDisplayNameKey, display_name_);
118 value->SetString(Store::kQualifierKey, qualifier_); 114 value->SetString(Store::kQualifierKey, qualifier_);
119 scoped_ptr<base::DictionaryValue> spec(new base::DictionaryValue); 115 scoped_ptr<base::DictionaryValue> spec(new base::DictionaryValue);
(...skipping 30 matching lines...) Expand all
150 scoped_ptr<Entry> Entry::Deserialize(const base::DictionaryValue& value) { 146 scoped_ptr<Entry> Entry::Deserialize(const base::DictionaryValue& value) {
151 scoped_ptr<Entry> entry(new Entry); 147 scoped_ptr<Entry> entry(new Entry);
152 int manifest_version = 0; 148 int manifest_version = 0;
153 if (value.HasKey(Store::kManifestVersionKey)) 149 if (value.HasKey(Store::kManifestVersionKey))
154 CHECK(value.GetInteger(Store::kManifestVersionKey, &manifest_version)); 150 CHECK(value.GetInteger(Store::kManifestVersionKey, &manifest_version));
155 std::string name_string; 151 std::string name_string;
156 if (!value.GetString(Store::kNameKey, &name_string)) { 152 if (!value.GetString(Store::kNameKey, &name_string)) {
157 LOG(ERROR) << "Entry::Deserialize: dictionary has no name key"; 153 LOG(ERROR) << "Entry::Deserialize: dictionary has no name key";
158 return nullptr; 154 return nullptr;
159 } 155 }
160 if (!mojo::IsValidName(name_string)) { 156 if (!shell::IsValidName(name_string)) {
161 LOG(WARNING) << "Entry::Deserialize: " << name_string << " is not a valid " 157 LOG(WARNING) << "Entry::Deserialize: " << name_string << " is not a valid "
162 << "Mojo name"; 158 << "Mojo name";
163 return nullptr; 159 return nullptr;
164 } 160 }
165 entry->set_name(name_string); 161 entry->set_name(name_string);
166 if (value.HasKey(Store::kQualifierKey)) { 162 if (value.HasKey(Store::kQualifierKey)) {
167 std::string qualifier; 163 std::string qualifier;
168 CHECK(value.GetString(Store::kQualifierKey, &qualifier)); 164 CHECK(value.GetString(Store::kQualifierKey, &qualifier));
169 entry->set_qualifier(qualifier); 165 entry->set_qualifier(qualifier);
170 } else { 166 } else {
171 entry->set_qualifier(mojo::GetNamePath(name_string)); 167 entry->set_qualifier(shell::GetNamePath(name_string));
172 } 168 }
173 std::string display_name; 169 std::string display_name;
174 if (!value.GetString(Store::kDisplayNameKey, &display_name)) { 170 if (!value.GetString(Store::kDisplayNameKey, &display_name)) {
175 LOG(WARNING) << "Entry::Deserialize: dictionary has no display_name key"; 171 LOG(WARNING) << "Entry::Deserialize: dictionary has no display_name key";
176 return nullptr; 172 return nullptr;
177 } 173 }
178 entry->set_display_name(display_name); 174 entry->set_display_name(display_name);
179 const base::DictionaryValue* capabilities = nullptr; 175 const base::DictionaryValue* capabilities = nullptr;
180 if (!value.GetDictionary(Store::kCapabilitiesKey, &capabilities)) { 176 if (!value.GetDictionary(Store::kCapabilitiesKey, &capabilities)) {
181 LOG(WARNING) << "Entry::Description: dictionary has no capabilities key"; 177 LOG(WARNING) << "Entry::Description: dictionary has no capabilities key";
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 const catalog::Entry& package = input.package() ? *input.package() : input; 225 const catalog::Entry& package = input.package() ? *input.package() : input;
230 result->resolved_name = package.name(); 226 result->resolved_name = package.name();
231 result->qualifier = input.qualifier(); 227 result->qualifier = input.qualifier();
232 result->capabilities = 228 result->capabilities =
233 shell::mojom::CapabilitySpec::From(input.capabilities()); 229 shell::mojom::CapabilitySpec::From(input.capabilities());
234 result->package_url = mojo::util::FilePathToFileURL(package.path()).spec(); 230 result->package_url = mojo::util::FilePathToFileURL(package.path()).spec();
235 return result; 231 return result;
236 } 232 }
237 233
238 } // namespace mojo 234 } // 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