Skip to content

Commit a8f6f44

Browse files
authored
Update engine to include new version of Mojo (#4668)
This required switching from the Future-based bindings to the callback-based bindings.
1 parent f307735 commit a8f6f44

14 files changed

Lines changed: 153 additions & 122 deletions

File tree

‎bin/cache/engine.version‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e0ae976409ccbf25e8e26d66c4575d081fc2abdf
1+
f91f5ad62f7a61de787e3e6397f0b63e9eab534e

‎examples/layers/services/media_service.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class PianoKey {
4242
Future<Null> load(mojom.MediaServiceProxy mediaService) async {
4343
try {
4444
mediaService.createPlayer(player);
45-
await player.prepare(await http.readDataPipe(soundUrl));
45+
player.prepare(await http.readDataPipe(soundUrl), (bool ignored) { });
4646
} catch (e) {
4747
print("Error: failed to load sound file $soundUrl");
4848
player.close();

‎packages/flutter/lib/src/http/mojo_client.dart‎

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -130,28 +130,26 @@ class MojoClient {
130130
///
131131
/// The Future will emit a [ClientException] if the response doesn't have a
132132
/// success status code.
133-
Future<mojo.MojoDataPipeConsumer> readDataPipe(dynamic url, { Map<String, String> headers }) async {
133+
Future<mojo.MojoDataPipeConsumer> readDataPipe(dynamic url, { Map<String, String> headers }) {
134+
Completer<mojo.MojoDataPipeConsumer> completer = new Completer<mojo.MojoDataPipeConsumer>();
134135
mojom.UrlLoaderProxy loader = new mojom.UrlLoaderProxy.unbound();
135-
mojom.UrlRequest request = _prepareRequest('GET', url, headers);
136-
mojom.UrlResponse response;
137-
try {
138-
networkService.createUrlLoader(loader);
139-
response = (await loader.start(request)).response;
140-
} catch (exception, stack) {
141-
FlutterError.reportError(new FlutterErrorDetails(
142-
exception: exception,
143-
stack: stack,
144-
library: 'networking HTTP library',
145-
context: 'while sending bytes to the Mojo network library',
146-
silent: true
147-
));
148-
return null;
149-
} finally {
136+
networkService.createUrlLoader(loader);
137+
loader.start(_prepareRequest('GET', url, headers), (mojom.UrlResponse response) {
150138
loader.close();
151-
}
152-
if (response.statusCode < 400)
153-
return response.body;
154-
throw new Exception("Request to $url failed with status ${response.statusCode}.");
139+
if (response.statusCode < 400) {
140+
completer.complete(response.body);
141+
} else {
142+
Exception exception = new Exception("Request to $url failed with status ${response.statusCode}.");
143+
FlutterError.reportError(new FlutterErrorDetails(
144+
exception: exception,
145+
library: 'networking HTTP library',
146+
context: 'while sending bytes to the Mojo network library',
147+
silent: true
148+
));
149+
completer.completeError(exception);
150+
}
151+
});
152+
return completer.future;
155153
}
156154

157155
mojom.UrlRequest _prepareRequest(String method, dynamic url, Map<String, String> headers, [dynamic body, Encoding encoding = UTF8]) {
@@ -177,35 +175,37 @@ class MojoClient {
177175
return request;
178176
}
179177

180-
Future<Response> _send(String method, dynamic url, Map<String, String> headers, [dynamic body, Encoding encoding = UTF8]) async {
178+
Future<Response> _send(String method, dynamic url, Map<String, String> headers, [dynamic body, Encoding encoding = UTF8]) {
179+
Completer<Response> completer = new Completer<Response>();
181180
mojom.UrlLoaderProxy loader = new mojom.UrlLoaderProxy.unbound();
181+
networkService.createUrlLoader(loader);
182182
mojom.UrlRequest request = _prepareRequest(method, url, headers, body, encoding);
183-
try {
184-
networkService.createUrlLoader(loader);
185-
mojom.UrlResponse response = (await loader.start(request)).response;
186-
ByteData data = await mojo.DataPipeDrainer.drainHandle(response.body);
187-
Uint8List bodyBytes = new Uint8List.view(data.buffer);
188-
Map<String, String> headers = <String, String>{};
189-
if (response.headers != null) {
190-
for (mojom.HttpHeader header in response.headers) {
191-
String headerName = header.name.toLowerCase();
192-
String existingValue = headers[headerName];
193-
headers[headerName] = existingValue != null ? '$existingValue, ${header.value}' : header.value;
183+
loader.start(request, (mojom.UrlResponse response) async {
184+
loader.close();
185+
try {
186+
ByteData data = await mojo.DataPipeDrainer.drainHandle(response.body);
187+
Uint8List bodyBytes = new Uint8List.view(data.buffer);
188+
Map<String, String> headers = <String, String>{};
189+
if (response.headers != null) {
190+
for (mojom.HttpHeader header in response.headers) {
191+
String headerName = header.name.toLowerCase();
192+
String existingValue = headers[headerName];
193+
headers[headerName] = existingValue != null ? '$existingValue, ${header.value}' : header.value;
194+
}
194195
}
196+
completer.complete(new Response.bytes(bodyBytes, response.statusCode, headers: headers));
197+
} catch (exception, stack) {
198+
FlutterError.reportError(new FlutterErrorDetails(
199+
exception: exception,
200+
stack: stack,
201+
library: 'networking HTTP library',
202+
context: 'while sending bytes to the Mojo network library',
203+
silent: true
204+
));
205+
completer.complete(new Response.bytes(null, 500));
195206
}
196-
return new Response.bytes(bodyBytes, response.statusCode, headers: headers);
197-
} catch (exception, stack) {
198-
FlutterError.reportError(new FlutterErrorDetails(
199-
exception: exception,
200-
stack: stack,
201-
library: 'networking HTTP library',
202-
context: 'while sending bytes to the Mojo network library',
203-
silent: true
204-
));
205-
return new Response.bytes(null, 500);
206-
} finally {
207-
loader.close();
208-
}
207+
});
208+
return completer.future;
209209
}
210210

211211
void _checkResponseSuccess(dynamic url, Response response) {

‎packages/flutter/lib/src/rendering/child_view.dart‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,10 @@ class ChildViewConnection {
7979
url, mojom.ViewProvider.connectToService
8080
);
8181
mojom.ServiceProviderProxy incomingServices = new mojom.ServiceProviderProxy.unbound();
82-
mojom.ServiceProviderStub outgoingServices = new mojom.ServiceProviderStub.unbound();
8382
_viewOwner = new mojom.ViewOwnerProxy.unbound();
84-
viewProvider.createView(_viewOwner, incomingServices, outgoingServices);
83+
viewProvider.createView(_viewOwner, incomingServices);
8584
viewProvider.close();
86-
_connection = new ApplicationConnection(outgoingServices, incomingServices);
85+
_connection = new ApplicationConnection(null, incomingServices);
8786
}
8887

8988
/// Wraps an already-established connection to a child app.

‎packages/flutter/lib/src/services/asset_bundle.dart‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,12 @@ class MojoAssetBundle extends CachingAssetBundle {
180180
mojom.AssetBundleProxy _bundle;
181181

182182
@override
183-
Future<core.MojoDataPipeConsumer> load(String key) async {
184-
return (await _bundle.getAsStream(key)).assetData;
183+
Future<core.MojoDataPipeConsumer> load(String key) {
184+
Completer<core.MojoDataPipeConsumer> completer = new Completer<core.MojoDataPipeConsumer>();
185+
_bundle.getAsStream(key, (core.MojoDataPipeConsumer assetData) {
186+
completer.complete(assetData);
187+
});
188+
return completer.future;
185189
}
186190
}
187191

‎packages/flutter/lib/src/services/clipboard.dart‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ class Clipboard {
3131
/// Retrieves data from the clipboard that matches the given format.
3232
///
3333
/// * `format` is a media type, such as `text/plain`.
34-
static Future<mojom.ClipboardData> getClipboardData(String format) async {
35-
return (await _clipboardProxy.getClipboardData(format)).clip;
34+
static Future<mojom.ClipboardData> getClipboardData(String format) {
35+
Completer<mojom.ClipboardData> completer = new Completer<mojom.ClipboardData>();
36+
_clipboardProxy.getClipboardData(format, (mojom.ClipboardData clip) {
37+
completer.complete(clip);
38+
});
39+
return completer.future;
3640
}
3741
}

‎packages/flutter/lib/src/services/haptic_feedback.dart‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ class HapticFeedback {
3636
/// was successfully conveyed to the embedder. There may not be any actual
3737
/// feedback if the device does not have a vibrator or one is disabled in
3838
/// system settings.
39-
static Future<bool> vibrate() async {
40-
return (await _hapticFeedbackProxy.vibrate()).success;
39+
static Future<bool> vibrate() {
40+
Completer<bool> completer = new Completer<bool>();
41+
_hapticFeedbackProxy.vibrate((bool result) {
42+
completer.complete(result);
43+
});
44+
return completer.future;
4145
}
4246
}

‎packages/flutter/lib/src/services/host_messages.dart‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,21 @@ final _ApplicationMessagesImpl _appMessages = new _ApplicationMessagesImpl();
4949
/// Flutter framework to exchange application-specific messages.
5050
class HostMessages {
5151
/// Send a message to the host application.
52-
static Future<String> sendToHost(String messageName, [String message = '']) async {
53-
return (await _hostAppMessagesProxy.sendString(messageName, message)).reply;
52+
static Future<String> sendToHost(String messageName, [String message = '']) {
53+
Completer<String> completer = new Completer<String>();
54+
_hostAppMessagesProxy.sendString(messageName, message, (String reply) {
55+
completer.complete(reply);
56+
});
57+
return completer.future;
5458
}
5559

5660
/// Sends a JSON-encoded message to the host application and JSON-decodes the response.
5761
static Future<dynamic> sendJSON(String messageName, [dynamic json]) async {
58-
return JSON.decode((await _hostAppMessagesProxy.sendString(messageName, JSON.encode(json))).reply);
62+
Completer<dynamic> completer = new Completer<dynamic>();
63+
_hostAppMessagesProxy.sendString(messageName, JSON.encode(json), (String reply) {
64+
completer.complete(JSON.decode(reply));
65+
});
66+
return completer.future;
5967
}
6068

6169
/// Register a callback for receiving messages from the host application.

‎packages/flutter/lib/src/services/path_provider.dart‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ class PathProvider {
2929
///
3030
/// * _iOS_: `NSTemporaryDirectory()`
3131
/// * _Android_: `getCacheDir()` on the context.
32-
static Future<Directory> getTemporaryDirectory() async {
33-
return new Directory((await _pathProviderProxy.temporaryDirectory()).path);
32+
static Future<Directory> getTemporaryDirectory() {
33+
Completer<Directory> completer = new Completer<Directory>();
34+
_pathProviderProxy.temporaryDirectory((String path) {
35+
completer.complete(new Directory(path));
36+
});
37+
return completer.future;
3438
}
3539

3640
/// Path to a directory where the application may place files that are private
@@ -41,7 +45,11 @@ class PathProvider {
4145
///
4246
/// * _iOS_: `NSDocumentsDirectory`
4347
/// * _Android_: The AppData directory.
44-
static Future<Directory> getApplicationDocumentsDirectory() async {
45-
return new Directory((await _pathProviderProxy.applicationDocumentsDirectory()).path);
48+
static Future<Directory> getApplicationDocumentsDirectory() {
49+
Completer<Directory> completer = new Completer<Directory>();
50+
_pathProviderProxy.applicationDocumentsDirectory((String path) {
51+
completer.complete(new Directory(path));
52+
});
53+
return completer.future;
4654
}
4755
}

‎packages/flutter/lib/src/services/shell.dart‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class _ShellServiceConnector extends bindings.ServiceConnector {
6464
return;
6565
}
6666
mojom.ServiceProviderProxy services = new mojom.ServiceProviderProxy.unbound();
67-
instance._shell.connectToApplication(url, services, null);
67+
instance._shell.connectToApplication(url, services);
6868
core.MojoMessagePipe pipe = new core.MojoMessagePipe();
6969
proxy.ctrl.bind(pipe.endpoints[0]);
7070
services.connectToService_(serviceName, pipe.endpoints[1]);
@@ -116,9 +116,8 @@ class MojoShell {
116116
if (_shell == null)
117117
return null;
118118
mojom.ServiceProviderProxy services = new mojom.ServiceProviderProxy.unbound();
119-
mojom.ServiceProviderStub exposedServices = new mojom.ServiceProviderStub.unbound();
120-
_shell.connectToApplication(url, services, exposedServices);
121-
return new ApplicationConnection(exposedServices, services);
119+
_shell.connectToApplication(url, services);
120+
return new ApplicationConnection(null, services);
122121
}
123122

124123
/// Interceptor for calls to [connectToService] and

0 commit comments

Comments
 (0)