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

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

Issue 2645973006: [Service Manager] Get rid of dynamic service discovery (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
« no previous file with comments | « services/catalog/instance.h ('k') | services/catalog/public/tools/catalog.gni » ('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/instance.h" 5 #include "services/catalog/instance.h"
6 6
7 #include <memory>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/values.h"
8 #include "services/catalog/entry.h" 11 #include "services/catalog/entry.h"
9 #include "services/catalog/entry_cache.h" 12 #include "services/catalog/entry_cache.h"
10 #include "services/catalog/manifest_provider.h" 13 #include "services/catalog/manifest_provider.h"
11 #include "services/catalog/reader.h"
12 14
13 namespace catalog { 15 namespace catalog {
14 namespace { 16 namespace {
15 17
16 void AddEntry(const Entry& entry, std::vector<mojom::EntryPtr>* ary) { 18 void AddEntry(const Entry& entry, std::vector<mojom::EntryPtr>* ary) {
17 mojom::EntryPtr entry_ptr(mojom::Entry::New()); 19 mojom::EntryPtr entry_ptr(mojom::Entry::New());
18 entry_ptr->name = entry.name(); 20 entry_ptr->name = entry.name();
19 entry_ptr->display_name = entry.display_name(); 21 entry_ptr->display_name = entry.display_name();
20 ary->push_back(std::move(entry_ptr)); 22 ary->push_back(std::move(entry_ptr));
21 } 23 }
22 24
23 } // namespace 25 } // namespace
24 26
25 Instance::Instance(Reader* system_reader) : system_reader_(system_reader) {} 27 Instance::Instance(EntryCache* system_cache,
28 ManifestProvider* service_manifest_provider)
29 : system_cache_(system_cache),
30 service_manifest_provider_(service_manifest_provider) {}
26 31
27 Instance::~Instance() {} 32 Instance::~Instance() {}
28 33
29 void Instance::BindResolver(service_manager::mojom::ResolverRequest request) { 34 void Instance::BindResolver(service_manager::mojom::ResolverRequest request) {
30 if (system_cache_) 35 resolver_bindings_.AddBinding(this, std::move(request));
31 resolver_bindings_.AddBinding(this, std::move(request));
32 else
33 pending_resolver_requests_.push_back(std::move(request));
34 } 36 }
35 37
36 void Instance::BindCatalog(mojom::CatalogRequest request) { 38 void Instance::BindCatalog(mojom::CatalogRequest request) {
37 if (system_cache_) 39 catalog_bindings_.AddBinding(this, std::move(request));
38 catalog_bindings_.AddBinding(this, std::move(request));
39 else
40 pending_catalog_requests_.push_back(std::move(request));
41 }
42
43 void Instance::CacheReady(EntryCache* cache) {
44 system_cache_ = cache;
45 for (auto& request : pending_resolver_requests_)
46 BindResolver(std::move(request));
47 for (auto& request : pending_catalog_requests_)
48 BindCatalog(std::move(request));
49 } 40 }
50 41
51 void Instance::ResolveServiceName(const std::string& service_name, 42 void Instance::ResolveServiceName(const std::string& service_name,
52 const ResolveServiceNameCallback& callback) { 43 const ResolveServiceNameCallback& callback) {
53 DCHECK(system_cache_); 44 DCHECK(system_cache_);
54 45
55 // TODO(beng): per-user catalogs. 46 // TODO(beng): per-user catalogs.
56 const Entry* entry = system_cache_->GetEntry(service_name); 47 const Entry* entry = system_cache_->GetEntry(service_name);
57 if (entry) { 48 if (entry) {
58 callback.Run(service_manager::mojom::ResolveResult::From(entry), 49 callback.Run(service_manager::mojom::ResolveResult::From(entry),
59 service_manager::mojom::ResolveResult::From(entry->parent())); 50 service_manager::mojom::ResolveResult::From(entry->parent()));
60 return; 51 return;
52 } else if (service_manifest_provider_) {
53 auto manifest = service_manifest_provider_->GetManifest(service_name);
54 if (manifest) {
55 auto entry = Entry::Deserialize(*manifest);
56 if (entry) {
57 callback.Run(
58 service_manager::mojom::ResolveResult::From(
59 const_cast<const Entry*>(entry.get())),
60 service_manager::mojom::ResolveResult::From(entry->parent()));
61
62 bool added = system_cache_->AddRootEntry(std::move(entry));
63 DCHECK(added);
64 return;
65 } else {
66 LOG(ERROR) << "Received malformed manifest for " << service_name;
67 }
68 }
61 } 69 }
62 70
63 system_reader_->CreateEntryForName(service_name, system_cache_, callback); 71 LOG(ERROR) << "Unable to locate service manifest for " << service_name;
72 callback.Run(nullptr, nullptr);
64 } 73 }
65 74
66 void Instance::GetEntries(const base::Optional<std::vector<std::string>>& names, 75 void Instance::GetEntries(const base::Optional<std::vector<std::string>>& names,
67 const GetEntriesCallback& callback) { 76 const GetEntriesCallback& callback) {
68 DCHECK(system_cache_); 77 DCHECK(system_cache_);
69 78
70 std::vector<mojom::EntryPtr> entries; 79 std::vector<mojom::EntryPtr> entries;
71 if (!names.has_value()) { 80 if (!names.has_value()) {
72 // TODO(beng): user catalog. 81 // TODO(beng): user catalog.
73 for (const auto& entry : system_cache_->entries()) 82 for (const auto& entry : system_cache_->entries())
(...skipping 25 matching lines...) Expand all
99 // TODO(beng): implement. 108 // TODO(beng): implement.
100 } 109 }
101 110
102 void Instance::GetEntriesSupportingScheme( 111 void Instance::GetEntriesSupportingScheme(
103 const std::string& scheme, 112 const std::string& scheme,
104 const GetEntriesSupportingSchemeCallback& callback) { 113 const GetEntriesSupportingSchemeCallback& callback) {
105 // TODO(beng): implement. 114 // TODO(beng): implement.
106 } 115 }
107 116
108 } // namespace catalog 117 } // namespace catalog
OLDNEW
« no previous file with comments | « services/catalog/instance.h ('k') | services/catalog/public/tools/catalog.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698