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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: mojo/shell/shell.cc
diff --git a/mojo/shell/shell.cc b/mojo/shell/shell.cc
index 0d833e14c48b11984ff471230a926e67bf5ad9d8..667de0b1cf36257f8ec01648f0e35099d5ee80d4 100644
--- a/mojo/shell/shell.cc
+++ b/mojo/shell/shell.cc
@@ -117,16 +117,35 @@ class Shell::Instance : public mojom::Connector,
pid_ = base::Process::Current().Pid();
}
DCHECK_NE(mojom::kInvalidInstanceID, id_);
+
+ shell_client_.set_connection_error_handler(
+ [this] {
+ shell_client_.reset();
+ OnConnectionLost();
+ });
}
~Instance() override {}
+ void OnConnectionLost() {
+ // Any time a Connector is lost or we lose the ShellClient connection, it
+ // may have been the last pipe using this Instance. If so, clean up.
+ if (connectors_.empty() && !shell_client_)
+ shell_->OnInstanceError(this);
+ }
+
+ void OnInitializeResponse(mojom::ConnectorRequest connector_request) {
+ if (connector_request.is_pending()) {
+ connectors_.AddBinding(this, std::move(connector_request));
+ connectors_.set_connection_error_handler(
+ base::Bind(&Instance::OnConnectionLost, base::Unretained(this)));
+ }
+ }
+
void InitializeClient() {
- shell_client_->Initialize(connectors_.CreateInterfacePtrAndBind(this),
- mojom::Identity::From(identity_), id_);
- connectors_.set_connection_error_handler(
- base::Bind(&mojo::shell::Shell::OnInstanceError,
- base::Unretained(shell_), base::Unretained(this)));
+ shell_client_->Initialize(mojom::Identity::From(identity_), id_,
+ base::Bind(&Instance::OnInitializeResponse,
+ base::Unretained(this)));
}
void ConnectToClient(scoped_ptr<ConnectParams> params) {
@@ -217,6 +236,7 @@ class Shell::Instance : public mojom::Connector,
params->set_connect_callback(callback);
shell_->Connect(std::move(params));
}
+
void Clone(mojom::ConnectorRequest request) override {
connectors_.AddBinding(this, std::move(request));
}
@@ -396,7 +416,6 @@ Shell::Shell(scoped_ptr<NativeRunnerFactory> native_runner_factory,
CreateInstance(CreateShellIdentity(), GetPermissiveCapabilities(),
std::move(client));
shell_connection_.reset(new ShellConnection(this, std::move(request)));
- shell_connection_->WaitForInitialize();
if (catalog)
InitCatalog(std::move(catalog));

Powered by Google App Engine
This is Rietveld 408576698