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

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

Issue 1761113002: Monitor the ShellClient binding for pipe closure as a signal to shut down the ShellConnection, rath… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@28lifecycle2
Patch Set: Created 4 years, 9 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/shell_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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& name) 11 Connector::ConnectParams::ConnectParams(const std::string& name)
12 : name_(name), 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)
21 : connector_(std::move(connector)) { 20 : connector_(std::move(connector)) {
22 connector_.set_connection_error_handler(connection_error_closure);
23 thread_checker_.reset(new base::ThreadChecker); 21 thread_checker_.reset(new base::ThreadChecker);
24 } 22 }
25 ConnectorImpl::~ConnectorImpl() {} 23 ConnectorImpl::~ConnectorImpl() {}
26 24
27 scoped_ptr<Connection> ConnectorImpl::Connect(const std::string& name) { 25 scoped_ptr<Connection> ConnectorImpl::Connect(const std::string& name) {
28 ConnectParams params(name); 26 ConnectParams params(name);
29 return Connect(&params); 27 return Connect(&params);
30 } 28 }
31 29
32 scoped_ptr<Connection> ConnectorImpl::Connect(ConnectParams* params) { 30 scoped_ptr<Connection> ConnectorImpl::Connect(ConnectParams* params) {
33 // Bind this object to the current thread the first time it is used to 31 // Bind this object to the current thread the first time it is used to
34 // connect. 32 // connect.
35 if (!connector_.is_bound()) { 33 if (!connector_.is_bound()) {
36 if (!unbound_state_.is_valid()) 34 if (!unbound_state_.is_valid()) {
35 // It's possible to get here when the link to the shell has been severed
36 // (and so the connector pipe has been closed) but the app has chosen not
37 // to quit.
37 return nullptr; 38 return nullptr;
39 }
38 connector_.Bind(std::move(unbound_state_)); 40 connector_.Bind(std::move(unbound_state_));
39 thread_checker_.reset(new base::ThreadChecker); 41 thread_checker_.reset(new base::ThreadChecker);
40 } 42 }
41 DCHECK(thread_checker_->CalledOnValidThread()); 43 DCHECK(thread_checker_->CalledOnValidThread());
42 44
43 DCHECK(params); 45 DCHECK(params);
44 std::string application_name = params->name(); 46 std::string application_name = params->name();
45 // 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
46 // a position to know who we're talking to. 48 // a position to know who we're talking to.
47 // 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
(...skipping 20 matching lines...) Expand all
68 } 70 }
69 71
70 scoped_ptr<Connector> ConnectorImpl::Clone() { 72 scoped_ptr<Connector> ConnectorImpl::Clone() {
71 shell::mojom::ConnectorPtr connector; 73 shell::mojom::ConnectorPtr connector;
72 connector_->Clone(GetProxy(&connector)); 74 connector_->Clone(GetProxy(&connector));
73 return make_scoped_ptr( 75 return make_scoped_ptr(
74 new ConnectorImpl(connector.PassInterface())); 76 new ConnectorImpl(connector.PassInterface()));
75 } 77 }
76 78
77 } // namespace mojo 79 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/public/cpp/lib/connector_impl.h ('k') | mojo/shell/public/cpp/lib/shell_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698