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 Future close({bool nodefer: false}) { | 44 Future close({bool immediate: false}) { |
45 if (shell != null) shell.close(); | 45 if (shell != null) { |
46 return _stub.close(); | 46 shell.close(immediate: immediate); |
| 47 } |
| 48 return _stub.close(immediate: immediate); |
47 } | 49 } |
48 } | 50 } |
49 | 51 |
50 // TODO(zra): Better documentation and examples. | 52 // TODO(zra): Better documentation and examples. |
51 // To implement, do the following: | 53 // To implement, do the following: |
52 // - Optionally override initialize() to process command-line args. | 54 // - Optionally override initialize() to process command-line args. |
53 // - Optionally override acceptConnection() if services are to be provided. | 55 // - Optionally override acceptConnection() if services are to be provided. |
54 // - Optionally override close() to clean up application resources. | 56 // - Optionally override close() to clean up application resources. |
55 abstract class Application { | 57 abstract class Application { |
56 _ApplicationImpl _applicationImpl; | 58 _ApplicationImpl _applicationImpl; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 requestQuit(); | 99 requestQuit(); |
98 close(); | 100 close(); |
99 } | 101 } |
100 | 102 |
101 void _errorHandler() { | 103 void _errorHandler() { |
102 close().then((_) { | 104 close().then((_) { |
103 if (onError != null) onError(); | 105 if (onError != null) onError(); |
104 }); | 106 }); |
105 } | 107 } |
106 | 108 |
107 Future close() { | 109 Future close({bool immediate: false}) { |
108 assert(_applicationImpl != null); | 110 assert(_applicationImpl != null); |
109 _applicationConnections.forEach((c) => c.close()); | 111 _applicationConnections.forEach((c) => c.close(immediate: immediate)); |
110 _applicationConnections.clear(); | 112 _applicationConnections.clear(); |
111 return _applicationImpl.close(); | 113 return _applicationImpl.close(immediate: immediate); |
112 } | 114 } |
113 | 115 |
114 // This method closes all the application connections. Used during apptesting. | 116 // This method closes all the application connections. Used during apptesting. |
115 void resetConnections() { | 117 void resetConnections() { |
116 assert(_applicationImpl != null); | 118 assert(_applicationImpl != null); |
117 _applicationConnections.forEach((c) => c.close()); | 119 _applicationConnections.forEach((c) => c.close()); |
118 _applicationConnections.clear(); | 120 _applicationConnections.clear(); |
119 } | 121 } |
120 | 122 |
121 void _acceptConnection(String requestorUrl, ServiceProviderStub services, | 123 void _acceptConnection(String requestorUrl, ServiceProviderStub services, |
122 ServiceProviderProxy exposedServices, String resolvedUrl) { | 124 ServiceProviderProxy exposedServices, String resolvedUrl) { |
123 var connection = new ApplicationConnection(services, exposedServices); | 125 var connection = new ApplicationConnection(services, exposedServices); |
124 _applicationConnections.add(connection); | 126 _applicationConnections.add(connection); |
125 acceptConnection(requestorUrl, resolvedUrl, connection); | 127 acceptConnection(requestorUrl, resolvedUrl, connection); |
126 } | 128 } |
127 | 129 |
128 // Override this method to provide services on |connection|. | 130 // Override this method to provide services on |connection|. |
129 void acceptConnection(String requestorUrl, String resolvedUrl, | 131 void acceptConnection(String requestorUrl, String resolvedUrl, |
130 ApplicationConnection connection) {} | 132 ApplicationConnection connection) {} |
131 } | 133 } |
OLD | NEW |