| 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 part of application; | 5 part of application; |
| 6 | 6 |
| 7 typedef Object ServiceFactory(core.MojoMessagePipeEndpoint endpoint); | 7 typedef Object ServiceFactory(core.MojoMessagePipeEndpoint endpoint); |
| 8 typedef void FallbackServiceFactory( | 8 typedef void FallbackServiceFactory( |
| 9 String interfaceName, core.MojoMessagePipeEndpoint endpoint); | 9 String interfaceName, core.MojoMessagePipeEndpoint endpoint); |
| 10 | 10 |
| 11 class LocalServiceProvider implements ServiceProvider { | 11 class LocalServiceProvider implements ServiceProvider { |
| 12 final ApplicationConnection connection; | 12 final ApplicationConnection connection; |
| 13 ServiceProviderStub _stub; | 13 ServiceProviderStub _stub; |
| 14 | 14 |
| 15 LocalServiceProvider(this.connection, this._stub) { | 15 LocalServiceProvider(this.connection, this._stub) { |
| 16 assert(_stub.isOpen); | 16 assert(_stub.isOpen); |
| 17 _stub.impl = this; | 17 _stub.impl = this; |
| 18 } | 18 } |
| 19 | 19 |
| 20 set onError(Function f) { | 20 set onError(Function f) { |
| 21 _stub.onError = f; | 21 _stub.onError = f; |
| 22 } | 22 } |
| 23 | 23 |
| 24 void close({bool nodefer: false}) => _stub.close(nodefer: nodefer); | 24 Future close({bool nodefer: false}) => _stub.close(nodefer: nodefer); |
| 25 | 25 |
| 26 void connectToService( | 26 void connectToService( |
| 27 String interfaceName, core.MojoMessagePipeEndpoint pipe) { | 27 String interfaceName, core.MojoMessagePipeEndpoint pipe) { |
| 28 if (connection._nameToServiceFactory.containsKey(interfaceName)) { | 28 if (connection._nameToServiceFactory.containsKey(interfaceName)) { |
| 29 connection._nameToServiceFactory[interfaceName](pipe); | 29 connection._nameToServiceFactory[interfaceName](pipe); |
| 30 return; | 30 return; |
| 31 } | 31 } |
| 32 if (connection.fallbackServiceFactory != null) { | 32 if (connection.fallbackServiceFactory != null) { |
| 33 connection.fallbackServiceFactory(interfaceName, pipe); | 33 connection.fallbackServiceFactory(interfaceName, pipe); |
| 34 return; | 34 return; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 remoteServiceProvider.ptr.connectToService(proxy.name, pipe.endpoints[1]); | 89 remoteServiceProvider.ptr.connectToService(proxy.name, pipe.endpoints[1]); |
| 90 return proxy; | 90 return proxy; |
| 91 } | 91 } |
| 92 | 92 |
| 93 void provideService(String interfaceName, ServiceFactory factory) { | 93 void provideService(String interfaceName, ServiceFactory factory) { |
| 94 assert(_localServiceProvider != null); | 94 assert(_localServiceProvider != null); |
| 95 _nameToServiceFactory[interfaceName] = factory; | 95 _nameToServiceFactory[interfaceName] = factory; |
| 96 } | 96 } |
| 97 | 97 |
| 98 void _errorHandler() { | 98 void _errorHandler() { |
| 99 if (onError != null) onError(); | 99 close().then((_) { |
| 100 close(); | 100 if (onError != null) onError(); |
| 101 }); |
| 101 } | 102 } |
| 102 | 103 |
| 103 void close({bool nodefer: false}) { | 104 Future close({bool nodefer: false}) { |
| 105 var rspCloseFuture; |
| 106 var lspCloseFuture; |
| 104 if (remoteServiceProvider != null) { | 107 if (remoteServiceProvider != null) { |
| 105 remoteServiceProvider.close(); | 108 rspCloseFuture = remoteServiceProvider.close(); |
| 106 remoteServiceProvider = null; | 109 remoteServiceProvider = null; |
| 110 } else { |
| 111 rspCloseFuture = new Future.value(null); |
| 107 } | 112 } |
| 108 if (_localServiceProvider != null) { | 113 if (_localServiceProvider != null) { |
| 109 _localServiceProvider.close(nodefer: nodefer); | 114 lspCloseFuture = _localServiceProvider.close(nodefer: nodefer); |
| 110 _localServiceProvider = null; | 115 _localServiceProvider = null; |
| 116 } else { |
| 117 lspCloseFuture = new Future.value(null); |
| 111 } | 118 } |
| 119 return rspCloseFuture.then((_) => lspCloseFuture); |
| 112 } | 120 } |
| 113 } | 121 } |
| OLD | NEW |