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

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

Issue 1877753003: Move mojo\shell to services\shell (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@62scan
Patch Set: . Created 4 years, 8 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
« no previous file with comments | « mojo/shell/public/cpp/lib/connector_impl.h ('k') | mojo/shell/public/cpp/lib/identity.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/identity.h"
8 #include "mojo/shell/public/cpp/lib/connection_impl.h"
9
10 namespace mojo {
11
12 Connector::ConnectParams::ConnectParams(const Identity& target)
13 : target_(target) {}
14 Connector::ConnectParams::ConnectParams(const std::string& name)
15 : target_(name, shell::mojom::kInheritUserID) {}
16 Connector::ConnectParams::~ConnectParams() {}
17
18 ConnectorImpl::ConnectorImpl(shell::mojom::ConnectorPtrInfo unbound_state)
19 : unbound_state_(std::move(unbound_state)) {}
20 ConnectorImpl::ConnectorImpl(shell::mojom::ConnectorPtr connector)
21 : connector_(std::move(connector)) {
22 thread_checker_.reset(new base::ThreadChecker);
23 }
24 ConnectorImpl::~ConnectorImpl() {}
25
26 scoped_ptr<Connection> ConnectorImpl::Connect(const std::string& name) {
27 ConnectParams params(name);
28 return Connect(&params);
29 }
30
31 scoped_ptr<Connection> ConnectorImpl::Connect(ConnectParams* params) {
32 // Bind this object to the current thread the first time it is used to
33 // connect.
34 if (!connector_.is_bound()) {
35 if (!unbound_state_.is_valid()) {
36 // It's possible to get here when the link to the shell has been severed
37 // (and so the connector pipe has been closed) but the app has chosen not
38 // to quit.
39 return nullptr;
40 }
41 connector_.Bind(std::move(unbound_state_));
42 thread_checker_.reset(new base::ThreadChecker);
43 }
44 DCHECK(thread_checker_->CalledOnValidThread());
45
46 DCHECK(params);
47 // We allow all interfaces on outgoing connections since we are presumably in
48 // a position to know who we're talking to.
49 CapabilityRequest request;
50 request.interfaces.insert("*");
51 shell::mojom::InterfaceProviderPtr local_interfaces;
52 shell::mojom::InterfaceProviderRequest local_request =
53 GetProxy(&local_interfaces);
54 shell::mojom::InterfaceProviderPtr remote_interfaces;
55 shell::mojom::InterfaceProviderRequest remote_request =
56 GetProxy(&remote_interfaces);
57 scoped_ptr<internal::ConnectionImpl> registry(new internal::ConnectionImpl(
58 params->target().name(), params->target(),
59 shell::mojom::kInvalidInstanceID, std::move(remote_interfaces),
60 std::move(local_request), request, Connection::State::PENDING));
61
62 shell::mojom::ShellClientPtr shell_client;
63 shell::mojom::PIDReceiverRequest pid_receiver_request;
64 params->TakeClientProcessConnection(&shell_client, &pid_receiver_request);
65 shell::mojom::ClientProcessConnectionPtr client_process_connection;
66 if (shell_client.is_bound() && pid_receiver_request.is_pending()) {
67 client_process_connection = shell::mojom::ClientProcessConnection::New();
68 client_process_connection->shell_client =
69 shell_client.PassInterface().PassHandle();
70 client_process_connection->pid_receiver_request =
71 pid_receiver_request.PassMessagePipe();
72 } else if (shell_client.is_bound() || pid_receiver_request.is_pending()) {
73 NOTREACHED() << "If one of shell_client or pid_receiver_request is valid, "
74 << "both must be valid.";
75 return std::move(registry);
76 }
77 connector_->Connect(
78 shell::mojom::Identity::From(params->target()),
79 std::move(remote_request), std::move(local_interfaces),
80 std::move(client_process_connection), registry->GetConnectCallback());
81 return std::move(registry);
82 }
83
84 scoped_ptr<Connector> ConnectorImpl::Clone() {
85 shell::mojom::ConnectorPtr connector;
86 connector_->Clone(GetProxy(&connector));
87 return make_scoped_ptr(
88 new ConnectorImpl(connector.PassInterface()));
89 }
90
91 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/public/cpp/lib/connector_impl.h ('k') | mojo/shell/public/cpp/lib/identity.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698