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

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

Powered by Google App Engine
This is Rietveld 408576698