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

Side by Side Diff: mojo/public/dart/src/application_connection.dart

Issue 968243003: Dart: Adds optional named arguments for creating bindings. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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 unified diff | Download patch
OLDNEW
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(String interfaceName, 8 typedef void FallbackServiceFactory(String interfaceName,
9 core.MojoMessagePipeEndpoint endpoint); 9 core.MojoMessagePipeEndpoint endpoint);
10 10
11 11
12 class LocalServiceProvider implements ServiceProvider { 12 class LocalServiceProvider implements ServiceProvider {
13 final ApplicationConnection connection; 13 final ApplicationConnection connection;
14 ServiceProviderStub _stub; 14 ServiceProviderBinding _binding;
sky 2015/03/02 20:28:22 Binding is such a better name than Stub. Thanks!
zra 2015/03/02 20:52:45 No problem =)
15 15
16 LocalServiceProvider(this.connection, this._stub) { 16 LocalServiceProvider(this.connection, this._binding) {
17 _stub.delegate = this; 17 _binding.delegate = this;
18 } 18 }
19 19
20 listen() => _stub.listen(); 20 listen({Function onClosed}) => _binding.listen(onClosed: onClosed);
21 21
22 void close({bool nodefer : false}) => _stub.close(nodefer: nodefer); 22 void close({bool nodefer : false}) => _binding.close(nodefer: nodefer);
23 23
24 void connectToService(String interfaceName, 24 void connectToService(String interfaceName,
25 core.MojoMessagePipeEndpoint pipe) { 25 core.MojoMessagePipeEndpoint pipe) {
26 if (connection._nameToServiceFactory.containsKey(interfaceName)) { 26 if (connection._nameToServiceFactory.containsKey(interfaceName)) {
27 connection._nameToServiceFactory[interfaceName](pipe); 27 connection._nameToServiceFactory[interfaceName](pipe);
28 return; 28 return;
29 } 29 }
30 if (connection.fallbackServiceFactory != null) { 30 if (connection.fallbackServiceFactory != null) {
31 connection.fallbackServiceFactory(interfaceName, pipe); 31 connection.fallbackServiceFactory(interfaceName, pipe);
32 return; 32 return;
(...skipping 24 matching lines...) Expand all
57 // 57 //
58 // The fallbackServiceFactory is only used if a service wasn't specified 58 // The fallbackServiceFactory is only used if a service wasn't specified
59 // with provideService(). 59 // with provideService().
60 60
61 class ApplicationConnection { 61 class ApplicationConnection {
62 ServiceProviderProxy remoteServiceProvider; 62 ServiceProviderProxy remoteServiceProvider;
63 LocalServiceProvider _localServiceProvider; 63 LocalServiceProvider _localServiceProvider;
64 final _nameToServiceFactory = new Map<String, ServiceFactory>(); 64 final _nameToServiceFactory = new Map<String, ServiceFactory>();
65 FallbackServiceFactory _fallbackServiceFactory; 65 FallbackServiceFactory _fallbackServiceFactory;
66 66
67 ApplicationConnection(ServiceProviderStub stub, ServiceProviderProxy proxy) 67 ApplicationConnection(
68 ServiceProviderBinding binding, ServiceProviderProxy proxy)
68 : remoteServiceProvider = proxy { 69 : remoteServiceProvider = proxy {
69 if (stub != null) _localServiceProvider = 70 if (binding != null)
70 new LocalServiceProvider(this, stub); 71 _localServiceProvider = new LocalServiceProvider(this, binding);
71 } 72 }
72 73
73 FallbackServiceFactory get fallbackServiceFactory => _fallbackServiceFactory; 74 FallbackServiceFactory get fallbackServiceFactory => _fallbackServiceFactory;
74 set fallbackServiceFactory(FallbackServiceFactory f) { 75 set fallbackServiceFactory(FallbackServiceFactory f) {
75 assert(_localServiceProvider != null); 76 assert(_localServiceProvider != null);
76 _fallbackServiceFactory = f; 77 _fallbackServiceFactory = f;
77 } 78 }
78 79
79 bindings.ProxyBase requestService(bindings.ProxyBase proxy) { 80 bindings.ProxyBase requestService(bindings.ProxyBase proxy) {
80 assert(!proxy.impl.isBound && 81 assert(!proxy.impl.isBound &&
81 (remoteServiceProvider != null) && 82 (remoteServiceProvider != null) &&
82 remoteServiceProvider.impl.isBound); 83 remoteServiceProvider.impl.isBound);
83 var pipe = new core.MojoMessagePipe(); 84 var pipe = new core.MojoMessagePipe();
84 proxy.impl.bind(pipe.endpoints[0]); 85 proxy.impl.bind(pipe.endpoints[0]);
85 remoteServiceProvider.ptr.connectToService( 86 remoteServiceProvider.ptr.connectToService(
86 proxy.name, pipe.endpoints[1]); 87 proxy.name, pipe.endpoints[1]);
87 return proxy; 88 return proxy;
88 } 89 }
89 90
90 void provideService(String interfaceName, ServiceFactory factory) { 91 void provideService(String interfaceName, ServiceFactory factory) {
91 assert(_localServiceProvider != null); 92 assert(_localServiceProvider != null);
92 _nameToServiceFactory[interfaceName] = factory; 93 _nameToServiceFactory[interfaceName] = factory;
93 } 94 }
94 95
95 void listen() { 96 void listen({Function onClosed}) {
96 assert(_localServiceProvider != null); 97 assert(_localServiceProvider != null);
97 _localServiceProvider.listen(); 98 _localServiceProvider.listen(onClosed: onClosed);
98 } 99 }
99 100
100 void close({bool nodefer: false}) { 101 void close({bool nodefer: false}) {
101 if (remoteServiceProvider != null) { 102 if (remoteServiceProvider != null) {
102 remoteServiceProvider.close(); 103 remoteServiceProvider.close();
103 remoteServiceProvider = null; 104 remoteServiceProvider = null;
104 } 105 }
105 if (_localServiceProvider != null) { 106 if (_localServiceProvider != null) {
106 _localServiceProvider.close(nodefer: nodefer); 107 _localServiceProvider.close(nodefer: nodefer);
107 _localServiceProvider = null; 108 _localServiceProvider = null;
108 } 109 }
109 110
110 } 111 }
111 } 112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698