Chromium Code Reviews| Index: mojo/public/dart/src/application.dart |
| diff --git a/mojo/public/dart/src/application.dart b/mojo/public/dart/src/application.dart |
| index 3ae900b5ce884a95669d031425ee1b1cc07ccf07..5942002dd7992d9464f91d634796ffea85ad84f8 100644 |
| --- a/mojo/public/dart/src/application.dart |
| +++ b/mojo/public/dart/src/application.dart |
| @@ -5,39 +5,56 @@ |
| part of application; |
| class _ApplicationImpl implements application_mojom.Application { |
| - application_mojom.ApplicationStub _stub; |
| + application_mojom.ApplicationBinding _binding; |
| shell_mojom.ShellProxy shell; |
| Application _application; |
| _ApplicationImpl(Application application, |
| - core.MojoMessagePipeEndpoint endpoint) { |
| + core.MojoMessagePipeEndpoint endpoint, |
| + {Function onClosed}) { |
| _application = application; |
| - _stub = new application_mojom.ApplicationStub.fromEndpoint(endpoint) |
| - ..delegate = this |
| - ..listen(); |
| + // We wrap the onClosed callback in a closure to ensure that all |
| + // necessary cleanup is performed on a PEER_CLOSED signal. |
|
sky
2015/03/02 20:28:22
The C++ side uses connection error and not just cl
zra
2015/03/02 20:52:45
Do you mean in addition to onDone? What does a con
|
| + _binding = new application_mojom.ApplicationBinding.fromEndpoint( |
| + endpoint, delegate: this, onClosed: _closer(onClosed)); |
| } |
| - _ApplicationImpl.fromHandle(Application application, core.MojoHandle handle) { |
| + _ApplicationImpl.fromHandle(Application application, core.MojoHandle handle, |
| + {Function onClosed}) { |
| _application = application; |
| - _stub = new application_mojom.ApplicationStub.fromHandle(handle) |
| - ..delegate = this |
| - ..listen(); |
| + _binding = new application_mojom.ApplicationBinding.fromHandle( |
| + handle, delegate: this, onClosed: _closer(onClosed)); |
| } |
| - void initialize(bindings.ProxyBase shellProxy, List<String> args, |
| - String url) { |
| + void initialize( |
| + bindings.ProxyBase shellProxy, List<String> args, String url) { |
| assert(shell == null); |
| shell = shellProxy; |
| _application.initialize(args, url); |
| } |
| - void acceptConnection(String requestorUrl, ServiceProviderStub services, |
| - bindings.ProxyBase exposedServices, String requested_url) => |
| - _application._acceptConnection(requestorUrl, services, exposedServices); |
| + void acceptConnection(String requestorUrl, |
| + ServiceProviderBinding services, |
| + bindings.ProxyBase exposedServices, |
| + String resolvedUrl) => |
| + _application._acceptConnection( |
| + requestorUrl, services, exposedServices, resolvedUrl); |
| void requestQuit() => _application._requestQuitAndClose(); |
| - void close({bool nodefer: false}) => shell.close(); |
| + Function _closer(Function onClosed) { |
| + return (() { |
| + if(onClosed != null) { |
| + onClosed(); |
| + } |
| + close(); |
| + }); |
| + } |
| + |
| + void close({bool nodefer: false}) { |
| + shell.close(); |
| + _binding.close(); |
| + } |
| } |
| // TODO(zra): Better documentation and examples. |
| @@ -49,14 +66,18 @@ abstract class Application { |
| _ApplicationImpl _applicationImpl; |
| List<ApplicationConnection> _applicationConnections; |
| - Application(core.MojoMessagePipeEndpoint endpoint) { |
| + Application(core.MojoMessagePipeEndpoint endpoint, {Function onClosed}) { |
| _applicationConnections = []; |
| - _applicationImpl = new _ApplicationImpl(this, endpoint); |
| + // We wrap the onClosed callback in a closure to ensure that all |
| + // necessary cleanup is performed on a PEER_CLOSED signal. |
| + _applicationImpl = new _ApplicationImpl( |
| + this, endpoint, onClosed: _closer(onClosed)); |
| } |
| - Application.fromHandle(core.MojoHandle appHandle) { |
| + Application.fromHandle(core.MojoHandle appHandle, {Function onClosed}) { |
| _applicationConnections = []; |
| - _applicationImpl = new _ApplicationImpl.fromHandle(this, appHandle); |
| + _applicationImpl = new _ApplicationImpl.fromHandle( |
| + this, appHandle, onClosed: _closer(onClosed)); |
| } |
| void initialize(List<String> args, String url) {} |
| @@ -65,14 +86,14 @@ abstract class Application { |
| // mojo services. Do not use for any other purpose. |
| void initializeFromShellProxy(shell_mojom.ShellProxy shellProxy, |
| List<String> args, String url) => |
| - _applicationImpl.initialize(shellProxy, args, url); |
| + _applicationImpl.initialize(shellProxy, args, url); |
| // Returns a connection to the app at |url|. |
| ApplicationConnection connectToApplication(String url) { |
| var proxy = new ServiceProviderProxy.unbound(); |
| - var stub = new ServiceProviderStub.unbound(); |
| - _applicationImpl.shell.ptr.connectToApplication(url, proxy, stub); |
| - var connection = new ApplicationConnection(stub, proxy); |
| + var binding = new ServiceProviderBinding.unbound(); |
| + _applicationImpl.shell.ptr.connectToApplication(url, proxy, binding); |
| + var connection = new ApplicationConnection(binding, proxy); |
| _applicationConnections.add(connection); |
| return connection; |
| } |
| @@ -88,23 +109,39 @@ abstract class Application { |
| close(); |
| } |
| + Function _closer(Function onClose) { |
| + return (() { |
| + if (onClose != null) { |
| + onClose(); |
| + } |
| + close(); |
| + }); |
| + } |
| + |
| void close() { |
| - assert(_applicationImpl != null); |
| _applicationConnections.forEach((c) => c.close()); |
| _applicationConnections.clear(); |
| - _applicationImpl.close(); |
| + if (_applicationImpl != null) { |
| + _applicationImpl.close(); |
| + _applicationImpl = null; |
| + } |
| } |
| - void _acceptConnection(String requestorUrl, ServiceProviderStub services, |
| - ServiceProviderProxy exposedServices) { |
| + void _acceptConnection( |
| + String requestorUrl, |
| + ServiceProviderBinding services, |
| + ServiceProviderProxy exposedServices, |
| + String resolvedUrl) { |
| var connection = new ApplicationConnection(services, exposedServices); |
| _applicationConnections.add(connection); |
| - acceptConnection(requestorUrl, connection); |
| + acceptConnection(requestorUrl, connection, resolvedUrl); |
| } |
| // Override this method to provide services on |connection|. |
| // If you provide at least one service or set fallbackServiceProvider, |
| // then you must invoke connection.listen(). |
| - void acceptConnection(String requestorUrl, ApplicationConnection connection) { |
| + void acceptConnection(String requestorUrl, |
| + ApplicationConnection connection, |
| + String resolvedUrl) { |
| } |
| } |