| 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_context.h" | 5 #include "services/service_manager/public/cpp/service_context.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 ServiceContext::ServiceContext( | 27 ServiceContext::ServiceContext( |
| 28 std::unique_ptr<service_manager::Service> service, | 28 std::unique_ptr<service_manager::Service> service, |
| 29 mojom::ServiceRequest request, | 29 mojom::ServiceRequest request, |
| 30 std::unique_ptr<Connector> connector, | 30 std::unique_ptr<Connector> connector, |
| 31 mojom::ConnectorRequest connector_request) | 31 mojom::ConnectorRequest connector_request) |
| 32 : pending_connector_request_(std::move(connector_request)), | 32 : pending_connector_request_(std::move(connector_request)), |
| 33 service_(std::move(service)), | 33 service_(std::move(service)), |
| 34 binding_(this, std::move(request)), | 34 binding_(this, std::move(request)), |
| 35 connector_(std::move(connector)), | 35 connector_(std::move(connector)), |
| 36 weak_factory_(this) { | 36 weak_factory_(this) { |
| 37 LOG(INFO) << "ServiceContext::ServiceContext"; |
| 37 DCHECK(binding_.is_bound()); | 38 DCHECK(binding_.is_bound()); |
| 38 binding_.set_connection_error_handler( | 39 binding_.set_connection_error_handler( |
| 39 base::Bind(&ServiceContext::OnConnectionError, base::Unretained(this))); | 40 base::Bind(&ServiceContext::OnConnectionError, base::Unretained(this))); |
| 40 if (!connector_) { | 41 if (!connector_) { |
| 41 connector_ = Connector::Create(&pending_connector_request_); | 42 connector_ = Connector::Create(&pending_connector_request_); |
| 42 } else { | 43 } else { |
| 43 DCHECK(pending_connector_request_.is_pending()); | 44 DCHECK(pending_connector_request_.is_pending()); |
| 44 } | 45 } |
| 45 } | 46 } |
| 46 | 47 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 73 void ServiceContext::DestroyService() { | 74 void ServiceContext::DestroyService() { |
| 74 QuitNow(); | 75 QuitNow(); |
| 75 service_.reset(); | 76 service_.reset(); |
| 76 } | 77 } |
| 77 | 78 |
| 78 //////////////////////////////////////////////////////////////////////////////// | 79 //////////////////////////////////////////////////////////////////////////////// |
| 79 // ServiceContext, mojom::Service implementation: | 80 // ServiceContext, mojom::Service implementation: |
| 80 | 81 |
| 81 void ServiceContext::OnStart(const ServiceInfo& info, | 82 void ServiceContext::OnStart(const ServiceInfo& info, |
| 82 const OnStartCallback& callback) { | 83 const OnStartCallback& callback) { |
| 84 LOG(INFO) << "ServiceContext::OnStart: " << info.identity.name(); |
| 83 local_info_ = info; | 85 local_info_ = info; |
| 84 callback.Run( | 86 callback.Run( |
| 85 std::move(pending_connector_request_), | 87 std::move(pending_connector_request_), |
| 86 mojo::MakeRequest(&service_control_, binding_.associated_group())); | 88 mojo::MakeRequest(&service_control_, binding_.associated_group())); |
| 87 | 89 |
| 88 service_->set_context(this); | 90 service_->set_context(this); |
| 89 service_->OnStart(); | 91 service_->OnStart(); |
| 90 } | 92 } |
| 91 | 93 |
| 92 void ServiceContext::OnConnect( | 94 void ServiceContext::OnConnect( |
| 93 const ServiceInfo& source_info, | 95 const ServiceInfo& source_info, |
| 94 mojom::InterfaceProviderRequest interfaces, | 96 mojom::InterfaceProviderRequest interfaces, |
| 95 const OnConnectCallback& callback) { | 97 const OnConnectCallback& callback) { |
| 98 LOG(INFO) << "ServiceContext::OnConnect"; |
| 96 InterfaceProviderSpec source_spec, target_spec; | 99 InterfaceProviderSpec source_spec, target_spec; |
| 97 GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, | 100 GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, |
| 98 local_info_.interface_provider_specs, &target_spec); | 101 local_info_.interface_provider_specs, &target_spec); |
| 99 GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, | 102 GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, |
| 100 source_info.interface_provider_specs, &source_spec); | 103 source_info.interface_provider_specs, &source_spec); |
| 101 | 104 |
| 102 // Acknowledge the request regardless of whether it's accepted. | 105 // Acknowledge the request regardless of whether it's accepted. |
| 103 callback.Run(); | 106 callback.Run(); |
| 104 | 107 |
| 105 CallOnConnect(source_info, source_spec, target_spec, std::move(interfaces)); | 108 CallOnConnect(source_info, source_spec, target_spec, std::move(interfaces)); |
| 106 } | 109 } |
| 107 | 110 |
| 108 void ServiceContext::OnBindInterface( | 111 void ServiceContext::OnBindInterface( |
| 109 const ServiceInfo& source_info, | 112 const ServiceInfo& source_info, |
| 110 const std::string& interface_name, | 113 const std::string& interface_name, |
| 111 mojo::ScopedMessagePipeHandle interface_pipe, | 114 mojo::ScopedMessagePipeHandle interface_pipe, |
| 112 const OnBindInterfaceCallback& callback) { | 115 const OnBindInterfaceCallback& callback) { |
| 116 LOG(INFO) << "ServiceContext::OnBindInterface: " << interface_name; |
| 113 // Acknowledge the request regardless of whether it's accepted. | 117 // Acknowledge the request regardless of whether it's accepted. |
| 114 callback.Run(); | 118 callback.Run(); |
| 115 | 119 |
| 116 service_->OnBindInterface(source_info, interface_name, | 120 service_->OnBindInterface(source_info, interface_name, |
| 117 std::move(interface_pipe)); | 121 std::move(interface_pipe)); |
| 118 } | 122 } |
| 119 | 123 |
| 120 //////////////////////////////////////////////////////////////////////////////// | 124 //////////////////////////////////////////////////////////////////////////////// |
| 121 // ServiceContext, private: | 125 // ServiceContext, private: |
| 122 | 126 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } | 171 } |
| 168 | 172 |
| 169 void ServiceContext::DestroyConnectionInterfaceRegistry( | 173 void ServiceContext::DestroyConnectionInterfaceRegistry( |
| 170 InterfaceRegistry* registry) { | 174 InterfaceRegistry* registry) { |
| 171 auto it = connection_interface_registries_.find(registry); | 175 auto it = connection_interface_registries_.find(registry); |
| 172 CHECK(it != connection_interface_registries_.end()); | 176 CHECK(it != connection_interface_registries_.end()); |
| 173 connection_interface_registries_.erase(it); | 177 connection_interface_registries_.erase(it); |
| 174 } | 178 } |
| 175 | 179 |
| 176 } // namespace service_manager | 180 } // namespace service_manager |
| OLD | NEW |