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

Side by Side Diff: mojo/shell/shell.cc

Issue 1793793002: Remove ShellConnection::WaitForInitialize (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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/runner/child/test_native_main.cc ('k') | mojo/shell/tests/shell/shell_unittest.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/shell.h" 5 #include "mojo/shell/shell.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 capability_spec_(capability_spec), 110 capability_spec_(capability_spec),
111 allow_any_application_(capability_spec.required.count("*") == 1), 111 allow_any_application_(capability_spec.required.count("*") == 1),
112 shell_client_(std::move(shell_client)), 112 shell_client_(std::move(shell_client)),
113 pid_receiver_binding_(this), 113 pid_receiver_binding_(this),
114 weak_factory_(this) { 114 weak_factory_(this) {
115 if (identity_.name() == kShellName || 115 if (identity_.name() == kShellName ||
116 shell_->GetLoaderForName(identity_.name())) { 116 shell_->GetLoaderForName(identity_.name())) {
117 pid_ = base::Process::Current().Pid(); 117 pid_ = base::Process::Current().Pid();
118 } 118 }
119 DCHECK_NE(mojom::kInvalidInstanceID, id_); 119 DCHECK_NE(mojom::kInvalidInstanceID, id_);
120
121 shell_client_.set_connection_error_handler(
122 base::Bind(&Instance::OnShellClientLost, base::Unretained(this)));
120 } 123 }
121 124
122 ~Instance() override {} 125 ~Instance() override {}
123 126
127 void OnShellClientLost() {
128 shell_client_.reset();
129 OnConnectionLost();
130 }
131
132 void OnConnectionLost() {
133 // Any time a Connector is lost or we lose the ShellClient connection, it
134 // may have been the last pipe using this Instance. If so, clean up.
135 if (connectors_.empty() && !shell_client_) {
136 // Deletes |this|.
137 shell_->OnInstanceError(this);
138 }
139 }
140
141 void OnInitializeResponse(mojom::ConnectorRequest connector_request) {
142 if (connector_request.is_pending()) {
143 connectors_.AddBinding(this, std::move(connector_request));
144 connectors_.set_connection_error_handler(
145 base::Bind(&Instance::OnConnectionLost, base::Unretained(this)));
146 }
147 }
148
124 void InitializeClient() { 149 void InitializeClient() {
125 shell_client_->Initialize(connectors_.CreateInterfacePtrAndBind(this), 150 shell_client_->Initialize(mojom::Identity::From(identity_), id_,
126 mojom::Identity::From(identity_), id_); 151 base::Bind(&Instance::OnInitializeResponse,
127 connectors_.set_connection_error_handler( 152 base::Unretained(this)));
128 base::Bind(&mojo::shell::Shell::OnInstanceError,
129 base::Unretained(shell_), base::Unretained(this)));
130 } 153 }
131 154
132 void ConnectToClient(scoped_ptr<ConnectParams> params) { 155 void ConnectToClient(scoped_ptr<ConnectParams> params) {
133 params->connect_callback().Run(mojom::ConnectResult::SUCCEEDED, 156 params->connect_callback().Run(mojom::ConnectResult::SUCCEEDED,
134 identity_.user_id(), id_); 157 identity_.user_id(), id_);
135 uint32_t source_id = mojom::kInvalidInstanceID; 158 uint32_t source_id = mojom::kInvalidInstanceID;
136 CapabilityRequest spec; 159 CapabilityRequest spec;
137 spec.interfaces.insert("*"); 160 spec.interfaces.insert("*");
138 Instance* source = shell_->GetExistingInstance(params->source()); 161 Instance* source = shell_->GetExistingInstance(params->source());
139 if (source) { 162 if (source) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 233
211 scoped_ptr<ConnectParams> params(new ConnectParams); 234 scoped_ptr<ConnectParams> params(new ConnectParams);
212 params->set_source(identity_); 235 params->set_source(identity_);
213 params->set_target(target); 236 params->set_target(target);
214 params->set_remote_interfaces(std::move(remote_interfaces)); 237 params->set_remote_interfaces(std::move(remote_interfaces));
215 params->set_local_interfaces(std::move(local_interfaces)); 238 params->set_local_interfaces(std::move(local_interfaces));
216 params->set_client_process_connection(std::move(client_process_connection)); 239 params->set_client_process_connection(std::move(client_process_connection));
217 params->set_connect_callback(callback); 240 params->set_connect_callback(callback);
218 shell_->Connect(std::move(params)); 241 shell_->Connect(std::move(params));
219 } 242 }
243
220 void Clone(mojom::ConnectorRequest request) override { 244 void Clone(mojom::ConnectorRequest request) override {
221 connectors_.AddBinding(this, std::move(request)); 245 connectors_.AddBinding(this, std::move(request));
222 } 246 }
223 247
224 // mojom::PIDReceiver: 248 // mojom::PIDReceiver:
225 void SetPID(uint32_t pid) override { 249 void SetPID(uint32_t pid) override {
226 PIDAvailable(pid); 250 PIDAvailable(pid);
227 } 251 }
228 252
229 // InterfaceFactory<mojom::Shell>: 253 // InterfaceFactory<mojom::Shell>:
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 CHECK_NE(mojom::kInvalidInstanceID, id); 370 CHECK_NE(mojom::kInvalidInstanceID, id);
347 return id; 371 return id;
348 } 372 }
349 373
350 void PIDAvailable(base::ProcessId pid) { 374 void PIDAvailable(base::ProcessId pid) {
351 pid_ = pid; 375 pid_ = pid;
352 shell_->NotifyPIDAvailable(id_, pid_); 376 shell_->NotifyPIDAvailable(id_, pid_);
353 } 377 }
354 378
355 mojo::shell::Shell* const shell_; 379 mojo::shell::Shell* const shell_;
380
356 // An id that identifies this instance. Distinct from pid, as a single process 381 // An id that identifies this instance. Distinct from pid, as a single process
357 // may vend multiple application instances, and this object may exist before a 382 // may vend multiple application instances, and this object may exist before a
358 // process is launched. 383 // process is launched.
359 const uint32_t id_; 384 const uint32_t id_;
360 const Identity identity_; 385 const Identity identity_;
361 const CapabilitySpec capability_spec_; 386 const CapabilitySpec capability_spec_;
362 const bool allow_any_application_; 387 const bool allow_any_application_;
363 mojom::ShellClientPtr shell_client_; 388 mojom::ShellClientPtr shell_client_;
364 Binding<mojom::PIDReceiver> pid_receiver_binding_; 389 Binding<mojom::PIDReceiver> pid_receiver_binding_;
365 BindingSet<mojom::Connector> connectors_; 390 BindingSet<mojom::Connector> connectors_;
(...skipping 23 matching lines...) Expand all
389 414
390 Shell::Shell(scoped_ptr<NativeRunnerFactory> native_runner_factory, 415 Shell::Shell(scoped_ptr<NativeRunnerFactory> native_runner_factory,
391 mojom::ShellClientPtr catalog) 416 mojom::ShellClientPtr catalog)
392 : native_runner_factory_(std::move(native_runner_factory)), 417 : native_runner_factory_(std::move(native_runner_factory)),
393 weak_ptr_factory_(this) { 418 weak_ptr_factory_(this) {
394 mojom::ShellClientPtr client; 419 mojom::ShellClientPtr client;
395 mojom::ShellClientRequest request = GetProxy(&client); 420 mojom::ShellClientRequest request = GetProxy(&client);
396 CreateInstance(CreateShellIdentity(), GetPermissiveCapabilities(), 421 CreateInstance(CreateShellIdentity(), GetPermissiveCapabilities(),
397 std::move(client)); 422 std::move(client));
398 shell_connection_.reset(new ShellConnection(this, std::move(request))); 423 shell_connection_.reset(new ShellConnection(this, std::move(request)));
399 shell_connection_->WaitForInitialize();
400 424
401 if (catalog) 425 if (catalog)
402 InitCatalog(std::move(catalog)); 426 InitCatalog(std::move(catalog));
403 } 427 }
404 428
405 Shell::~Shell() { 429 Shell::~Shell() {
406 TerminateShellConnections(); 430 TerminateShellConnections();
407 STLDeleteValues(&name_to_loader_); 431 STLDeleteValues(&name_to_loader_);
408 for (auto& runner : native_runners_) 432 for (auto& runner : native_runners_)
409 runner.reset(); 433 runner.reset();
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 for (auto it = native_runners_.begin(); it != native_runners_.end(); ++it) { 705 for (auto it = native_runners_.begin(); it != native_runners_.end(); ++it) {
682 if (it->get() == runner) { 706 if (it->get() == runner) {
683 native_runners_.erase(it); 707 native_runners_.erase(it);
684 return; 708 return;
685 } 709 }
686 } 710 }
687 } 711 }
688 712
689 } // namespace shell 713 } // namespace shell
690 } // namespace mojo 714 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/runner/child/test_native_main.cc ('k') | mojo/shell/tests/shell/shell_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698