[roll] Update third-party dart packages

Roller-URL: https://ci.chromium.org/b/8792245257472776353
Roller-Owners: flutter-on-fuchsia-team@google.com, godofredoc@google.com
CQ-Do-Not-Cancel-Tryjobs: true
Change-Id: I4b733f1655d9cfd93d8fc527b4e5dc13ef2d109c
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/dart-pkg/+/788364
Commit-Queue: GI Roller <global-integration-roller@fuchsia-infra.iam.gserviceaccount.com>
diff --git a/dds/BUILD.gn b/dds/BUILD.gn
index f5de0d5..484c36a 100644
--- a/dds/BUILD.gn
+++ b/dds/BUILD.gn
@@ -1,4 +1,4 @@
-# This file is generated by package_importer.py for dds-2.6.0
+# This file is generated by package_importer.py for dds-2.7.0
 
 import("//build/dart/dart_library.gni")
 
diff --git a/dds/CHANGELOG.md b/dds/CHANGELOG.md
index b8dd8a5..282dd5c 100644
--- a/dds/CHANGELOG.md
+++ b/dds/CHANGELOG.md
@@ -1,3 +1,9 @@
+# 2.7.0
+- Added `DartDevelopmentService.setExternalDevToolsUri(Uri uri)`, adding support for registering an external DevTools server with DDS.
+
+# 2.6.1
+- [DAP] Fix a crash handling errors when fetching full strings in evaluation and logging events.
+
 # 2.6.0
 - Add support for registering and subscribing to custom service streams.
 - [DAP] Supplying incorrect types of arguments in `launch`/`attach` requests will now result in a clear error message in an error response instead of terminating the adapter.
diff --git a/dds/lib/dds.dart b/dds/lib/dds.dart
index 177a926..03cbbf4 100644
--- a/dds/lib/dds.dart
+++ b/dds/lib/dds.dart
@@ -103,6 +103,13 @@
   /// Stop accepting requests after gracefully handling existing requests.
   Future<void> shutdown();
 
+  /// Registers an external DevTools server with this instance of
+  /// [DartDevelopmentService] to allow for DDS to redirect DevTools requests
+  /// to the DevTools server.
+  ///
+  /// Throws a [StateError] if DevTools is already being served by DDS.
+  void setExternalDevToolsUri(Uri uri);
+
   /// Set to `true` if this instance of [DartDevelopmentService] requires an
   /// authentication code to connect.
   bool get authCodesEnabled;
diff --git a/dds/lib/src/dap/adapters/dart.dart b/dds/lib/src/dap/adapters/dart.dart
index 985f089..40d22b1 100644
--- a/dds/lib/src/dap/adapters/dart.dart
+++ b/dds/lib/src/dap/adapters/dart.dart
@@ -1610,16 +1610,6 @@
     sendResponse(ThreadsResponseBody(threads: threads));
   }
 
-  /// Sets the package config file to use for `package: URI` resolution.
-  ///
-  /// It is no longer necessary to call this method as the package config file
-  /// is no longer used. URI lookups are done via the VM Service.
-  @Deprecated('No longer necessary, URI lookups are done via VM Service')
-  void usePackageConfigFile(File packageConfig) {
-    // TODO(dantup): Remove this method after Flutter DA is updated not to use
-    // it.
-  }
-
   /// [variablesRequest] is called by the client to request child variables for
   /// a given variables variablesReference.
   ///
@@ -1977,15 +1967,17 @@
       allowTruncatedValue: false,
       includeQuotesAroundString: false,
     )
-        // TODO: Fix this static error.
-        // ignore: body_might_complete_normally_catch_error
-        .catchError((e) {
-      // Fetching strings from the server may throw if they have been
-      // collected since (for example if a Hot Restart occurs while
-      // we're running this). Log the error and just return null so
-      // nothing is shown.
-      logger?.call('$e');
-    });
+        // Fetching strings from the server may throw if they have been
+        // collected since (for example if a Hot Restart occurs while
+        // we're running this) or if the app is terminating. Log the error and
+        // just return null so nothing is shown.
+        .then<String?>(
+      (s) => s,
+      onError: (Object e) {
+        logger?.call('$e');
+        return null;
+      },
+    );
   }
 
   /// Handles a dart:developer log() event, sending output to the client.
diff --git a/dds/lib/src/dds_impl.dart b/dds/lib/src/dds_impl.dart
index 33be98f..c6d6067 100644
--- a/dds/lib/src/dds_impl.dart
+++ b/dds/lib/src/dds_impl.dart
@@ -320,18 +320,41 @@
   }
 
   Handler _httpHandler() {
+    final notFoundHandler = proxyHandler(remoteVmServiceUri);
+
+    // If DDS is serving DevTools, install the DevTools handlers and forward
+    // any unhandled HTTP requests to the VM service.
     if (_devToolsConfiguration != null && _devToolsConfiguration!.enable) {
-      // Install the DevTools handlers and forward any unhandled HTTP requests to
-      // the VM service.
       final String buildDir =
           _devToolsConfiguration!.customBuildDirectoryPath.toFilePath();
       return defaultHandler(
         dds: this,
         buildDir: buildDir,
-        notFoundHandler: proxyHandler(remoteVmServiceUri),
+        notFoundHandler: notFoundHandler,
       ) as FutureOr<Response> Function(Request);
     }
-    return proxyHandler(remoteVmServiceUri);
+
+    // Otherwise, DevTools may be served externally, or not at all.
+    return (Request request) {
+      final pathSegments = request.url.pathSegments;
+      if (pathSegments.isEmpty || pathSegments.first != 'devtools') {
+        // Not a DevTools request, forward to the VM service.
+        return notFoundHandler(request);
+      } else {
+        if (_devToolsUri == null) {
+          // DevTools is not being served externally.
+          return Response.notFound(
+            'No DevTools instance is registered with the Dart Development Service (DDS).',
+          );
+        }
+        // Redirect to the external DevTools server.
+        return Response.seeOther(
+          _devToolsUri!.replace(
+            queryParameters: request.requestedUri.queryParameters,
+          ),
+        );
+      }
+    };
   }
 
   List<String> _cleanupPathSegments(Uri uri) {
@@ -365,7 +388,8 @@
     return uri.replace(scheme: 'sse', pathSegments: pathSegments);
   }
 
-  Uri? _toDevTools(Uri? uri) {
+  @visibleForTesting
+  Uri? toDevTools(Uri? uri) {
     // The DevTools URI is a bit strange as the query parameters appear after
     // the fragment. There's no nice way to encode the query parameters
     // properly, so we create another Uri just to grab the formatted query.
@@ -419,8 +443,20 @@
   Uri? get wsUri => _toWebSocket(_uri);
 
   @override
-  Uri? get devToolsUri =>
-      _devToolsConfiguration?.enable ?? false ? _toDevTools(_uri) : null;
+  Uri? get devToolsUri {
+    _devToolsUri ??=
+        _devToolsConfiguration?.enable ?? false ? toDevTools(_uri) : null;
+    return _devToolsUri;
+  }
+
+  void setExternalDevToolsUri(Uri uri) {
+    if (_devToolsConfiguration?.enable ?? false) {
+      throw StateError('A hosted DevTools instance is already being served.');
+    }
+    _devToolsUri = uri;
+  }
+
+  Uri? _devToolsUri;
 
   final bool _ipv6;
 
diff --git a/dds/pubspec.yaml b/dds/pubspec.yaml
index 61febf3..ff75532 100644
--- a/dds/pubspec.yaml
+++ b/dds/pubspec.yaml
@@ -1,5 +1,5 @@
 name: dds
-version: 2.6.0
+version: 2.7.0
 description: >-
   A library used to spawn the Dart Developer Service, used to communicate with
   a Dart VM Service instance.
diff --git a/dwds/BUILD.gn b/dwds/BUILD.gn
index 469e418..60e44d8 100644
--- a/dwds/BUILD.gn
+++ b/dwds/BUILD.gn
@@ -1,4 +1,4 @@
-# This file is generated by package_importer.py for dwds-16.0.1
+# This file is generated by package_importer.py for dwds-16.0.2
 
 import("//build/dart/dart_library.gni")
 
diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md
index 4de87b5..f1cb02f 100644
--- a/dwds/CHANGELOG.md
+++ b/dwds/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 16.0.2
+- Don't complete an already completed `Completer` in `ChromeProxyService` to fix
+  Flutter tools crash: https://github.com/dart-lang/webdev/pull/1862
+
 ## 16.0.1
 
 - Allow the following API to return `null` and add error handling:
diff --git a/dwds/lib/src/services/chrome_proxy_service.dart b/dwds/lib/src/services/chrome_proxy_service.dart
index daf4237..01d9cba 100644
--- a/dwds/lib/src/services/chrome_proxy_service.dart
+++ b/dwds/lib/src/services/chrome_proxy_service.dart
@@ -257,7 +257,13 @@
 
     unawaited(appConnection.onStart.then((_) async {
       await debugger.resumeFromStart();
-      _startedCompleter.complete();
+      if (!_startedCompleter.isCompleted) {
+        _startedCompleter.complete();
+      } else {
+        // See https://github.com/flutter/flutter/issues/117676:
+        _logger
+            .warning('Unexpected state, debugging may not work as expected.');
+      }
     }));
 
     unawaited(appConnection.onDone.then((_) => destroyIsolate()));
diff --git a/dwds/lib/src/version.dart b/dwds/lib/src/version.dart
index a0e68d5..fead18b 100644
--- a/dwds/lib/src/version.dart
+++ b/dwds/lib/src/version.dart
@@ -1,2 +1,2 @@
 // Generated code. Do not modify.
-const packageVersion = '16.0.1';
+const packageVersion = '16.0.2';
diff --git a/dwds/mono_pkg.yaml b/dwds/mono_pkg.yaml
index 5e2ccaf..d5dc531 100644
--- a/dwds/mono_pkg.yaml
+++ b/dwds/mono_pkg.yaml
@@ -15,12 +15,10 @@
       - command: Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
       - test:
       sdk:
-        - dev
         - stable
     - test:
       os: windows
       sdk:
-        - dev
         - stable
   - beta_cron:
     - analyze: .
diff --git a/dwds/pubspec.yaml b/dwds/pubspec.yaml
index 9efb973..4373cbb 100644
--- a/dwds/pubspec.yaml
+++ b/dwds/pubspec.yaml
@@ -1,6 +1,6 @@
 name: dwds
 # Every time this changes you need to run `dart run build_runner build`.
-version: 16.0.1
+version: 16.0.2
 description: >-
   A service that proxies between the Chrome debug protocol and the Dart VM
   service protocol.