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/lib/connection_impl.h" | 7 #include "mojo/shell/public/cpp/lib/connection_impl.h" |
8 | 8 |
9 namespace mojo { | 9 namespace mojo { |
10 | 10 |
11 Connector::ConnectParams::ConnectParams(const std::string& url) | 11 Connector::ConnectParams::ConnectParams(const std::string& name) |
12 : url_(url), | 12 : name_(name), |
13 user_id_(shell::mojom::Connector::kUserInherit) { | 13 user_id_(shell::mojom::Connector::kUserInherit) { |
14 } | 14 } |
15 Connector::ConnectParams::~ConnectParams() {} | 15 Connector::ConnectParams::~ConnectParams() {} |
16 | 16 |
17 ConnectorImpl::ConnectorImpl(shell::mojom::ConnectorPtrInfo unbound_state) | 17 ConnectorImpl::ConnectorImpl(shell::mojom::ConnectorPtrInfo unbound_state) |
18 : unbound_state_(std::move(unbound_state)) {} | 18 : unbound_state_(std::move(unbound_state)) {} |
19 ConnectorImpl::ConnectorImpl(shell::mojom::ConnectorPtr connector, | 19 ConnectorImpl::ConnectorImpl(shell::mojom::ConnectorPtr connector, |
20 const base::Closure& connection_error_closure) | 20 const base::Closure& connection_error_closure) |
21 : connector_(std::move(connector)) { | 21 : connector_(std::move(connector)) { |
22 connector_.set_connection_error_handler(connection_error_closure); | 22 connector_.set_connection_error_handler(connection_error_closure); |
23 thread_checker_.reset(new base::ThreadChecker); | 23 thread_checker_.reset(new base::ThreadChecker); |
24 } | 24 } |
25 ConnectorImpl::~ConnectorImpl() {} | 25 ConnectorImpl::~ConnectorImpl() {} |
26 | 26 |
27 scoped_ptr<Connection> ConnectorImpl::Connect(const std::string& url) { | 27 scoped_ptr<Connection> ConnectorImpl::Connect(const std::string& name) { |
28 ConnectParams params(url); | 28 ConnectParams params(name); |
29 return Connect(¶ms); | 29 return Connect(¶ms); |
30 } | 30 } |
31 | 31 |
32 scoped_ptr<Connection> ConnectorImpl::Connect(ConnectParams* params) { | 32 scoped_ptr<Connection> ConnectorImpl::Connect(ConnectParams* params) { |
33 // Bind this object to the current thread the first time it is used to | 33 // Bind this object to the current thread the first time it is used to |
34 // connect. | 34 // connect. |
35 if (!connector_.is_bound()) { | 35 if (!connector_.is_bound()) { |
36 if (!unbound_state_.is_valid()) | 36 if (!unbound_state_.is_valid()) |
37 return nullptr; | 37 return nullptr; |
38 connector_.Bind(std::move(unbound_state_)); | 38 connector_.Bind(std::move(unbound_state_)); |
39 thread_checker_.reset(new base::ThreadChecker); | 39 thread_checker_.reset(new base::ThreadChecker); |
40 } | 40 } |
41 DCHECK(thread_checker_->CalledOnValidThread()); | 41 DCHECK(thread_checker_->CalledOnValidThread()); |
42 | 42 |
43 DCHECK(params); | 43 DCHECK(params); |
44 std::string application_url = params->url().spec(); | 44 std::string application_name = params->name(); |
45 // We allow all interfaces on outgoing connections since we are presumably in | 45 // We allow all interfaces on outgoing connections since we are presumably in |
46 // a position to know who we're talking to. | 46 // a position to know who we're talking to. |
47 // TODO(beng): is this a valid assumption or do we need to figure some way to | 47 // TODO(beng): is this a valid assumption or do we need to figure some way to |
48 // filter here too? | 48 // filter here too? |
49 std::set<std::string> allowed; | 49 std::set<std::string> allowed; |
50 allowed.insert("*"); | 50 allowed.insert("*"); |
51 shell::mojom::InterfaceProviderPtr local_interfaces; | 51 shell::mojom::InterfaceProviderPtr local_interfaces; |
52 shell::mojom::InterfaceProviderRequest local_request = | 52 shell::mojom::InterfaceProviderRequest local_request = |
53 GetProxy(&local_interfaces); | 53 GetProxy(&local_interfaces); |
54 shell::mojom::InterfaceProviderPtr remote_interfaces; | 54 shell::mojom::InterfaceProviderPtr remote_interfaces; |
55 shell::mojom::InterfaceProviderRequest remote_request = | 55 shell::mojom::InterfaceProviderRequest remote_request = |
56 GetProxy(&remote_interfaces); | 56 GetProxy(&remote_interfaces); |
57 scoped_ptr<internal::ConnectionImpl> registry(new internal::ConnectionImpl( | 57 scoped_ptr<internal::ConnectionImpl> registry(new internal::ConnectionImpl( |
58 application_url, application_url, | 58 application_name, application_name, |
59 shell::mojom::Connector::kInvalidApplicationID, params->user_id(), | 59 shell::mojom::Connector::kInvalidApplicationID, params->user_id(), |
60 std::move(remote_interfaces), std::move(local_request), allowed)); | 60 std::move(remote_interfaces), std::move(local_request), allowed)); |
61 connector_->Connect(application_url, | 61 connector_->Connect(application_name, |
62 params->user_id(), | 62 params->user_id(), |
63 std::move(remote_request), | 63 std::move(remote_request), |
64 std::move(local_interfaces), | 64 std::move(local_interfaces), |
65 registry->GetConnectCallback()); | 65 registry->GetConnectCallback()); |
66 return std::move(registry); | 66 return std::move(registry); |
67 } | 67 } |
68 | 68 |
69 scoped_ptr<Connector> ConnectorImpl::Clone() { | 69 scoped_ptr<Connector> ConnectorImpl::Clone() { |
70 shell::mojom::ConnectorPtr connector; | 70 shell::mojom::ConnectorPtr connector; |
71 connector_->Clone(GetProxy(&connector)); | 71 connector_->Clone(GetProxy(&connector)); |
72 return make_scoped_ptr( | 72 return make_scoped_ptr( |
73 new ConnectorImpl(connector.PassInterface())); | 73 new ConnectorImpl(connector.PassInterface())); |
74 } | 74 } |
75 | 75 |
76 } // namespace mojo | 76 } // namespace mojo |
OLD | NEW |