| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "mojo/shell/public/cpp/lib/connector_impl.h" | 5 #include "mojo/shell/public/cpp/lib/connector_impl.h" |
| 6 | 6 |
| 7 #include "mojo/shell/public/cpp/identity.h" |
| 7 #include "mojo/shell/public/cpp/lib/connection_impl.h" | 8 #include "mojo/shell/public/cpp/lib/connection_impl.h" |
| 8 | 9 |
| 9 namespace mojo { | 10 namespace mojo { |
| 10 | 11 |
| 12 Connector::ConnectParams::ConnectParams(const Identity& target) |
| 13 : target_(target) {} |
| 11 Connector::ConnectParams::ConnectParams(const std::string& name) | 14 Connector::ConnectParams::ConnectParams(const std::string& name) |
| 12 : name_(name), | 15 : target_(name, shell::mojom::kInheritUserID) {} |
| 13 user_id_(shell::mojom::kInheritUserID) { | |
| 14 } | |
| 15 Connector::ConnectParams::~ConnectParams() {} | 16 Connector::ConnectParams::~ConnectParams() {} |
| 16 | 17 |
| 17 ConnectorImpl::ConnectorImpl(shell::mojom::ConnectorPtrInfo unbound_state) | 18 ConnectorImpl::ConnectorImpl(shell::mojom::ConnectorPtrInfo unbound_state) |
| 18 : unbound_state_(std::move(unbound_state)) {} | 19 : unbound_state_(std::move(unbound_state)) {} |
| 19 ConnectorImpl::ConnectorImpl(shell::mojom::ConnectorPtr connector) | 20 ConnectorImpl::ConnectorImpl(shell::mojom::ConnectorPtr connector) |
| 20 : connector_(std::move(connector)) { | 21 : connector_(std::move(connector)) { |
| 21 thread_checker_.reset(new base::ThreadChecker); | 22 thread_checker_.reset(new base::ThreadChecker); |
| 22 } | 23 } |
| 23 ConnectorImpl::~ConnectorImpl() {} | 24 ConnectorImpl::~ConnectorImpl() {} |
| 24 | 25 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 36 // (and so the connector pipe has been closed) but the app has chosen not | 37 // (and so the connector pipe has been closed) but the app has chosen not |
| 37 // to quit. | 38 // to quit. |
| 38 return nullptr; | 39 return nullptr; |
| 39 } | 40 } |
| 40 connector_.Bind(std::move(unbound_state_)); | 41 connector_.Bind(std::move(unbound_state_)); |
| 41 thread_checker_.reset(new base::ThreadChecker); | 42 thread_checker_.reset(new base::ThreadChecker); |
| 42 } | 43 } |
| 43 DCHECK(thread_checker_->CalledOnValidThread()); | 44 DCHECK(thread_checker_->CalledOnValidThread()); |
| 44 | 45 |
| 45 DCHECK(params); | 46 DCHECK(params); |
| 46 std::string application_name = params->name(); | |
| 47 // We allow all interfaces on outgoing connections since we are presumably in | 47 // We allow all interfaces on outgoing connections since we are presumably in |
| 48 // a position to know who we're talking to. | 48 // a position to know who we're talking to. |
| 49 // TODO(beng): We should filter outgoing interfaces also. The shell must pass | 49 // TODO(beng): We should filter outgoing interfaces also. The shell must pass |
| 50 // the manifest CapabilityFilter to the ShellConnection via | 50 // the manifest CapabilityFilter to the ShellConnection via |
| 51 // Initialize(), it can be used here. | 51 // Initialize(), it can be used here. |
| 52 std::set<std::string> allowed; | 52 std::set<std::string> allowed; |
| 53 allowed.insert("*"); | 53 allowed.insert("*"); |
| 54 shell::mojom::InterfaceProviderPtr local_interfaces; | 54 shell::mojom::InterfaceProviderPtr local_interfaces; |
| 55 shell::mojom::InterfaceProviderRequest local_request = | 55 shell::mojom::InterfaceProviderRequest local_request = |
| 56 GetProxy(&local_interfaces); | 56 GetProxy(&local_interfaces); |
| 57 shell::mojom::InterfaceProviderPtr remote_interfaces; | 57 shell::mojom::InterfaceProviderPtr remote_interfaces; |
| 58 shell::mojom::InterfaceProviderRequest remote_request = | 58 shell::mojom::InterfaceProviderRequest remote_request = |
| 59 GetProxy(&remote_interfaces); | 59 GetProxy(&remote_interfaces); |
| 60 scoped_ptr<internal::ConnectionImpl> registry(new internal::ConnectionImpl( | 60 scoped_ptr<internal::ConnectionImpl> registry(new internal::ConnectionImpl( |
| 61 application_name, application_name, shell::mojom::kInvalidInstanceID, | 61 params->target().name(), params->target(), |
| 62 params->user_id(), std::move(remote_interfaces), std::move(local_request), | 62 shell::mojom::kInvalidInstanceID, std::move(remote_interfaces), |
| 63 allowed, Connection::State::PENDING)); | 63 std::move(local_request), allowed, Connection::State::PENDING)); |
| 64 connector_->Connect(application_name, | 64 connector_->Connect( |
| 65 params->user_id(), | 65 shell::mojom::Identity::From(params->target()), |
| 66 std::move(remote_request), | 66 std::move(remote_request), std::move(local_interfaces), |
| 67 std::move(local_interfaces), | 67 registry->GetConnectCallback()); |
| 68 registry->GetConnectCallback()); | |
| 69 return std::move(registry); | 68 return std::move(registry); |
| 70 } | 69 } |
| 71 | 70 |
| 72 scoped_ptr<Connector> ConnectorImpl::Clone() { | 71 scoped_ptr<Connector> ConnectorImpl::Clone() { |
| 73 shell::mojom::ConnectorPtr connector; | 72 shell::mojom::ConnectorPtr connector; |
| 74 connector_->Clone(GetProxy(&connector)); | 73 connector_->Clone(GetProxy(&connector)); |
| 75 return make_scoped_ptr( | 74 return make_scoped_ptr( |
| 76 new ConnectorImpl(connector.PassInterface())); | 75 new ConnectorImpl(connector.PassInterface())); |
| 77 } | 76 } |
| 78 | 77 |
| 79 } // namespace mojo | 78 } // namespace mojo |
| OLD | NEW |