| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:mojo/application.dart'; | 7 import 'package:mojo/application.dart'; |
| 8 import 'package:mojo/bindings.dart'; | 8 import 'package:mojo/bindings.dart'; |
| 9 import 'package:mojo/core.dart'; | 9 import 'package:mojo/core.dart'; |
| 10 import 'package:_mojo_for_test_only/test/echo_service.mojom.dart'; | 10 import 'package:_mojo_for_test_only/test/echo_service.mojom.dart'; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 dynamic delayedEchoString(String value, int millis, | 27 dynamic delayedEchoString(String value, int millis, |
| 28 [Function responseFactory]) { | 28 [Function responseFactory]) { |
| 29 if (value == "quit") { | 29 if (value == "quit") { |
| 30 _stub.close(); | 30 _stub.close(); |
| 31 } | 31 } |
| 32 return new Future.delayed( | 32 return new Future.delayed( |
| 33 new Duration(milliseconds: millis), () => responseFactory(value)); | 33 new Duration(milliseconds: millis), () => responseFactory(value)); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void swap() { |
| 37 _swapImpls(this); |
| 38 } |
| 39 |
| 36 void quit() {} | 40 void quit() {} |
| 41 |
| 42 static void _swapImpls(EchoServiceImpl impl) { |
| 43 final stub = impl._stub; |
| 44 final app = impl._application; |
| 45 // It is not allowed to do an unbind in the midst of handling an event, so |
| 46 // it is delayed until popping back out to the event loop. |
| 47 Timer.run(() { |
| 48 final endpoint = stub.unbind(); |
| 49 new EchoServiceImpl(app, endpoint); |
| 50 }); |
| 51 } |
| 37 } | 52 } |
| 38 | 53 |
| 39 class EchoApplication extends Application { | 54 class EchoApplication extends Application { |
| 40 EchoApplication.fromHandle(MojoHandle handle) : super.fromHandle(handle); | 55 EchoApplication.fromHandle(MojoHandle handle) : super.fromHandle(handle); |
| 41 | 56 |
| 42 @override | 57 @override |
| 43 void acceptConnection(String requestorUrl, String resolvedUrl, | 58 void acceptConnection(String requestorUrl, String resolvedUrl, |
| 44 ApplicationConnection connection) { | 59 ApplicationConnection connection) { |
| 45 // No services are required from the remote end. | 60 // No services are required from the remote end. |
| 46 connection.remoteServiceProvider.close(); | 61 connection.remoteServiceProvider.close(); |
| 47 connection.provideService(EchoService.serviceName, | 62 connection.provideService(EchoService.serviceName, |
| 48 (endpoint) => new EchoServiceImpl(this, endpoint)); | 63 (endpoint) => new EchoServiceImpl(this, endpoint)); |
| 49 } | 64 } |
| 50 } | 65 } |
| 51 | 66 |
| 52 main(List args, Object handleToken) { | 67 main(List args, Object handleToken) { |
| 53 MojoHandle appHandle = new MojoHandle(handleToken); | 68 MojoHandle appHandle = new MojoHandle(handleToken); |
| 54 new EchoApplication.fromHandle(appHandle) | 69 new EchoApplication.fromHandle(appHandle) |
| 55 ..onError = ((_) { | 70 ..onError = ((_) { |
| 56 MojoHandle.reportLeakedHandles(); | 71 MojoHandle.reportLeakedHandles(); |
| 57 }); | 72 }); |
| 58 } | 73 } |
| OLD | NEW |