OLD | NEW |
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; |
(...skipping 23 matching lines...) Expand all Loading... |
34 } | 34 } |
35 | 35 |
36 @override | 36 @override |
37 void acceptConnection(String requestorUrl, ServiceProviderStub services, | 37 void acceptConnection(String requestorUrl, ServiceProviderStub services, |
38 bindings.ProxyBase exposedServices, String resolvedUrl) => _application | 38 bindings.ProxyBase exposedServices, String resolvedUrl) => _application |
39 ._acceptConnection(requestorUrl, services, exposedServices, resolvedUrl); | 39 ._acceptConnection(requestorUrl, services, exposedServices, resolvedUrl); |
40 | 40 |
41 @override | 41 @override |
42 void requestQuit() => _application._requestQuitAndClose(); | 42 void requestQuit() => _application._requestQuitAndClose(); |
43 | 43 |
44 void close({bool nodefer: false}) { | 44 Future close({bool nodefer: false}) { |
45 if (shell != null) shell.close(); | 45 if (shell != null) shell.close(); |
46 _stub.close(); | 46 return _stub.close(); |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 // TODO(zra): Better documentation and examples. | 50 // TODO(zra): Better documentation and examples. |
51 // To implement, do the following: | 51 // To implement, do the following: |
52 // - Optionally override initialize() to process command-line args. | 52 // - Optionally override initialize() to process command-line args. |
53 // - Optionally override acceptConnection() if services are to be provided. | 53 // - Optionally override acceptConnection() if services are to be provided. |
54 // - Optionally override close() to clean up application resources. | 54 // - Optionally override close() to clean up application resources. |
55 abstract class Application { | 55 abstract class Application { |
56 _ApplicationImpl _applicationImpl; | 56 _ApplicationImpl _applicationImpl; |
57 List<ApplicationConnection> _applicationConnections; | 57 List<ApplicationConnection> _applicationConnections; |
| 58 Function onError; |
58 | 59 |
59 Application(core.MojoMessagePipeEndpoint endpoint) { | 60 Application(core.MojoMessagePipeEndpoint endpoint) { |
60 _applicationConnections = []; | 61 _applicationConnections = []; |
61 _applicationImpl = new _ApplicationImpl(this, endpoint); | 62 _applicationImpl = new _ApplicationImpl(this, endpoint); |
62 _applicationImpl.onError = close; | 63 _applicationImpl.onError = _errorHandler; |
63 } | 64 } |
64 | 65 |
65 Application.fromHandle(core.MojoHandle appHandle) { | 66 Application.fromHandle(core.MojoHandle appHandle) { |
66 _applicationConnections = []; | 67 _applicationConnections = []; |
67 _applicationImpl = new _ApplicationImpl.fromHandle(this, appHandle); | 68 _applicationImpl = new _ApplicationImpl.fromHandle(this, appHandle); |
68 _applicationImpl.onError = close; | 69 _applicationImpl.onError = _errorHandler; |
69 } | 70 } |
70 | 71 |
71 void initialize(List<String> args, String url) {} | 72 void initialize(List<String> args, String url) {} |
72 | 73 |
73 // TODO(skydart): This is a temporary fix to allow sky application to consume | 74 // TODO(skydart): This is a temporary fix to allow sky application to consume |
74 // mojo services. Do not use for any other purpose. | 75 // mojo services. Do not use for any other purpose. |
75 void initializeFromShellProxy( | 76 void initializeFromShellProxy( |
76 shell_mojom.ShellProxy shellProxy, List<String> args, String url) => | 77 shell_mojom.ShellProxy shellProxy, List<String> args, String url) => |
77 _applicationImpl.initialize(shellProxy, args, url); | 78 _applicationImpl.initialize(shellProxy, args, url); |
78 | 79 |
(...skipping 11 matching lines...) Expand all Loading... |
90 connectToApplication(url).requestService(proxy); | 91 connectToApplication(url).requestService(proxy); |
91 } | 92 } |
92 | 93 |
93 void requestQuit() {} | 94 void requestQuit() {} |
94 | 95 |
95 void _requestQuitAndClose() { | 96 void _requestQuitAndClose() { |
96 requestQuit(); | 97 requestQuit(); |
97 close(); | 98 close(); |
98 } | 99 } |
99 | 100 |
100 void close() { | 101 void _errorHandler() { |
| 102 close().then((_) { |
| 103 if (onError != null) onError(); |
| 104 }); |
| 105 } |
| 106 |
| 107 Future close() { |
101 assert(_applicationImpl != null); | 108 assert(_applicationImpl != null); |
102 _applicationConnections.forEach((c) => c.close()); | 109 _applicationConnections.forEach((c) => c.close()); |
103 _applicationConnections.clear(); | 110 _applicationConnections.clear(); |
104 _applicationImpl.close(); | 111 return _applicationImpl.close(); |
105 } | 112 } |
106 | 113 |
107 // This method closes all the application connections. Used during apptesting. | 114 // This method closes all the application connections. Used during apptesting. |
108 void resetConnections() { | 115 void resetConnections() { |
109 assert(_applicationImpl != null); | 116 assert(_applicationImpl != null); |
110 _applicationConnections.forEach((c) => c.close()); | 117 _applicationConnections.forEach((c) => c.close()); |
111 _applicationConnections.clear(); | 118 _applicationConnections.clear(); |
112 } | 119 } |
113 | 120 |
114 void _acceptConnection(String requestorUrl, ServiceProviderStub services, | 121 void _acceptConnection(String requestorUrl, ServiceProviderStub services, |
115 ServiceProviderProxy exposedServices, String resolvedUrl) { | 122 ServiceProviderProxy exposedServices, String resolvedUrl) { |
116 var connection = new ApplicationConnection(services, exposedServices); | 123 var connection = new ApplicationConnection(services, exposedServices); |
117 _applicationConnections.add(connection); | 124 _applicationConnections.add(connection); |
118 acceptConnection(requestorUrl, resolvedUrl, connection); | 125 acceptConnection(requestorUrl, resolvedUrl, connection); |
119 } | 126 } |
120 | 127 |
121 // Override this method to provide services on |connection|. | 128 // Override this method to provide services on |connection|. |
122 void acceptConnection(String requestorUrl, String resolvedUrl, | 129 void acceptConnection(String requestorUrl, String resolvedUrl, |
123 ApplicationConnection connection) {} | 130 ApplicationConnection connection) {} |
124 } | 131 } |
OLD | NEW |