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

Unified Diff: mojo/services/catalog/builder.cc

Issue 1779683002: Add catalog unittests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@43catalog
Patch Set: . Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/services/catalog/builder.h ('k') | mojo/services/catalog/builder_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/services/catalog/builder.cc
diff --git a/mojo/services/catalog/builder.cc b/mojo/services/catalog/builder.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cd0111208ea4871d5328ebaad356e4405cea3045
--- /dev/null
+++ b/mojo/services/catalog/builder.cc
@@ -0,0 +1,64 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/services/catalog/builder.h"
+
+#include "base/values.h"
+#include "mojo/services/catalog/store.h"
+#include "mojo/shell/public/cpp/names.h"
+
+namespace catalog {
+
+CapabilityFilter BuildCapabilityFilter(const base::DictionaryValue& value) {
+ CapabilityFilter filter;
+ base::DictionaryValue::Iterator it(value);
+ for (; !it.IsAtEnd(); it.Advance()) {
+ const base::ListValue* values = nullptr;
+ CHECK(it.value().GetAsList(&values));
+ AllowedInterfaces interfaces;
+ for (auto i = values->begin(); i != values->end(); ++i) {
+ std::string iface_name;
+ const base::Value* v = *i;
+ CHECK(v->GetAsString(&iface_name));
+ interfaces.insert(iface_name);
+ }
+ filter[it.key()] = interfaces;
+ }
+ return filter;
+}
+
+Entry BuildEntry(const base::DictionaryValue& value) {
+ Entry entry;
+ std::string name_string;
+ CHECK(value.GetString(Store::kNameKey, &name_string));
+ CHECK(mojo::IsValidName(name_string)) << "Invalid Name: " << name_string;
+ entry.name = name_string;
+ if (value.HasKey(Store::kQualifierKey)) {
+ CHECK(value.GetString(Store::kQualifierKey, &entry.qualifier));
+ } else {
+ entry.qualifier = mojo::GetNamePath(name_string);
+ }
+ CHECK(value.GetString(Store::kDisplayNameKey, &entry.display_name));
+ const base::DictionaryValue* capabilities = nullptr;
+ CHECK(value.GetDictionary(Store::kCapabilitiesKey, &capabilities));
+ entry.capabilities = BuildCapabilityFilter(*capabilities);
+
+ return entry;
+}
+
+void SerializeEntry(const Entry& entry, base::DictionaryValue** value) {
+ *value = new base::DictionaryValue;
+ (*value)->SetString(Store::kNameKey, entry.name);
+ (*value)->SetString(Store::kDisplayNameKey, entry.display_name);
+ base::DictionaryValue* capabilities = new base::DictionaryValue;
+ for (const auto& pair : entry.capabilities) {
+ scoped_ptr<base::ListValue> interfaces(new base::ListValue);
+ for (const auto& iface_name : pair.second)
+ interfaces->AppendString(iface_name);
+ capabilities->Set(pair.first, std::move(interfaces));
+ }
+ (*value)->Set(Store::kCapabilitiesKey, make_scoped_ptr(capabilities));
+}
+
+} // namespace catalog
« no previous file with comments | « mojo/services/catalog/builder.h ('k') | mojo/services/catalog/builder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698