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

Side by Side Diff: services/service_manager/public/cpp/lib/service_context.cc

Issue 2446313003: Revise InterfaceRegistry API to support filtering interfaces @ Bind() time. (Closed)
Patch Set: . Created 4 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/service_manager/public/cpp/service_context.h" 5 #include "services/service_manager/public/cpp/service_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "mojo/public/cpp/bindings/interface_ptr.h" 10 #include "mojo/public/cpp/bindings/interface_ptr.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 if (should_run_connection_lost_closure_ && 44 if (should_run_connection_lost_closure_ &&
45 !connection_lost_closure_.is_null()) 45 !connection_lost_closure_.is_null())
46 connection_lost_closure_.Run(); 46 connection_lost_closure_.Run();
47 } 47 }
48 48
49 //////////////////////////////////////////////////////////////////////////////// 49 ////////////////////////////////////////////////////////////////////////////////
50 // ServiceContext, mojom::Service implementation: 50 // ServiceContext, mojom::Service implementation:
51 51
52 void ServiceContext::OnStart(const ServiceInfo& info, 52 void ServiceContext::OnStart(const ServiceInfo& info,
53 const OnStartCallback& callback) { 53 const OnStartCallback& callback) {
54 identity_ = info.identity; 54 local_info_ = info;
55 if (!initialize_handler_.is_null()) 55 if (!initialize_handler_.is_null())
56 initialize_handler_.Run(); 56 initialize_handler_.Run();
57 57
58 callback.Run(std::move(pending_connector_request_)); 58 callback.Run(std::move(pending_connector_request_));
59 59
60 service_->OnStart(info); 60 service_->OnStart(info);
61 } 61 }
62 62
63 void ServiceContext::OnConnect( 63 void ServiceContext::OnConnect(
64 const ServiceInfo& source_info, 64 const ServiceInfo& source_info,
65 mojom::InterfaceProviderRequest interfaces, 65 mojom::InterfaceProviderRequest interfaces) {
66 const InterfaceSet& allowed_interfaces, 66 auto target_it = local_info_.interface_provider_specs.find(
67 const CapabilitySet& allowed_capabilities) { 67 mojom::kServiceManager_ConnectorSpec);
68 // TODO(beng): do something with |allowed_capabilities|. 68 InterfaceProviderSpec target_spec;
69 auto registry = base::MakeUnique<InterfaceRegistry>( 69 if (target_it != local_info_.interface_provider_specs.end())
70 identity_, source_info.identity, allowed_interfaces); 70 target_spec = target_it->second;
71 registry->Bind(std::move(interfaces)); 71 auto source_it = source_info.interface_provider_specs.find(
72 mojom::kServiceManager_ConnectorSpec);
73 InterfaceProviderSpec source_spec;
74 if (source_it != source_info.interface_provider_specs.end())
75 source_spec = source_it->second;
76
77 auto registry = base::MakeUnique<InterfaceRegistry>(local_info_.identity,
78 target_spec);
79 registry->Bind(std::move(interfaces), source_info.identity, source_spec);
72 80
73 if (!service_->OnConnect(source_info, registry.get())) 81 if (!service_->OnConnect(source_info, registry.get()))
74 return; 82 return;
75 83
76 // TODO(beng): it appears we never prune this list. We should, when the 84 // TODO(beng): it appears we never prune this list. We should, when the
77 // registry's remote interface provider pipe breaks. 85 // registry's remote interface provider pipe breaks.
78 incoming_connections_.push_back(std::move(registry)); 86 incoming_connections_.push_back(std::move(registry));
79 } 87 }
80 88
81 //////////////////////////////////////////////////////////////////////////////// 89 ////////////////////////////////////////////////////////////////////////////////
82 // ServiceContext, private: 90 // ServiceContext, private:
83 91
84 void ServiceContext::OnConnectionError() { 92 void ServiceContext::OnConnectionError() {
85 // Note that the Service doesn't technically have to quit now, it may live 93 // Note that the Service doesn't technically have to quit now, it may live
86 // on to service existing connections. All existing Connectors however are 94 // on to service existing connections. All existing Connectors however are
87 // invalid. 95 // invalid.
88 should_run_connection_lost_closure_ = service_->OnStop(); 96 should_run_connection_lost_closure_ = service_->OnStop();
89 if (should_run_connection_lost_closure_ && 97 if (should_run_connection_lost_closure_ &&
90 !connection_lost_closure_.is_null()) 98 !connection_lost_closure_.is_null())
91 connection_lost_closure_.Run(); 99 connection_lost_closure_.Run();
92 // We don't reset the connector as clients may have taken a raw pointer to it. 100 // We don't reset the connector as clients may have taken a raw pointer to it.
93 // Connect() will return nullptr if they try to connect to anything. 101 // Connect() will return nullptr if they try to connect to anything.
94 } 102 }
95 103
96 } // namespace service_manager 104 } // namespace service_manager
OLDNEW
« no previous file with comments | « services/service_manager/public/cpp/lib/interface_registry.cc ('k') | services/service_manager/public/cpp/service_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698