Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: mojo/shell/public/cpp/lib/connector_impl.cc

Issue 1728083002: Extract a Connector interface from Shell that can be cloned & passed to other threads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@12uid
Patch Set: . Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mojo/shell/public/cpp/lib/connector_impl.h"
6
7 #include "mojo/shell/public/cpp/lib/connection_impl.h"
8
9 namespace mojo {
10
11 Connector::ConnectParams::ConnectParams(const std::string& url)
12 : url_(url),
13 filter_(shell::mojom::CapabilityFilter::New()),
14 user_id_(shell::mojom::Connector::kUserInherit) {
15 filter_->filter.SetToEmpty();
16 }
17 Connector::ConnectParams::~ConnectParams() {}
18
19 ConnectorImpl::ConnectorImpl(shell::mojom::ConnectorPtrInfo unbound_state)
20 : unbound_state_(std::move(unbound_state)) {}
21 ConnectorImpl::~ConnectorImpl() {}
22
23 scoped_ptr<Connection> ConnectorImpl::Connect(const std::string& url) {
24 ConnectParams params(url);
25 params.set_filter(CreatePermissiveCapabilityFilter());
26 return Connect(&params);
27 }
28
29 scoped_ptr<Connection> ConnectorImpl::Connect(ConnectParams* params) {
30 // Bind this object to the current thread the first time it is used to
31 // connect.
32 if (!connector_.is_bound()) {
33 if (!unbound_state_.is_valid())
34 return nullptr;
35 connector_.Bind(std::move(unbound_state_));
sky 2016/02/24 17:08:07 It would be good if you add threadchecker to asser
36 }
37
38 DCHECK(params);
39 std::string application_url = params->url().spec();
40 // We allow all interfaces on outgoing connections since we are presumably in
41 // a position to know who we're talking to.
42 // TODO(beng): is this a valid assumption or do we need to figure some way to
43 // filter here too?
44 std::set<std::string> allowed;
45 allowed.insert("*");
46 shell::mojom::InterfaceProviderPtr local_interfaces;
47 shell::mojom::InterfaceProviderRequest local_request =
48 GetProxy(&local_interfaces);
49 shell::mojom::InterfaceProviderPtr remote_interfaces;
50 shell::mojom::InterfaceProviderRequest remote_request =
51 GetProxy(&remote_interfaces);
52 scoped_ptr<internal::ConnectionImpl> registry(new internal::ConnectionImpl(
53 application_url, application_url,
54 shell::mojom::Connector::kInvalidApplicationID, params->user_id(),
55 std::move(remote_interfaces), std::move(local_request), allowed));
56 connector_->Connect(application_url,
57 params->user_id(),
58 std::move(remote_request),
59 std::move(local_interfaces),
60 params->TakeFilter(),
61 registry->GetConnectCallback());
62 return std::move(registry);
63 }
64
65 scoped_ptr<Connector> ConnectorImpl::Clone() {
66 shell::mojom::ConnectorPtr connector;
67 connector_->Clone(GetProxy(&connector));
68 return make_scoped_ptr(
69 new ConnectorImpl(connector.PassInterface()));
70 }
71
72 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698