| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "mojo/public/cpp/bindings/interface_ptr.h" | 8 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 9 #include "mojo/shell/public/cpp/capabilities.h" |
| 9 #include "mojo/shell/public/cpp/connector.h" | 10 #include "mojo/shell/public/cpp/connector.h" |
| 10 #include "mojo/shell/public/cpp/lib/connection_impl.h" | 11 #include "mojo/shell/public/cpp/lib/connection_impl.h" |
| 11 #include "mojo/shell/public/cpp/lib/connector_impl.h" | 12 #include "mojo/shell/public/cpp/lib/connector_impl.h" |
| 12 #include "mojo/shell/public/cpp/shell_client.h" | 13 #include "mojo/shell/public/cpp/shell_client.h" |
| 13 #include "mojo/shell/public/cpp/shell_connection.h" | 14 #include "mojo/shell/public/cpp/shell_connection.h" |
| 14 | 15 |
| 15 namespace mojo { | 16 namespace mojo { |
| 16 | 17 |
| 17 //////////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////////// |
| 18 // ShellConnection, public: | 19 // ShellConnection, public: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 42 base::Bind(&ShellConnection::OnConnectionError, | 43 base::Bind(&ShellConnection::OnConnectionError, |
| 43 weak_factory_.GetWeakPtr())); | 44 weak_factory_.GetWeakPtr())); |
| 44 client_->Initialize(connector_.get(), identity.To<Identity>(), id); | 45 client_->Initialize(connector_.get(), identity.To<Identity>(), id); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void ShellConnection::AcceptConnection( | 48 void ShellConnection::AcceptConnection( |
| 48 shell::mojom::IdentityPtr source, | 49 shell::mojom::IdentityPtr source, |
| 49 uint32_t source_id, | 50 uint32_t source_id, |
| 50 shell::mojom::InterfaceProviderRequest local_interfaces, | 51 shell::mojom::InterfaceProviderRequest local_interfaces, |
| 51 shell::mojom::InterfaceProviderPtr remote_interfaces, | 52 shell::mojom::InterfaceProviderPtr remote_interfaces, |
| 52 Array<String> allowed_interfaces, | 53 shell::mojom::CapabilityRequestPtr allowed_capabilities, |
| 53 const String& name) { | 54 const String& name) { |
| 54 scoped_ptr<Connection> registry(new internal::ConnectionImpl( | 55 scoped_ptr<Connection> registry(new internal::ConnectionImpl( |
| 55 name, source.To<Identity>(), source_id, std::move(remote_interfaces), | 56 name, source.To<Identity>(), source_id, std::move(remote_interfaces), |
| 56 std::move(local_interfaces), | 57 std::move(local_interfaces), |
| 57 allowed_interfaces.To<std::set<std::string>>(), | 58 allowed_capabilities->interfaces.To<std::set<std::string>>(), |
| 58 Connection::State::CONNECTED)); | 59 Connection::State::CONNECTED)); |
| 59 if (!client_->AcceptConnection(registry.get())) | 60 if (!client_->AcceptConnection(registry.get())) |
| 60 return; | 61 return; |
| 61 | 62 |
| 62 // TODO(beng): it appears we never prune this list. We should, when the | 63 // TODO(beng): it appears we never prune this list. We should, when the |
| 63 // connection's remote service provider pipe breaks. | 64 // connection's remote service provider pipe breaks. |
| 64 incoming_connections_.push_back(std::move(registry)); | 65 incoming_connections_.push_back(std::move(registry)); |
| 65 } | 66 } |
| 66 | 67 |
| 67 //////////////////////////////////////////////////////////////////////////////// | 68 //////////////////////////////////////////////////////////////////////////////// |
| 68 // ShellConnection, private: | 69 // ShellConnection, private: |
| 69 | 70 |
| 70 void ShellConnection::OnConnectionError() { | 71 void ShellConnection::OnConnectionError() { |
| 71 // Note that the ShellClient doesn't technically have to quit now, it may live | 72 // Note that the ShellClient doesn't technically have to quit now, it may live |
| 72 // on to service existing connections. All existing Connectors however are | 73 // on to service existing connections. All existing Connectors however are |
| 73 // invalid. | 74 // invalid. |
| 74 client_->ShellConnectionLost(); | 75 client_->ShellConnectionLost(); |
| 75 // We don't reset the connector as clients may have taken a raw pointer to it. | 76 // We don't reset the connector as clients may have taken a raw pointer to it. |
| 76 // Connect() will return nullptr if they try to connect to anything. | 77 // Connect() will return nullptr if they try to connect to anything. |
| 77 } | 78 } |
| 78 | 79 |
| 79 } // namespace mojo | 80 } // namespace mojo |
| OLD | NEW |