| 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 "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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 auto target_it = local_info_.interface_provider_specs.find( | 66 InterfaceProviderSpec source_spec, target_spec; |
| 67 mojom::kServiceManager_ConnectorSpec); | 67 GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, |
| 68 InterfaceProviderSpec target_spec; | 68 local_info_.interface_provider_specs, &target_spec); |
| 69 if (target_it != local_info_.interface_provider_specs.end()) | 69 GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, |
| 70 target_spec = target_it->second; | 70 source_info.interface_provider_specs, &source_spec); |
| 71 auto source_it = source_info.interface_provider_specs.find( | 71 auto registry = base::MakeUnique<InterfaceRegistry>(); |
| 72 mojom::kServiceManager_ConnectorSpec); | 72 registry->Bind(std::move(interfaces), local_info_.identity, target_spec, |
| 73 InterfaceProviderSpec source_spec; | 73 source_info.identity, 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); | |
| 80 | 74 |
| 81 if (!service_->OnConnect(source_info, registry.get())) | 75 if (!service_->OnConnect(source_info, registry.get())) |
| 82 return; | 76 return; |
| 83 | 77 |
| 84 // TODO(beng): it appears we never prune this list. We should, when the | 78 // TODO(beng): it appears we never prune this list. We should, when the |
| 85 // registry's remote interface provider pipe breaks. | 79 // registry's remote interface provider pipe breaks. |
| 86 incoming_connections_.push_back(std::move(registry)); | 80 incoming_connections_.push_back(std::move(registry)); |
| 87 } | 81 } |
| 88 | 82 |
| 89 //////////////////////////////////////////////////////////////////////////////// | 83 //////////////////////////////////////////////////////////////////////////////// |
| 90 // ServiceContext, private: | 84 // ServiceContext, private: |
| 91 | 85 |
| 92 void ServiceContext::OnConnectionError() { | 86 void ServiceContext::OnConnectionError() { |
| 93 // Note that the Service doesn't technically have to quit now, it may live | 87 // Note that the Service doesn't technically have to quit now, it may live |
| 94 // on to service existing connections. All existing Connectors however are | 88 // on to service existing connections. All existing Connectors however are |
| 95 // invalid. | 89 // invalid. |
| 96 should_run_connection_lost_closure_ = service_->OnStop(); | 90 should_run_connection_lost_closure_ = service_->OnStop(); |
| 97 if (should_run_connection_lost_closure_ && | 91 if (should_run_connection_lost_closure_ && |
| 98 !connection_lost_closure_.is_null()) | 92 !connection_lost_closure_.is_null()) |
| 99 connection_lost_closure_.Run(); | 93 connection_lost_closure_.Run(); |
| 100 // We don't reset the connector as clients may have taken a raw pointer to it. | 94 // We don't reset the connector as clients may have taken a raw pointer to it. |
| 101 // Connect() will return nullptr if they try to connect to anything. | 95 // Connect() will return nullptr if they try to connect to anything. |
| 102 } | 96 } |
| 103 | 97 |
| 104 } // namespace service_manager | 98 } // namespace service_manager |
| OLD | NEW |