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

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

Issue 982673002: Dart: Removes need to call listen(). (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Merge and Format 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
« no previous file with comments | « mojo/dart/test/validation_test.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 implements application_mojom.Application { 7 class _ApplicationImpl implements application_mojom.Application {
8 application_mojom.ApplicationStub _stub; 8 application_mojom.ApplicationStub _stub;
9 shell_mojom.ShellProxy shell; 9 shell_mojom.ShellProxy shell;
10 Application _application; 10 Application _application;
11 11
12 _ApplicationImpl(Application application, 12 _ApplicationImpl(
13 core.MojoMessagePipeEndpoint endpoint, {Function onClosed}) { 13 Application application, core.MojoMessagePipeEndpoint endpoint) {
14 _application = application; 14 _application = application;
15 // We wrap the onClosed callback in a closure to ensure that all 15 _stub = new application_mojom.ApplicationStub.fromEndpoint(endpoint, this);
16 // necessary cleanup is performed on a PEER_CLOSED signal. 16 _stub.onError = close;
17 _stub = new application_mojom.ApplicationStub.fromEndpoint(
18 endpoint,
19 impl: this,
20 onClosed: _closer(onClosed));
21 } 17 }
22 18
23 _ApplicationImpl.fromHandle(Application application, core.MojoHandle handle, 19 _ApplicationImpl.fromHandle(Application application, core.MojoHandle handle) {
24 {Function onClosed}) {
25 _application = application; 20 _application = application;
26 _stub = new application_mojom.ApplicationStub.fromHandle( 21 _stub = new application_mojom.ApplicationStub.fromHandle(handle, this);
27 handle, 22 _stub.onError = close;
28 impl: this,
29 onClosed: _closer(onClosed));
30 } 23 }
31 24
32 void initialize(bindings.ProxyBase shellProxy, List<String> args, 25 set onError(core.ErrorHandler f) {
33 String url) { 26 _stub.onError = f;
27 }
28
29 void initialize(
30 bindings.ProxyBase shellProxy, List<String> args, String url) {
34 assert(shell == null); 31 assert(shell == null);
35 shell = shellProxy; 32 shell = shellProxy;
36 _application.initialize(args, url); 33 _application.initialize(args, url);
37 } 34 }
38 35
39 @override 36 @override
40 void acceptConnection(String requestorUrl, ServiceProviderStub services, 37 void acceptConnection(String requestorUrl, ServiceProviderStub services,
41 bindings.ProxyBase exposedServices, String resolvedUrl) => 38 bindings.ProxyBase exposedServices, String resolvedUrl) => _application
42 _application._acceptConnection( 39 ._acceptConnection(requestorUrl, services, exposedServices, resolvedUrl);
43 requestorUrl,
44 services,
45 exposedServices,
46 resolvedUrl);
47 40
48 @override 41 @override
49 void requestQuit() => _application._requestQuitAndClose(); 42 void requestQuit() => _application._requestQuitAndClose();
50 43
51 Function _closer(Function onClosed) {
52 return (() {
53 if (onClosed != null) {
54 onClosed();
55 }
56 close();
57 });
58 }
59
60 void close({bool nodefer: false}) { 44 void close({bool nodefer: false}) {
61 shell.close(); 45 if (shell != null) shell.close();
62 _stub.close(); 46 _stub.close();
63 } 47 }
64 } 48 }
65 49
66 // TODO(zra): Better documentation and examples. 50 // TODO(zra): Better documentation and examples.
67 // To implement, do the following: 51 // To implement, do the following:
68 // - Optionally override initialize() to process command-line args. 52 // - Optionally override initialize() to process command-line args.
69 // - Optionally override acceptConnection() if services are to be provided. 53 // - Optionally override acceptConnection() if services are to be provided.
70 // - Optionally override close() to clean up application resources. 54 // - Optionally override close() to clean up application resources.
71 abstract class Application { 55 abstract class Application {
72 _ApplicationImpl _applicationImpl; 56 _ApplicationImpl _applicationImpl;
73 List<ApplicationConnection> _applicationConnections; 57 List<ApplicationConnection> _applicationConnections;
74 58
75 Application(core.MojoMessagePipeEndpoint endpoint, {Function onClosed}) { 59 Application(core.MojoMessagePipeEndpoint endpoint) {
76 _applicationConnections = []; 60 _applicationConnections = [];
77 // We wrap the onClosed callback in a closure to ensure that all 61 _applicationImpl = new _ApplicationImpl(this, endpoint);
78 // necessary cleanup is performed on a PEER_CLOSED signal. 62 _applicationImpl.onError = close;
79 _applicationImpl =
80 new _ApplicationImpl(this, endpoint, onClosed: _closer(onClosed));
81 } 63 }
82 64
83 Application.fromHandle(core.MojoHandle appHandle, {Function onClosed}) { 65 Application.fromHandle(core.MojoHandle appHandle) {
84 _applicationConnections = []; 66 _applicationConnections = [];
85 _applicationImpl = 67 _applicationImpl = new _ApplicationImpl.fromHandle(this, appHandle);
86 new _ApplicationImpl.fromHandle(this, appHandle, onClosed: _closer(onClo sed)); 68 _applicationImpl.onError = close;
87 } 69 }
88 70
89 void initialize(List<String> args, String url) {} 71 void initialize(List<String> args, String url) {}
90 72
91 // TODO(skydart): This is a temporary fix to allow sky application to consume 73 // TODO(skydart): This is a temporary fix to allow sky application to consume
92 // mojo services. Do not use for any other purpose. 74 // mojo services. Do not use for any other purpose.
93 void initializeFromShellProxy(shell_mojom.ShellProxy shellProxy, 75 void initializeFromShellProxy(
94 List<String> args, String url) => 76 shell_mojom.ShellProxy shellProxy, List<String> args, String url) =>
95 _applicationImpl.initialize(shellProxy, args, url); 77 _applicationImpl.initialize(shellProxy, args, url);
96 78
97 // Returns a connection to the app at |url|. 79 // Returns a connection to the app at |url|.
98 ApplicationConnection connectToApplication(String url) { 80 ApplicationConnection connectToApplication(String url) {
99 var proxy = new ServiceProviderProxy.unbound(); 81 var proxy = new ServiceProviderProxy.unbound();
100 var stub = new ServiceProviderStub.unbound(); 82 var stub = new ServiceProviderStub.unbound();
101 _applicationImpl.shell.ptr.connectToApplication(url, proxy, stub); 83 _applicationImpl.shell.ptr.connectToApplication(url, proxy, stub);
102 var connection = new ApplicationConnection(stub, proxy); 84 var connection = new ApplicationConnection(stub, proxy);
103 _applicationConnections.add(connection); 85 _applicationConnections.add(connection);
104 return connection; 86 return connection;
105 } 87 }
106 88
107 void connectToService(String url, bindings.ProxyBase proxy) { 89 void connectToService(String url, bindings.ProxyBase proxy) {
108 connectToApplication(url).requestService(proxy); 90 connectToApplication(url).requestService(proxy);
109 } 91 }
110 92
111 void requestQuit() {} 93 void requestQuit() {}
112 94
113 void _requestQuitAndClose() { 95 void _requestQuitAndClose() {
114 requestQuit(); 96 requestQuit();
115 close(); 97 close();
116 } 98 }
117 99
118 Function _closer(Function onClose) {
119 return (() {
120 if (onClose != null) {
121 onClose();
122 }
123 close();
124 });
125 }
126
127 void close() { 100 void close() {
128 assert(_applicationImpl != null); 101 assert(_applicationImpl != null);
129 _applicationConnections.forEach((c) => c.close()); 102 _applicationConnections.forEach((c) => c.close());
130 _applicationConnections.clear(); 103 _applicationConnections.clear();
131 _applicationImpl.close(); 104 _applicationImpl.close();
132 } 105 }
133 106
134 // This method closes all the application connections. Used during apptesting. 107 // This method closes all the application connections. Used during apptesting.
135 resetConnections() { 108 void resetConnections() {
136 assert(_applicationImpl != null); 109 assert(_applicationImpl != null);
137 _applicationConnections.forEach((c) => c.close()); 110 _applicationConnections.forEach((c) => c.close());
138 _applicationConnections.clear(); 111 _applicationConnections.clear();
139 } 112 }
140 113
141 void _acceptConnection(String requestorUrl, ServiceProviderStub services, 114 void _acceptConnection(String requestorUrl, ServiceProviderStub services,
142 ServiceProviderProxy exposedServices, String resolvedUrl) { 115 ServiceProviderProxy exposedServices, String resolvedUrl) {
143 var connection = new ApplicationConnection(services, exposedServices); 116 var connection = new ApplicationConnection(services, exposedServices);
144 _applicationConnections.add(connection); 117 _applicationConnections.add(connection);
145 acceptConnection(requestorUrl, resolvedUrl, connection); 118 acceptConnection(requestorUrl, resolvedUrl, connection);
146 } 119 }
147 120
148 // Override this method to provide services on |connection|. 121 // Override this method to provide services on |connection|.
149 // If you provide at least one service or set fallbackServiceProvider,
150 // then you must invoke connection.listen().
151 void acceptConnection(String requestorUrl, String resolvedUrl, 122 void acceptConnection(String requestorUrl, String resolvedUrl,
152 ApplicationConnection connection) { 123 ApplicationConnection connection) {}
153 }
154 } 124 }
OLDNEW
« no previous file with comments | « mojo/dart/test/validation_test.dart ('k') | mojo/public/dart/src/application_connection.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698