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

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

Issue 1132063007: Rationalize Dart mojo and sky package structure (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 7 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/rules.gni ('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
(Empty)
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
3 // found in the LICENSE file.
4
5 part of application;
6
7 class _ApplicationImpl implements application_mojom.Application {
8 application_mojom.ApplicationStub _stub;
9 shell_mojom.ShellProxy shell;
10 Application _application;
11
12 _ApplicationImpl(
13 Application application, core.MojoMessagePipeEndpoint endpoint) {
14 _application = application;
15 _stub = new application_mojom.ApplicationStub.fromEndpoint(endpoint, this);
16 _stub.onError = close;
17 }
18
19 _ApplicationImpl.fromHandle(Application application, core.MojoHandle handle) {
20 _application = application;
21 _stub = new application_mojom.ApplicationStub.fromHandle(handle, this);
22 _stub.onError = close;
23 }
24
25 set onError(core.ErrorHandler f) {
26 _stub.onError = f;
27 }
28
29 void initialize(
30 bindings.ProxyBase shellProxy, List<String> args, String url) {
31 assert(shell == null);
32 shell = shellProxy;
33 _application.initialize(args, url);
34 }
35
36 @override
37 void acceptConnection(String requestorUrl, ServiceProviderStub services,
38 bindings.ProxyBase exposedServices, String resolvedUrl) => _application
39 ._acceptConnection(requestorUrl, services, exposedServices, resolvedUrl);
40
41 @override
42 void requestQuit() => _application._requestQuitAndClose();
43
44 Future close({bool immediate: false}) {
45 if (shell != null) {
46 shell.close(immediate: immediate);
47 }
48 return _stub.close(immediate: immediate);
49 }
50 }
51
52 // TODO(zra): Better documentation and examples.
53 // To implement, do the following:
54 // - Optionally override initialize() to process command-line args.
55 // - Optionally override acceptConnection() if services are to be provided.
56 // - Optionally override close() to clean up application resources.
57 abstract class Application {
58 _ApplicationImpl _applicationImpl;
59 List<ApplicationConnection> _applicationConnections;
60 Function onError;
61
62 Application(core.MojoMessagePipeEndpoint endpoint) {
63 _applicationConnections = [];
64 _applicationImpl = new _ApplicationImpl(this, endpoint);
65 _applicationImpl.onError = _errorHandler;
66 }
67
68 Application.fromHandle(core.MojoHandle appHandle) {
69 _applicationConnections = [];
70 _applicationImpl = new _ApplicationImpl.fromHandle(this, appHandle);
71 _applicationImpl.onError = _errorHandler;
72 }
73
74 void initialize(List<String> args, String url) {}
75
76 // TODO(skydart): This is a temporary fix to allow sky application to consume
77 // mojo services. Do not use for any other purpose.
78 void initializeFromShellProxy(
79 shell_mojom.ShellProxy shellProxy, List<String> args, String url) =>
80 _applicationImpl.initialize(shellProxy, args, url);
81
82 // Returns a connection to the app at |url|.
83 ApplicationConnection connectToApplication(String url) {
84 var proxy = new ServiceProviderProxy.unbound();
85 var stub = new ServiceProviderStub.unbound();
86 _applicationImpl.shell.ptr.connectToApplication(url, proxy, stub);
87 var connection = new ApplicationConnection(stub, proxy);
88 _applicationConnections.add(connection);
89 return connection;
90 }
91
92 void connectToService(String url, bindings.ProxyBase proxy) {
93 connectToApplication(url).requestService(proxy);
94 }
95
96 void requestQuit() {}
97
98 void _requestQuitAndClose() {
99 requestQuit();
100 close();
101 }
102
103 void _errorHandler() {
104 close().then((_) {
105 if (onError != null) onError();
106 });
107 }
108
109 Future close({bool immediate: false}) {
110 assert(_applicationImpl != null);
111 _applicationConnections.forEach((c) => c.close(immediate: immediate));
112 _applicationConnections.clear();
113 return _applicationImpl.close(immediate: immediate);
114 }
115
116 // This method closes all the application connections. Used during apptesting.
117 void resetConnections() {
118 assert(_applicationImpl != null);
119 _applicationConnections.forEach((c) => c.close());
120 _applicationConnections.clear();
121 }
122
123 void _acceptConnection(String requestorUrl, ServiceProviderStub services,
124 ServiceProviderProxy exposedServices, String resolvedUrl) {
125 var connection = new ApplicationConnection(services, exposedServices);
126 _applicationConnections.add(connection);
127 acceptConnection(requestorUrl, resolvedUrl, connection);
128 }
129
130 // Override this method to provide services on |connection|.
131 void acceptConnection(String requestorUrl, String resolvedUrl,
132 ApplicationConnection connection) {}
133 }
OLDNEW
« no previous file with comments | « mojo/public/dart/rules.gni ('k') | mojo/public/dart/src/application_connection.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698