OLD | NEW |
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.h" | 5 #include "services/service_manager/public/cpp/service.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "services/service_manager/public/cpp/service_context.h" | 8 #include "services/service_manager/public/cpp/service_context.h" |
9 #include "services/service_manager/public/interfaces/interface_provider.mojom.h" | |
10 #include "services/service_manager/public/interfaces/interface_provider_spec.moj
om.h" | |
11 | 9 |
12 namespace service_manager { | 10 namespace service_manager { |
13 | 11 |
14 Service::Service() = default; | 12 Service::Service() = default; |
15 | 13 |
16 Service::~Service() = default; | 14 Service::~Service() = default; |
17 | 15 |
18 void Service::OnStart() {} | 16 void Service::OnStart() {} |
19 | 17 |
20 bool Service::OnConnect(const ServiceInfo& remote_info, | |
21 InterfaceRegistry* registry) { | |
22 return false; | |
23 } | |
24 | |
25 void Service::OnBindInterface(const ServiceInfo& source_info, | 18 void Service::OnBindInterface(const ServiceInfo& source_info, |
26 const std::string& interface_name, | 19 const std::string& interface_name, |
27 mojo::ScopedMessagePipeHandle interface_pipe) { | 20 mojo::ScopedMessagePipeHandle interface_pipe) {} |
28 // TODO(beng): Eliminate this implementation once everyone is migrated to | |
29 // OnBindInterface(). | |
30 mojom::InterfaceProviderPtr interface_provider; | |
31 InterfaceProviderSpec source_spec, target_spec; | |
32 GetInterfaceProviderSpec( | |
33 mojom::kServiceManager_ConnectorSpec, | |
34 service_context_->local_info().interface_provider_specs, | |
35 &target_spec); | |
36 GetInterfaceProviderSpec( | |
37 mojom::kServiceManager_ConnectorSpec, | |
38 source_info.interface_provider_specs, | |
39 &source_spec); | |
40 service_context_->CallOnConnect(source_info, source_spec, target_spec, | |
41 MakeRequest(&interface_provider)); | |
42 interface_provider->GetInterface(interface_name, std::move(interface_pipe)); | |
43 } | |
44 | 21 |
45 bool Service::OnServiceManagerConnectionLost() { | 22 bool Service::OnServiceManagerConnectionLost() { |
46 return true; | 23 return true; |
47 } | 24 } |
48 | 25 |
49 ServiceContext* Service::context() const { | 26 ServiceContext* Service::context() const { |
50 DCHECK(service_context_) | 27 DCHECK(service_context_) |
51 << "Service::context() may only be called after the Service constructor."; | 28 << "Service::context() may only be called after the Service constructor."; |
52 return service_context_; | 29 return service_context_; |
53 } | 30 } |
54 | 31 |
55 void Service::SetContext(ServiceContext* context) { | 32 void Service::SetContext(ServiceContext* context) { |
56 service_context_ = context; | 33 service_context_ = context; |
57 } | 34 } |
58 | 35 |
59 ForwardingService::ForwardingService(Service* target) : target_(target) {} | 36 ForwardingService::ForwardingService(Service* target) : target_(target) {} |
60 | 37 |
61 ForwardingService::~ForwardingService() {} | 38 ForwardingService::~ForwardingService() {} |
62 | 39 |
63 void ForwardingService::OnStart() { | 40 void ForwardingService::OnStart() { |
64 target_->OnStart(); | 41 target_->OnStart(); |
65 } | 42 } |
66 | 43 |
67 bool ForwardingService::OnConnect(const ServiceInfo& remote_info, | |
68 InterfaceRegistry* registry) { | |
69 return target_->OnConnect(remote_info, registry); | |
70 } | |
71 | |
72 void ForwardingService::OnBindInterface( | 44 void ForwardingService::OnBindInterface( |
73 const ServiceInfo& remote_info, | 45 const ServiceInfo& remote_info, |
74 const std::string& interface_name, | 46 const std::string& interface_name, |
75 mojo::ScopedMessagePipeHandle interface_pipe) { | 47 mojo::ScopedMessagePipeHandle interface_pipe) { |
76 target_->OnBindInterface(remote_info, interface_name, | 48 target_->OnBindInterface(remote_info, interface_name, |
77 std::move(interface_pipe)); | 49 std::move(interface_pipe)); |
78 } | 50 } |
79 | 51 |
80 bool ForwardingService::OnServiceManagerConnectionLost() { | 52 bool ForwardingService::OnServiceManagerConnectionLost() { |
81 return target_->OnServiceManagerConnectionLost(); | 53 return target_->OnServiceManagerConnectionLost(); |
82 } | 54 } |
83 | 55 |
84 void ForwardingService::SetContext(ServiceContext* context) { | 56 void ForwardingService::SetContext(ServiceContext* context) { |
85 target_->SetContext(context); | 57 target_->SetContext(context); |
86 } | 58 } |
87 | 59 |
88 } // namespace service_manager | 60 } // namespace service_manager |
OLD | NEW |