Chromium Code Reviews| Index: pkg/dev_compiler/web/web_command.dart |
| diff --git a/pkg/dev_compiler/web/web_command.dart b/pkg/dev_compiler/web/web_command.dart |
| index 6ddda879637de5d7cc2df3fc4d0039a4bf0536f0..cac9be8f6055172a170215d4543ccf58f30dfe14 100644 |
| --- a/pkg/dev_compiler/web/web_command.dart |
| +++ b/pkg/dev_compiler/web/web_command.dart |
| @@ -6,6 +6,7 @@ library dev_compiler.web.web_command; |
| import 'dart:async'; |
| import 'dart:convert'; |
| +import 'dart:math' as math; |
| import 'dart:html' show HttpRequest; |
| import 'dart:typed_data'; |
| @@ -46,6 +47,7 @@ class JSMap<K, V> { |
| external set(K k, V v); |
| external JSIterator<K> keys(); |
| external JSIterator<V> values(); |
| + external int get size; |
| } |
| @JS('Array.from') |
| @@ -80,8 +82,23 @@ class WebCompileCommand extends Command { |
| } |
| Future<Null> requestSummaries(String sdkUrl, JSMap<String, String> summaryMap, |
| - Function onCompileReady, Function onError) async { |
| + Function onCompileReady, Function onError, Function onProgress) async { |
| var sdkRequest; |
| + var progress = 0; |
| + int lastReported = 0; |
| + // Add 1 to the count for the SDK summary. |
| + var total = summaryMap.size + 1; |
| + // No need to report after every summary is loaded. Posting about 100 |
| + // progress updates should be more than sufficient for users to understand |
| + // how long loading will take. |
| + num progressDelta = math.max(total / 100, 1); |
| + num nextProgressToReport = 0; |
| + maybeReportProgress() { |
| + if (nextProgressToReport > progress && progress != total) return; |
| + nextProgressToReport += progressDelta; |
| + if (onProgress != null) onProgress(progress, total); |
| + } |
| + |
| try { |
| sdkRequest = await HttpRequest.request(sdkUrl, |
| responseType: "arraybuffer", mimeType: "application/octet-stream"); |
| @@ -89,14 +106,21 @@ class WebCompileCommand extends Command { |
| onError('Dart sdk summaries failed to load: $error. url: $sdkUrl'); |
| return null; |
| } |
| + progress++; |
| + maybeReportProgress(); |
| var sdkBytes = (sdkRequest.response as ByteBuffer).asUint8List(); |
| // Map summary URLs to HttpRequests. |
| - var summaryRequests = iteratorToList(summaryMap.values()) |
| - .map((String summaryUrl) => HttpRequest.request(summaryUrl, |
| - responseType: "arraybuffer", mimeType: "application/octet-stream")) |
| - .toList(); |
| + |
| + var summaryRequests = |
| + iteratorToList(summaryMap.values()).map((String summaryUrl) async { |
| + var ret = await HttpRequest.request(summaryUrl, |
|
Alan Knight
2017/05/13 00:22:41
Style guide frowns on abbreviations and non-meanin
|
| + responseType: "arraybuffer", mimeType: "application/octet-stream"); |
| + progress++; |
| + maybeReportProgress(); |
| + return ret; |
| + }).toList(); |
| try { |
| var summaryResponses = await Future.wait(summaryRequests); |
| // Map summary responses to summary bytes. |