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

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: Changes per review feedback 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
« no previous file with comments | « mojo/public/dart/application.dart ('k') | mojo/public/dart/src/application_connection.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:
42 // - Optionally override initialize() to process command-line args.
61 // - Optionally override acceptConnection() if services are to be provided. 43 // - Optionally override acceptConnection() if services are to be provided.
62 // The override should configure the supplied ServiceProvider and call 44 // - Optionally override close() to clean up application resources.
63 // listen(). See ServiceProvider for details on how to configure it.
64 // - Optionally override initialize() where needed.
65 // - Optionally override requestClose() to clean up state specific to your
66 // application.
67 // To use an Application:
68 // - Call listen() on a newly created Application to begin providing services.
69 // - Call connectToService() to request services from the Shell.
70 // - Call close() to close connections to any requested ServiceProviders and the
71 // Shell.
72 abstract class Application { 45 abstract class Application {
73 _ApplicationImpl _applicationImpl; 46 _ApplicationImpl _applicationImpl;
74 List<ApplicationConnection> _applicationConnections; 47 List<ApplicationConnection> _applicationConnections;
75 List<ServiceProvider> _serviceProviders;
76 48
77 Application(core.MojoMessagePipeEndpoint endpoint) { 49 Application(core.MojoMessagePipeEndpoint endpoint) {
78 _applicationConnections = []; 50 _applicationConnections = [];
79 _serviceProviders = [];
80 _applicationImpl = new _ApplicationImpl(this, endpoint); 51 _applicationImpl = new _ApplicationImpl(this, endpoint);
81 } 52 }
82 53
83 Application.fromHandle(core.MojoHandle appHandle) { 54 Application.fromHandle(core.MojoHandle appHandle) {
84 _applicationConnections = []; 55 _applicationConnections = [];
85 _serviceProviders = [];
86 _applicationImpl = new _ApplicationImpl.fromHandle(this, appHandle); 56 _applicationImpl = new _ApplicationImpl.fromHandle(this, appHandle);
87 } 57 }
88 58
89 void initialize(List<String> args, String url) {} 59 void initialize(List<String> args, String url) {}
90 60
91 // TODO(skydart): This is a temporary fix to allow sky application to consume 61 // TODO(skydart): This is a temporary fix to allow sky application to consume
92 // mojo services. Do not use for any other purpose. 62 // mojo services. Do not use for any other purpose.
93 void initializeFromShellProxy(shell_mojom.ShellProxy shellProxy, 63 void initializeFromShellProxy(shell_mojom.ShellProxy shellProxy,
94 List<String> args, String url) { 64 List<String> args, String url) {
95 _applicationImpl.initialize(shellProxy, args, url); 65 _applicationImpl.initialize(shellProxy, args, url);
96 } 66 }
97 67
98 // Establishes a connection to the app at |url|. 68 // Returns a connection to the app at |url|.
99 ApplicationConnection connectToApplication(String url) { 69 ApplicationConnection connectToApplication(String url) {
100 var serviceProviderProxy = 70 var proxy = new ServiceProviderProxy.unbound();
101 new service_provider.ServiceProviderProxy.unbound(); 71 var stub = new ServiceProviderStub.unbound();
102 // TODO: Need to expose ServiceProvider for local services. 72 _applicationImpl.shell.connectToApplication(url, proxy, stub);
103 _applicationImpl.shell.connectToApplication( 73 var connection = new ApplicationConnection(stub, proxy);
104 url, serviceProviderProxy, null); 74 _applicationConnections.add(connection);
105 var applicationConnection = new ApplicationConnection(serviceProviderProxy); 75 return connection;
106 _applicationConnections.add(applicationConnection);
107 return applicationConnection;
108 } 76 }
109 77
110 void connectToService(String url, bindings.Proxy proxy) { 78 void connectToService(String url, bindings.Proxy proxy) {
111 connectToApplication(url).connectToService(proxy); 79 connectToApplication(url).requestService(proxy);
112 } 80 }
113 81
114 void requestQuit() {} 82 void requestQuit() {}
115 83
116 listen() => _applicationImpl.listen(); 84 listen() => _applicationImpl.listen();
117 85
118 void _requestQuitAndClose() { 86 void _requestQuitAndClose() {
119 requestQuit(); 87 requestQuit();
120 close(); 88 close();
121 } 89 }
122 90
123 void close() { 91 void close() {
124 assert(_applicationImpl != null); 92 assert(_applicationImpl != null);
125 _applicationConnections.forEach((c) => c.serviceProvider.close()); 93 _applicationConnections.forEach((c) => c.close());
126 _applicationConnections.clear(); 94 _applicationConnections.clear();
127 _serviceProviders.forEach((sp) => sp.close());
128 _serviceProviders.clear();
129 _applicationImpl.close(); 95 _applicationImpl.close();
130 } 96 }
131 97
132 void _acceptConnection( 98 void _acceptConnection(
133 String requestorUrl, 99 String requestorUrl,
134 service_provider.ServiceProviderStub services, 100 ServiceProviderStub services,
135 service_provider.ServiceProviderProxy exposedServices) { 101 ServiceProviderProxy exposedServices) {
136 var serviceProvider = new ServiceProvider(services, exposedServices); 102 var connection = new ApplicationConnection(services, exposedServices);
137 _serviceProviders.add(serviceProvider); 103 _applicationConnections.add(connection);
138 acceptConnection(requestorUrl, serviceProvider); 104 acceptConnection(requestorUrl, connection);
139 } 105 }
140 106
141 // Override to register the necessary set of interface on |serviceProvider|. 107 // Override this method to provide services on |connection|.
142 // If you register at least one interface (or set the fallback), then you 108 // If you provide at least one service or set fallbackServiceProvider,
143 // must invoke serviceProvider.listen(). 109 // then you must invoke connection.listen().
144 void acceptConnection(String requestorUrl, ServiceProvider serviceProvider) {} 110 void acceptConnection(String requestorUrl, ApplicationConnection connection) {
111 }
145 } 112 }
OLDNEW
« no previous file with comments | « mojo/public/dart/application.dart ('k') | mojo/public/dart/src/application_connection.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698