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

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

Issue 959993002: Dart: Removes name conflicts from generated 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 class _ApplicationImpl extends application_mojom.Application { 7 class _ApplicationImpl implements application_mojom.Application {
8 application_mojom.ApplicationStub _stub;
8 shell_mojom.ShellProxy shell; 9 shell_mojom.ShellProxy shell;
9 Application _application; 10 Application _application;
10 11
11 _ApplicationImpl( 12 _ApplicationImpl(Application application,
12 Application application, core.MojoMessagePipeEndpoint endpoint) 13 core.MojoMessagePipeEndpoint endpoint) {
13 : _application = application, super(endpoint) { 14 _application = application;
14 super.delegate = this; 15 _stub = new application_mojom.ApplicationStub.fromEndpoint(endpoint)
16 ..delegate = this
17 ..listen();
15 } 18 }
16 19
17 _ApplicationImpl.fromHandle(Application application, core.MojoHandle handle) 20 _ApplicationImpl.fromHandle(Application application, core.MojoHandle handle) {
18 : _application = application, super.fromHandle(handle) { 21 _application = application;
19 super.delegate = this; 22 _stub = new application_mojom.ApplicationStub.fromHandle(handle)
23 ..delegate = this
24 ..listen();
20 } 25 }
21 26
22 void initialize( 27 void initialize(bindings.Proxy shellProxy, List<String> args, String url) {
23 shell_mojom.ShellProxy shellProxy, List<String> args, String url) {
24 assert(shell == null); 28 assert(shell == null);
25 shell = shellProxy; 29 shell = new shell_mojom.ShellProxy(shellProxy);
26 _application.initialize(args, url); 30 _application.initialize(args, url);
27 } 31 }
28 32
29 void acceptConnection( 33 void acceptConnection(String requestorUrl,
30 String requestorUrl, 34 ServiceProviderStub services,
31 ServiceProviderStub services, 35 bindings.Proxy exposedServices) {
32 ServiceProviderProxy exposedServices) => 36 var serviceProviderProxy = exposedServices == null
33 _application._acceptConnection(requestorUrl, services, exposedServices); 37 ? null : new ServiceProviderProxy(exposedServices);
38 _application._acceptConnection(
39 requestorUrl, services, serviceProviderProxy);
40 }
34 41
35 void requestQuit() => _application._requestQuitAndClose(); 42 void requestQuit() => _application._requestQuitAndClose();
36 43
37 void close({bool nodefer: false}) => shell.close(); 44 void close({bool nodefer: false}) =>
45 shell_mojom.ShellProxyClose(shell);
38 } 46 }
39 47
40 // TODO(zra): Better documentation and examples. 48 // TODO(zra): Better documentation and examples.
41 // To implement, do the following: 49 // To implement, do the following:
42 // - Optionally override initialize() to process command-line args. 50 // - Optionally override initialize() to process command-line args.
43 // - Optionally override acceptConnection() if services are to be provided. 51 // - Optionally override acceptConnection() if services are to be provided.
44 // - Optionally override close() to clean up application resources. 52 // - Optionally override close() to clean up application resources.
45 abstract class Application { 53 abstract class Application {
46 _ApplicationImpl _applicationImpl; 54 _ApplicationImpl _applicationImpl;
47 List<ApplicationConnection> _applicationConnections; 55 List<ApplicationConnection> _applicationConnections;
48 56
49 Application(core.MojoMessagePipeEndpoint endpoint) { 57 Application(core.MojoMessagePipeEndpoint endpoint) {
50 _applicationConnections = []; 58 _applicationConnections = [];
51 _applicationImpl = new _ApplicationImpl(this, endpoint); 59 _applicationImpl = new _ApplicationImpl(this, endpoint);
52 } 60 }
53 61
54 Application.fromHandle(core.MojoHandle appHandle) { 62 Application.fromHandle(core.MojoHandle appHandle) {
55 _applicationConnections = []; 63 _applicationConnections = [];
56 _applicationImpl = new _ApplicationImpl.fromHandle(this, appHandle); 64 _applicationImpl = new _ApplicationImpl.fromHandle(this, appHandle);
57 } 65 }
58 66
59 void initialize(List<String> args, String url) {} 67 void initialize(List<String> args, String url) {}
60 68
61 // 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
62 // mojo services. Do not use for any other purpose. 70 // mojo services. Do not use for any other purpose.
63 void initializeFromShellProxy(shell_mojom.ShellProxy shellProxy, 71 void initializeFromShellProxy(shell_mojom.ShellProxy shellProxy,
64 List<String> args, String url) { 72 List<String> args, String url) {
65 _applicationImpl.initialize(shellProxy, args, url); 73 _applicationImpl.initialize(
74 shell_mojom.ShellGetProxyImpl(shellProxy), args, url);
66 } 75 }
67 76
68 // Returns a connection to the app at |url|. 77 // Returns a connection to the app at |url|.
69 ApplicationConnection connectToApplication(String url) { 78 ApplicationConnection connectToApplication(String url) {
70 var proxy = new ServiceProviderProxy.unbound(); 79 var proxy = new ServiceProviderProxy.unbound();
71 var stub = new ServiceProviderStub.unbound(); 80 var stub = new ServiceProviderStub.unbound();
72 _applicationImpl.shell.connectToApplication(url, proxy, stub); 81 _applicationImpl.shell.connectToApplication(
82 url, ServiceProviderRequest(proxy), stub);
73 var connection = new ApplicationConnection(stub, proxy); 83 var connection = new ApplicationConnection(stub, proxy);
74 _applicationConnections.add(connection); 84 _applicationConnections.add(connection);
75 return connection; 85 return connection;
76 } 86 }
77 87
78 void connectToService(String url, bindings.Proxy proxy) { 88 void connectToService(String url, bindings.Proxy proxy) {
79 connectToApplication(url).requestService(proxy); 89 connectToApplication(url).requestService(proxy);
80 } 90 }
81 91
82 void requestQuit() {} 92 void requestQuit() {}
83 93
84 listen() => _applicationImpl.listen();
85
86 void _requestQuitAndClose() { 94 void _requestQuitAndClose() {
87 requestQuit(); 95 requestQuit();
88 close(); 96 close();
89 } 97 }
90 98
91 void close() { 99 void close() {
92 assert(_applicationImpl != null); 100 assert(_applicationImpl != null);
93 _applicationConnections.forEach((c) => c.close()); 101 _applicationConnections.forEach((c) => c.close());
94 _applicationConnections.clear(); 102 _applicationConnections.clear();
95 _applicationImpl.close(); 103 _applicationImpl.close();
96 } 104 }
97 105
98 void _acceptConnection( 106 void _acceptConnection(
99 String requestorUrl, 107 String requestorUrl,
100 ServiceProviderStub services, 108 ServiceProviderStub services,
101 ServiceProviderProxy exposedServices) { 109 ServiceProviderProxy exposedServices) {
102 var connection = new ApplicationConnection(services, exposedServices); 110 var connection = new ApplicationConnection(services, exposedServices);
103 _applicationConnections.add(connection); 111 _applicationConnections.add(connection);
104 acceptConnection(requestorUrl, connection); 112 acceptConnection(requestorUrl, connection);
105 } 113 }
106 114
107 // Override this method to provide services on |connection|. 115 // Override this method to provide services on |connection|.
108 // If you provide at least one service or set fallbackServiceProvider, 116 // If you provide at least one service or set fallbackServiceProvider,
109 // then you must invoke connection.listen(). 117 // then you must invoke connection.listen().
110 void acceptConnection(String requestorUrl, ApplicationConnection connection) { 118 void acceptConnection(String requestorUrl, ApplicationConnection connection) {
111 } 119 }
112 } 120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698