| 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/shell/public/cpp/shell_connection.h" | 5 #include "services/shell/public/cpp/shell_connection.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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 client_->Initialize(connector_.get(), identity_, id); | 69 client_->Initialize(connector_.get(), identity_, id); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void ShellConnection::AcceptConnection( | 72 void ShellConnection::AcceptConnection( |
| 73 mojom::IdentityPtr source, | 73 mojom::IdentityPtr source, |
| 74 uint32_t source_id, | 74 uint32_t source_id, |
| 75 mojom::InterfaceProviderRequest local_interfaces, | 75 mojom::InterfaceProviderRequest local_interfaces, |
| 76 mojom::InterfaceProviderPtr remote_interfaces, | 76 mojom::InterfaceProviderPtr remote_interfaces, |
| 77 mojom::CapabilityRequestPtr allowed_capabilities, | 77 mojom::CapabilityRequestPtr allowed_capabilities, |
| 78 const mojo::String& name) { | 78 const mojo::String& name) { |
| 79 std::unique_ptr<Connection> registry(new internal::ConnectionImpl( | 79 std::unique_ptr<internal::ConnectionImpl> registry( |
| 80 name, source.To<Identity>(), source_id, std::move(remote_interfaces), | 80 new internal::ConnectionImpl(name, source.To<Identity>(), source_id, |
| 81 std::move(local_interfaces), allowed_capabilities.To<CapabilityRequest>(), | 81 allowed_capabilities.To<CapabilityRequest>(), |
| 82 Connection::State::CONNECTED)); | 82 Connection::State::CONNECTED)); |
| 83 |
| 84 InterfaceRegistry* exposed_interfaces = |
| 85 client_->GetInterfaceRegistryForConnection(); |
| 86 if (exposed_interfaces) { |
| 87 exposed_interfaces->Bind(std::move(local_interfaces)); |
| 88 registry->set_exposed_interfaces(exposed_interfaces); |
| 89 } else { |
| 90 std::unique_ptr<InterfaceRegistry> interfaces( |
| 91 new InterfaceRegistry(registry.get())); |
| 92 interfaces->Bind(std::move(local_interfaces)); |
| 93 registry->SetExposedInterfaces(std::move(interfaces)); |
| 94 } |
| 95 shell::InterfaceProvider* remote_interface_provider = |
| 96 client_->GetInterfaceProviderForConnection(); |
| 97 if (remote_interface_provider) { |
| 98 remote_interface_provider->Bind(std::move(remote_interfaces)); |
| 99 registry->set_remote_interfaces(remote_interface_provider); |
| 100 } else { |
| 101 std::unique_ptr<InterfaceProvider> interfaces(new InterfaceProvider); |
| 102 interfaces->Bind(std::move(remote_interfaces)); |
| 103 registry->SetRemoteInterfaces(std::move(interfaces)); |
| 104 } |
| 105 |
| 83 if (!client_->AcceptConnection(registry.get())) | 106 if (!client_->AcceptConnection(registry.get())) |
| 84 return; | 107 return; |
| 85 | 108 |
| 86 // TODO(beng): it appears we never prune this list. We should, when the | 109 // TODO(beng): it appears we never prune this list. We should, when the |
| 87 // connection's remote service provider pipe breaks. | 110 // connection's remote service provider pipe breaks. |
| 88 incoming_connections_.push_back(std::move(registry)); | 111 incoming_connections_.push_back(std::move(registry)); |
| 89 } | 112 } |
| 90 | 113 |
| 91 //////////////////////////////////////////////////////////////////////////////// | 114 //////////////////////////////////////////////////////////////////////////////// |
| 92 // ShellConnection, private: | 115 // ShellConnection, private: |
| 93 | 116 |
| 94 void ShellConnection::OnConnectionError() { | 117 void ShellConnection::OnConnectionError() { |
| 95 // Note that the ShellClient doesn't technically have to quit now, it may live | 118 // Note that the ShellClient doesn't technically have to quit now, it may live |
| 96 // on to service existing connections. All existing Connectors however are | 119 // on to service existing connections. All existing Connectors however are |
| 97 // invalid. | 120 // invalid. |
| 98 should_run_connection_lost_closure_ = client_->ShellConnectionLost(); | 121 should_run_connection_lost_closure_ = client_->ShellConnectionLost(); |
| 99 if (should_run_connection_lost_closure_ && | 122 if (should_run_connection_lost_closure_ && |
| 100 !connection_lost_closure_.is_null()) | 123 !connection_lost_closure_.is_null()) |
| 101 connection_lost_closure_.Run(); | 124 connection_lost_closure_.Run(); |
| 102 // We don't reset the connector as clients may have taken a raw pointer to it. | 125 // We don't reset the connector as clients may have taken a raw pointer to it. |
| 103 // Connect() will return nullptr if they try to connect to anything. | 126 // Connect() will return nullptr if they try to connect to anything. |
| 104 } | 127 } |
| 105 | 128 |
| 106 } // namespace shell | 129 } // namespace shell |
| OLD | NEW |