Make Sky embedder.connection deal with null handles
Also: gratuitous simplication of ApplicationConnection.requestService().
R=abarth@chromium.org
Review URL: https://codereview.chromium.org/954653002
diff --git a/mojo/public/dart/src/application_connection.dart b/mojo/public/dart/src/application_connection.dart
index 4f31468..c44944e 100644
--- a/mojo/public/dart/src/application_connection.dart
+++ b/mojo/public/dart/src/application_connection.dart
@@ -74,11 +74,9 @@
assert(!proxy.isBound &&
(remoteServiceProvider != null) &&
remoteServiceProvider.isBound);
- var applicationPipe = new core.MojoMessagePipe();
- var proxyEndpoint = applicationPipe.endpoints[0];
- var applicationEndpoint = applicationPipe.endpoints[1];
- proxy.bind(proxyEndpoint);
- remoteServiceProvider.connectToService(proxy.name, applicationEndpoint);
+ var pipe = new core.MojoMessagePipe();
+ proxy.bind(pipe.endpoints[0]);
+ remoteServiceProvider.connectToService(proxy.name, pipe.endpoints[1]);
return proxy;
}
diff --git a/sky/framework/embedder.dart b/sky/framework/embedder.dart
index 90046be..8b2385d 100644
--- a/sky/framework/embedder.dart
+++ b/sky/framework/embedder.dart
@@ -12,14 +12,26 @@
final _EmbedderImpl embedder = new _EmbedderImpl();
class _EmbedderImpl {
- static final ShellProxy shell = new ShellProxy.fromHandle(
+ ApplicationConnection _connection;
+
+ final ShellProxy shell = new ShellProxy.fromHandle(
new core.MojoHandle(internals.takeShellProxyHandle()));
- static final ApplicationConnection connection = new ApplicationConnection(
- new ServiceProviderStub.fromHandle(
- new core.MojoHandle(internals.takeServicesProvidedToEmbedder())),
- new ServiceProviderProxy.fromHandle(
- new core.MojoHandle(internals.takeServicesProvidedByEmbedder())));
+ ApplicationConnection get connection {
+ if (_connection == null) {
+ var stubHandle = new core.MojoHandle(
+ internals.takeServicesProvidedToEmbedder());
+ var proxyHandle = new core.MojoHandle(
+ internals.takeServicesProvidedByEmbedder());
+ _connection = new ApplicationConection(
+ stubHandle.isValid ? ServiceProviderStub.fromHandle(stubHandle)
+ : null;
+ proxyHandle.isValid ? ServiceProviderProxy.fromHandle(proxyHandle)
+ : null;
+ );
+ }
+ return _connection;
+ }
ApplicationConnection connectToApplication(String url) {
var proxy = new ServiceProviderProxy.unbound();