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

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

Issue 934253003: Dart Bindings: ApplicationConnection (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 class _ApplicationImpl extends application_mojom.Application { 7 class _ApplicationImpl extends application_mojom.Application {
8 shell_mojom.ShellProxy shell; 8 shell_mojom.ShellProxy shell;
9 Application _application; 9 Application _application;
10 10
11 _ApplicationImpl( 11 _ApplicationImpl(
12 Application application, core.MojoMessagePipeEndpoint endpoint) 12 Application application, core.MojoMessagePipeEndpoint endpoint)
13 : _application = application, super(endpoint) { 13 : _application = application, super(endpoint) {
14 super.delegate = this; 14 super.delegate = this;
15 } 15 }
16 16
17 _ApplicationImpl.fromHandle(Application application, core.MojoHandle handle) 17 _ApplicationImpl.fromHandle(Application application, core.MojoHandle handle)
18 : _application = application, super.fromHandle(handle) { 18 : _application = application, super.fromHandle(handle) {
19 super.delegate = this; 19 super.delegate = this;
20 } 20 }
21 21
22 void initialize(shell_mojom.ShellProxy shellProxy, 22 void initialize(
23 List<String> args, 23 shell_mojom.ShellProxy shellProxy, List<String> args, String url) {
24 String url) {
25 assert(shell == null); 24 assert(shell == null);
26 shell = shellProxy; 25 shell = shellProxy;
27 _application.initialize(args, url); 26 _application.initialize(args, url);
28 } 27 }
29 28
30 void acceptConnection( 29 void acceptConnection(
31 String requestorUrl, 30 String requestorUrl,
32 service_provider.ServiceProviderStub services, 31 ServiceProviderStub services,
33 service_provider.ServiceProviderProxy exposedServices) => 32 ServiceProviderProxy exposedServices) =>
34 _application._acceptConnection(requestorUrl, services, exposedServices); 33 _application._acceptConnection(requestorUrl, services, exposedServices);
35 34
36 void requestQuit() => _application._requestQuitAndClose(); 35 void requestQuit() => _application._requestQuitAndClose();
37 36
38 void close({bool nodefer: false}) => shell.close(); 37 void close({bool nodefer: false}) => shell.close();
39 } 38 }
40 39
41 // ApplicationConnection represents a single outgoing connection to another app.
42 class ApplicationConnection {
43 // ServiceProvider used to obtain services from the remote application.
44 service_provider.ServiceProviderProxy serviceProvider;
45
46 ApplicationConnection(this.serviceProvider);
47
48 // Obtains a service from the remote application.
49 void connectToService(bindings.Proxy proxy) {
50 assert(!proxy.isBound);
51 var applicationPipe = new core.MojoMessagePipe();
52 var proxyEndpoint = applicationPipe.endpoints[0];
53 var applicationEndpoint = applicationPipe.endpoints[1];
54 proxy.bind(proxyEndpoint);
55 serviceProvider.connectToService(proxy.name, applicationEndpoint);
56 }
57 }
58
59 // TODO(zra): Better documentation and examples. 40 // TODO(zra): Better documentation and examples.
60 // To implement, do the following: 41 // To implement, do the following:
61 // - Optionally override acceptConnection() if services are to be provided. 42 // - Optionally override acceptConnection() if services are to be provided.
zra 2015/02/18 21:45:33 It looks like this comment is out of date now. Sho
hansmuller1 2015/02/18 22:07:24 I revised the comment and removed the part about "
62 // The override should configure the supplied ServiceProvider and call 43 // The override should configure the supplied ServiceProvider and call
63 // listen(). See ServiceProvider for details on how to configure it. 44 // listen(). See ServiceProvider for details on how to configure it.
64 // - Optionally override initialize() where needed. 45 // - Optionally override initialize() where needed.
65 // - Optionally override requestClose() to clean up state specific to your 46 // - Optionally override requestClose() to clean up state specific to your
66 // application. 47 // application.
67 // To use an Application: 48 // To use an Application:
68 // - Call listen() on a newly created Application to begin providing services. 49 // - Call listen() on a newly created Application to begin providing services.
69 // - Call connectToService() to request services from the Shell. 50 // - Call connectToService() to request services from the Shell.
70 // - Call close() to close connections to any requested ServiceProviders and the 51 // - Call close() to close connections to any requested ServiceProviders and the
71 // Shell. 52 // Shell.
72 abstract class Application { 53 abstract class Application {
73 _ApplicationImpl _applicationImpl; 54 _ApplicationImpl _applicationImpl;
74 List<ApplicationConnection> _applicationConnections; 55 List<ApplicationConnection> _applicationConnections;
75 List<ServiceProvider> _serviceProviders;
76 56
77 Application(core.MojoMessagePipeEndpoint endpoint) { 57 Application(core.MojoMessagePipeEndpoint endpoint) {
78 _applicationConnections = []; 58 _applicationConnections = [];
79 _serviceProviders = [];
80 _applicationImpl = new _ApplicationImpl(this, endpoint); 59 _applicationImpl = new _ApplicationImpl(this, endpoint);
81 } 60 }
82 61
83 Application.fromHandle(core.MojoHandle appHandle) { 62 Application.fromHandle(core.MojoHandle appHandle) {
84 _applicationConnections = []; 63 _applicationConnections = [];
85 _serviceProviders = [];
86 _applicationImpl = new _ApplicationImpl.fromHandle(this, appHandle); 64 _applicationImpl = new _ApplicationImpl.fromHandle(this, appHandle);
87 } 65 }
88 66
89 void initialize(List<String> args, String url) {} 67 void initialize(List<String> args, String url) {}
90 68
91 // TODO(skydart): This is a temporary fix to allow sky application to consume 69 // TODO(skydart): This is a temporary fix to allow sky application to consume
92 // mojo services. Do not use for any other purpose. 70 // mojo services. Do not use for any other purpose.
93 void initializeFromShellProxy(shell_mojom.ShellProxy shellProxy, 71 void initializeFromShellProxy(shell_mojom.ShellProxy shellProxy,
94 List<String> args, String url) { 72 List<String> args, String url) {
95 _applicationImpl.initialize(shellProxy, args, url); 73 _applicationImpl.initialize(shellProxy, args, url);
96 } 74 }
97 75
98 // Establishes a connection to the app at |url|. 76 // Returns a connection to the app at |url|.
99 ApplicationConnection connectToApplication(String url) { 77 ApplicationConnection connectToApplication(String url) {
100 var serviceProviderProxy = 78 var proxy = new ServiceProviderProxy.unbound();
101 new service_provider.ServiceProviderProxy.unbound(); 79 var stub = new ServiceProviderStub.unbound();
102 // TODO: Need to expose ServiceProvider for local services. 80 _applicationImpl.shell.connectToApplication(url, proxy, stub);
103 _applicationImpl.shell.connectToApplication( 81 var connection = new ApplicationConnection(stub, proxy);
104 url, serviceProviderProxy, null); 82 _applicationConnections.add(connection);
105 var applicationConnection = new ApplicationConnection(serviceProviderProxy); 83 return connection;
106 _applicationConnections.add(applicationConnection);
107 return applicationConnection;
108 } 84 }
109 85
110 void connectToService(String url, bindings.Proxy proxy) { 86 void connectToService(String url, bindings.Proxy proxy) {
111 connectToApplication(url).connectToService(proxy); 87 connectToApplication(url).requestService(proxy);
112 } 88 }
113 89
114 void requestQuit() {} 90 void requestQuit() {}
115 91
116 listen() => _applicationImpl.listen(); 92 listen() => _applicationImpl.listen();
117 93
118 void _requestQuitAndClose() { 94 void _requestQuitAndClose() {
119 requestQuit(); 95 requestQuit();
120 close(); 96 close();
121 } 97 }
122 98
123 void close() { 99 void close() {
124 assert(_applicationImpl != null); 100 assert(_applicationImpl != null);
125 _applicationConnections.forEach((c) => c.serviceProvider.close()); 101 _applicationConnections.forEach((c) => c.close());
126 _applicationConnections.clear(); 102 _applicationConnections.clear();
127 _serviceProviders.forEach((sp) => sp.close());
128 _serviceProviders.clear();
129 _applicationImpl.close(); 103 _applicationImpl.close();
130 } 104 }
131 105
132 void _acceptConnection( 106 void _acceptConnection(
133 String requestorUrl, 107 String requestorUrl,
134 service_provider.ServiceProviderStub services, 108 ServiceProviderStub services,
135 service_provider.ServiceProviderProxy exposedServices) { 109 ServiceProviderProxy exposedServices) {
136 var serviceProvider = new ServiceProvider(services, exposedServices); 110 var connection = new ApplicationConnection(services, exposedServices);
137 _serviceProviders.add(serviceProvider); 111 _applicationConnections.add(connection);
138 acceptConnection(requestorUrl, serviceProvider); 112 acceptConnection(requestorUrl, connection);
139 } 113 }
140 114
141 // Override to register the necessary set of interface on |serviceProvider|. 115 // Override this method to provide services on |connection|.
142 // If you register at least one interface (or set the fallback), then you 116 // If you provide at least one service or set fallbackServiceProvider,
143 // must invoke serviceProvider.listen(). 117 // then you must invoke connection.listen().
144 void acceptConnection(String requestorUrl, ServiceProvider serviceProvider) {} 118 void acceptConnection(String requestorUrl, ApplicationConnection connection) { }
zra 2015/02/18 21:45:33 This curly brace looks out of place.
hansmuller1 2015/02/18 22:07:24 Another long line. Fixed.
145 } 119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698