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

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

Issue 2611183006: Service Manager: Miscellaneous catalog cleanup (Closed)
Patch Set: Created 3 years, 11 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/instance.h" 5 #include "services/catalog/instance.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "services/catalog/entry.h" 8 #include "services/catalog/entry.h"
9 #include "services/catalog/entry_cache.h"
9 #include "services/catalog/manifest_provider.h" 10 #include "services/catalog/manifest_provider.h"
10 #include "services/catalog/reader.h" 11 #include "services/catalog/reader.h"
11 12
12 namespace catalog { 13 namespace catalog {
13 namespace { 14 namespace {
14 15
15 void AddEntry(const Entry& entry, std::vector<mojom::EntryPtr>* ary) { 16 void AddEntry(const Entry& entry, std::vector<mojom::EntryPtr>* ary) {
16 mojom::EntryPtr entry_ptr(mojom::Entry::New()); 17 mojom::EntryPtr entry_ptr(mojom::Entry::New());
17 entry_ptr->name = entry.name(); 18 entry_ptr->name = entry.name();
18 entry_ptr->display_name = entry.display_name(); 19 entry_ptr->display_name = entry.display_name();
(...skipping 26 matching lines...) Expand all
45 BindResolver(std::move(request)); 46 BindResolver(std::move(request));
46 for (auto& request : pending_catalog_requests_) 47 for (auto& request : pending_catalog_requests_)
47 BindCatalog(std::move(request)); 48 BindCatalog(std::move(request));
48 } 49 }
49 50
50 void Instance::ResolveServiceName(const std::string& service_name, 51 void Instance::ResolveServiceName(const std::string& service_name,
51 const ResolveServiceNameCallback& callback) { 52 const ResolveServiceNameCallback& callback) {
52 DCHECK(system_cache_); 53 DCHECK(system_cache_);
53 54
54 // TODO(beng): per-user catalogs. 55 // TODO(beng): per-user catalogs.
55 auto entry = system_cache_->find(service_name); 56 const Entry* entry = system_cache_->GetEntry(service_name);
56 if (entry != system_cache_->end()) { 57 if (entry) {
57 callback.Run(service_manager::mojom::ResolveResult::From(*entry->second)); 58 callback.Run(service_manager::mojom::ResolveResult::From(entry),
59 service_manager::mojom::ResolveResult::From(entry->parent()));
58 return; 60 return;
59 } 61 }
60 62
61 system_reader_->CreateEntryForName(service_name, system_cache_, callback); 63 system_reader_->CreateEntryForName(service_name, system_cache_, callback);
62 } 64 }
63 65
64 void Instance::GetEntries(const base::Optional<std::vector<std::string>>& names, 66 void Instance::GetEntries(const base::Optional<std::vector<std::string>>& names,
65 const GetEntriesCallback& callback) { 67 const GetEntriesCallback& callback) {
66 DCHECK(system_cache_); 68 DCHECK(system_cache_);
67 69
68 std::vector<mojom::EntryPtr> entries; 70 std::vector<mojom::EntryPtr> entries;
69 if (!names.has_value()) { 71 if (!names.has_value()) {
70 // TODO(beng): user catalog. 72 // TODO(beng): user catalog.
71 for (const auto& entry : *system_cache_) 73 for (const auto& entry : system_cache_->entries())
72 AddEntry(*entry.second, &entries); 74 AddEntry(*entry.second, &entries);
73 } else { 75 } else {
74 for (const std::string& name : names.value()) { 76 for (const std::string& name : names.value()) {
75 Entry* entry = nullptr; 77 const Entry* entry = system_cache_->GetEntry(name);
76 // TODO(beng): user catalog. 78 // TODO(beng): user catalog.
77 if (system_cache_->find(name) != system_cache_->end()) 79 if (entry)
78 entry = (*system_cache_)[name].get(); 80 AddEntry(*entry, &entries);
79 else
80 continue;
81 AddEntry(*entry, &entries);
82 } 81 }
83 } 82 }
84 callback.Run(std::move(entries)); 83 callback.Run(std::move(entries));
85 } 84 }
86 85
87 void Instance::GetEntriesProvidingCapability( 86 void Instance::GetEntriesProvidingCapability(
88 const std::string& capability, 87 const std::string& capability,
89 const GetEntriesProvidingCapabilityCallback& callback) { 88 const GetEntriesProvidingCapabilityCallback& callback) {
90 std::vector<mojom::EntryPtr> entries; 89 std::vector<mojom::EntryPtr> entries;
91 for (const auto& entry : *system_cache_) 90 for (const auto& entry : system_cache_->entries())
92 if (entry.second->ProvidesCapability(capability)) 91 if (entry.second->ProvidesCapability(capability))
93 entries.push_back(mojom::Entry::From(*entry.second)); 92 entries.push_back(mojom::Entry::From(*entry.second));
94 callback.Run(std::move(entries)); 93 callback.Run(std::move(entries));
95 } 94 }
96 95
97 void Instance::GetEntriesConsumingMIMEType( 96 void Instance::GetEntriesConsumingMIMEType(
98 const std::string& mime_type, 97 const std::string& mime_type,
99 const GetEntriesConsumingMIMETypeCallback& callback) { 98 const GetEntriesConsumingMIMETypeCallback& callback) {
100 // TODO(beng): implement. 99 // TODO(beng): implement.
101 } 100 }
102 101
103 void Instance::GetEntriesSupportingScheme( 102 void Instance::GetEntriesSupportingScheme(
104 const std::string& scheme, 103 const std::string& scheme,
105 const GetEntriesSupportingSchemeCallback& callback) { 104 const GetEntriesSupportingSchemeCallback& callback) {
106 // TODO(beng): implement. 105 // TODO(beng): implement.
107 } 106 }
108 107
109 } // namespace catalog 108 } // namespace catalog
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698