| OLD | NEW |
| 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 Loading... |
| 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 [this] { |
| 123 shell_client_.reset(); |
| 124 OnConnectionLost(); |
| 125 }); |
| 120 } | 126 } |
| 121 | 127 |
| 122 ~Instance() override {} | 128 ~Instance() override {} |
| 123 | 129 |
| 130 void OnConnectionLost() { |
| 131 // Any time a Connector is lost or we lose the ShellClient connection, it |
| 132 // may have been the last pipe using this Instance. If so, clean up. |
| 133 if (connectors_.empty() && !shell_client_) |
| 134 shell_->OnInstanceError(this); |
| 135 } |
| 136 |
| 137 void OnInitializeResponse(mojom::ConnectorRequest connector_request) { |
| 138 if (connector_request.is_pending()) { |
| 139 connectors_.AddBinding(this, std::move(connector_request)); |
| 140 connectors_.set_connection_error_handler( |
| 141 base::Bind(&Instance::OnConnectionLost, base::Unretained(this))); |
| 142 } |
| 143 } |
| 144 |
| 124 void InitializeClient() { | 145 void InitializeClient() { |
| 125 shell_client_->Initialize(connectors_.CreateInterfacePtrAndBind(this), | 146 shell_client_->Initialize(mojom::Identity::From(identity_), id_, |
| 126 mojom::Identity::From(identity_), id_); | 147 base::Bind(&Instance::OnInitializeResponse, |
| 127 connectors_.set_connection_error_handler( | 148 base::Unretained(this))); |
| 128 base::Bind(&mojo::shell::Shell::OnInstanceError, | |
| 129 base::Unretained(shell_), base::Unretained(this))); | |
| 130 } | 149 } |
| 131 | 150 |
| 132 void ConnectToClient(scoped_ptr<ConnectParams> params) { | 151 void ConnectToClient(scoped_ptr<ConnectParams> params) { |
| 133 params->connect_callback().Run(mojom::ConnectResult::SUCCEEDED, | 152 params->connect_callback().Run(mojom::ConnectResult::SUCCEEDED, |
| 134 identity_.user_id(), id_); | 153 identity_.user_id(), id_); |
| 135 uint32_t source_id = mojom::kInvalidInstanceID; | 154 uint32_t source_id = mojom::kInvalidInstanceID; |
| 136 CapabilityRequest spec; | 155 CapabilityRequest spec; |
| 137 spec.interfaces.insert("*"); | 156 spec.interfaces.insert("*"); |
| 138 Instance* source = shell_->GetExistingInstance(params->source()); | 157 Instance* source = shell_->GetExistingInstance(params->source()); |
| 139 if (source) { | 158 if (source) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 229 |
| 211 scoped_ptr<ConnectParams> params(new ConnectParams); | 230 scoped_ptr<ConnectParams> params(new ConnectParams); |
| 212 params->set_source(identity_); | 231 params->set_source(identity_); |
| 213 params->set_target(target); | 232 params->set_target(target); |
| 214 params->set_remote_interfaces(std::move(remote_interfaces)); | 233 params->set_remote_interfaces(std::move(remote_interfaces)); |
| 215 params->set_local_interfaces(std::move(local_interfaces)); | 234 params->set_local_interfaces(std::move(local_interfaces)); |
| 216 params->set_client_process_connection(std::move(client_process_connection)); | 235 params->set_client_process_connection(std::move(client_process_connection)); |
| 217 params->set_connect_callback(callback); | 236 params->set_connect_callback(callback); |
| 218 shell_->Connect(std::move(params)); | 237 shell_->Connect(std::move(params)); |
| 219 } | 238 } |
| 239 |
| 220 void Clone(mojom::ConnectorRequest request) override { | 240 void Clone(mojom::ConnectorRequest request) override { |
| 221 connectors_.AddBinding(this, std::move(request)); | 241 connectors_.AddBinding(this, std::move(request)); |
| 222 } | 242 } |
| 223 | 243 |
| 224 // mojom::PIDReceiver: | 244 // mojom::PIDReceiver: |
| 225 void SetPID(uint32_t pid) override { | 245 void SetPID(uint32_t pid) override { |
| 226 PIDAvailable(pid); | 246 PIDAvailable(pid); |
| 227 } | 247 } |
| 228 | 248 |
| 229 // InterfaceFactory<mojom::Shell>: | 249 // InterfaceFactory<mojom::Shell>: |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 | 409 |
| 390 Shell::Shell(scoped_ptr<NativeRunnerFactory> native_runner_factory, | 410 Shell::Shell(scoped_ptr<NativeRunnerFactory> native_runner_factory, |
| 391 mojom::ShellClientPtr catalog) | 411 mojom::ShellClientPtr catalog) |
| 392 : native_runner_factory_(std::move(native_runner_factory)), | 412 : native_runner_factory_(std::move(native_runner_factory)), |
| 393 weak_ptr_factory_(this) { | 413 weak_ptr_factory_(this) { |
| 394 mojom::ShellClientPtr client; | 414 mojom::ShellClientPtr client; |
| 395 mojom::ShellClientRequest request = GetProxy(&client); | 415 mojom::ShellClientRequest request = GetProxy(&client); |
| 396 CreateInstance(CreateShellIdentity(), GetPermissiveCapabilities(), | 416 CreateInstance(CreateShellIdentity(), GetPermissiveCapabilities(), |
| 397 std::move(client)); | 417 std::move(client)); |
| 398 shell_connection_.reset(new ShellConnection(this, std::move(request))); | 418 shell_connection_.reset(new ShellConnection(this, std::move(request))); |
| 399 shell_connection_->WaitForInitialize(); | |
| 400 | 419 |
| 401 if (catalog) | 420 if (catalog) |
| 402 InitCatalog(std::move(catalog)); | 421 InitCatalog(std::move(catalog)); |
| 403 } | 422 } |
| 404 | 423 |
| 405 Shell::~Shell() { | 424 Shell::~Shell() { |
| 406 TerminateShellConnections(); | 425 TerminateShellConnections(); |
| 407 STLDeleteValues(&name_to_loader_); | 426 STLDeleteValues(&name_to_loader_); |
| 408 for (auto& runner : native_runners_) | 427 for (auto& runner : native_runners_) |
| 409 runner.reset(); | 428 runner.reset(); |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 for (auto it = native_runners_.begin(); it != native_runners_.end(); ++it) { | 700 for (auto it = native_runners_.begin(); it != native_runners_.end(); ++it) { |
| 682 if (it->get() == runner) { | 701 if (it->get() == runner) { |
| 683 native_runners_.erase(it); | 702 native_runners_.erase(it); |
| 684 return; | 703 return; |
| 685 } | 704 } |
| 686 } | 705 } |
| 687 } | 706 } |
| 688 | 707 |
| 689 } // namespace shell | 708 } // namespace shell |
| 690 } // namespace mojo | 709 } // namespace mojo |
| OLD | NEW |