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

Unified Diff: pkg/dev_compiler/web/web_command.dart

Issue 2879843004: Add progress events for loading DDC summaries to make it clear to users whether loading a DDC appli… (Closed)
Patch Set: Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/dev_compiler/web/main.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
« no previous file with comments | « pkg/dev_compiler/web/main.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698