Skip to content

Replaced WipConnection with WipDebugger. #502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dwds/lib/dwds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Dwds {
LogWriter logWriter,
bool verbose,
bool enableDebugExtension,
WipDebugger wipDebugger,
}) async {
hostname ??= 'localhost';
reloadConfiguration ??= ReloadConfiguration.none;
Expand Down Expand Up @@ -99,6 +100,7 @@ class Dwds {
hostname,
verbose,
logWriter,
wipDebugger,
);
cascade = cascade.add(devHandler.handler).add(assetHandler.handler);

Expand Down
22 changes: 10 additions & 12 deletions dwds/lib/src/debugging/inspector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AppInspector extends Domain {
/// Map of [ScriptRef] id to containing [LibraryRef] id.
final _scriptIdToLibraryId = <String, String>{};

final WipConnection _tabConnection;
final WipDebugger _wipDebugger;
final AssetHandler _assetHandler;
final Debugger _debugger;
final Isolate isolate;
Expand All @@ -49,10 +49,10 @@ class AppInspector extends Domain {

AppInspector._(
this.isolate,
this._tabConnection,
this._assetHandler,
this._debugger,
this._root,
this._wipDebugger,
) : isolateRef = _toIsolateRef(isolate),
super.forInspector();

Expand Down Expand Up @@ -81,7 +81,7 @@ class AppInspector extends Domain {
..number = isolate.number;

static Future<AppInspector> initialize(
WipConnection tabConnection,
WipDebugger wipDebugger,
AssetHandler assetHandler,
Debugger debugger,
String root,
Expand All @@ -96,7 +96,7 @@ class AppInspector extends Domain {
..libraries = []
..extensionRPCs = [];
var inspector =
AppInspector._(isolate, tabConnection, assetHandler, debugger, root);
AppInspector._(isolate, assetHandler, debugger, root, wipDebugger);
await inspector._initialize();
return inspector;
}
Expand All @@ -123,7 +123,7 @@ class AppInspector extends Domain {
return library.$expression;
})();
''';
result = await _tabConnection.runtime.sendCommand('Runtime.evaluate',
result = await _wipDebugger.sendCommand('Runtime.evaluate',
params: {'expression': evalExpression});
handleErrorIfPresent(result,
evalContents: evalExpression,
Expand All @@ -139,8 +139,8 @@ function($argsString) {
return library.$expression;
}
''';
result = await _tabConnection.runtime
.sendCommand('Runtime.callFunctionOn', params: {
result =
await _wipDebugger.sendCommand('Runtime.callFunctionOn', params: {
'functionDeclaration': evalExpression,
'arguments': arguments,
// TODO(jakemac): Use the executionContext instead, or possibly the
Expand Down Expand Up @@ -265,7 +265,7 @@ function($argsString) {
return result;
})()
''';
var result = await _tabConnection.runtime.sendCommand('Runtime.evaluate',
var result = await _wipDebugger.sendCommand('Runtime.evaluate',
params: {'expression': expression, 'returnByValue': true});
handleErrorIfPresent(result, evalContents: expression);
var classDescriptors = (result.result['result']['value']['classes'] as List)
Expand Down Expand Up @@ -405,8 +405,7 @@ function($argsString) {
Future<List<LibraryRef>> _getLibraryRefs() async {
if (_libraryRefs.isNotEmpty) return _libraryRefs.values.toList();
var expression = "require('dart_sdk').dart.getLibraries();";
var librariesResult = await _tabConnection.runtime.sendCommand(
'Runtime.evaluate',
var librariesResult = await _wipDebugger.sendCommand('Runtime.evaluate',
params: {'expression': expression, 'returnByValue': true});
handleErrorIfPresent(librariesResult, evalContents: expression);
var libraries =
Expand All @@ -424,8 +423,7 @@ function($argsString) {
/// Runs an eval on the page to compute all existing registered extensions.
Future<List<String>> _getExtensionRpcs() async {
var expression = "require('dart_sdk').developer._extensions.keys.toList();";
var extensionsResult = await _tabConnection.runtime.sendCommand(
'Runtime.evaluate',
var extensionsResult = await _wipDebugger.sendCommand('Runtime.evaluate',
params: {'expression': expression, 'returnByValue': true});
handleErrorIfPresent(extensionsResult, evalContents: expression);
return List.from(extensionsResult.result['result']['value'] as List);
Expand Down
3 changes: 3 additions & 0 deletions dwds/lib/src/handlers/dev_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class DevHandler {
final bool _verbose;
final void Function(Level, String) _logWriter;
final Future<ChromeConnection> Function() _chromeConnection;
final WipDebugger _wipDebugger;

Stream<AppConnection> get connectedApps => _connectedApps.stream;

Expand All @@ -50,6 +51,7 @@ class DevHandler {
this._hostname,
this._verbose,
this._logWriter,
this._wipDebugger,
) {
_sub = buildResults.listen(_emitBuildResults);
_listen();
Expand Down Expand Up @@ -87,6 +89,7 @@ class DevHandler {
chromeConnection,
_assetHandler.getRelativeAsset,
appInstanceId,
_wipDebugger,
onResponse: _verbose
? (response) {
if (response['error'] == null) return;
Expand Down
20 changes: 14 additions & 6 deletions dwds/lib/src/services/chrome_proxy_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class ChromeProxyService implements VmServiceInterface {
// TODO(grouma) - This should be class private.
final WipConnection tabConnection;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this still used? Can it be removed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline. This can only be replaced when we have an alternative for listening to the console log events.


final WipDebugger _wipDebugger;

final AssetHandler _assetHandler;

/// Provides debugger-related functionality.
Expand All @@ -61,10 +63,14 @@ class ChromeProxyService implements VmServiceInterface {
this._tab,
this.tabConnection,
this._assetHandler,
this._wipDebugger,
);

static Future<ChromeProxyService> create(ChromeConnection chromeConnection,
AssetHandler assetHandler, String appInstanceId) async {
static Future<ChromeProxyService> create(
ChromeConnection chromeConnection,
AssetHandler assetHandler,
String appInstanceId,
WipDebugger wipDebugger) async {
ChromeTab appTab;
for (var tab in await chromeConnection.getTabs()) {
if (tab.url.startsWith('chrome-extensions:')) continue;
Expand All @@ -84,13 +90,16 @@ class ChromeProxyService implements VmServiceInterface {
var tabConnection = await appTab.connect();
await tabConnection.runtime.enable();

wipDebugger = WipDebugger(tabConnection);

// TODO: What about `architectureBits`, `targetCPU`, `hostCPU` and `pid`?
final vm = VM()
..isolates = []
..name = 'ChromeDebugProxy'
..startTime = DateTime.now().millisecondsSinceEpoch
..version = Platform.version;
var service = ChromeProxyService._(vm, appTab, tabConnection, assetHandler);
var service = ChromeProxyService._(
vm, appTab, tabConnection, assetHandler, wipDebugger);
await service._initialize();
await service.createIsolate();
return service;
Expand Down Expand Up @@ -121,7 +130,7 @@ class ChromeProxyService implements VmServiceInterface {
}

_inspector = await AppInspector.initialize(
tabConnection,
_wipDebugger,
_assetHandler,
_debugger,
uri,
Expand Down Expand Up @@ -206,8 +215,7 @@ class ChromeProxyService implements VmServiceInterface {
require("dart_sdk").developer.invokeExtension(
"$method", JSON.stringify(${jsonEncode(stringArgs)}));
''';
var response =
await tabConnection.runtime.sendCommand('Runtime.evaluate', params: {
var response = await _wipDebugger.sendCommand('Runtime.evaluate', params: {
'expression': expression,
'awaitPromise': true,
});
Expand Down
5 changes: 3 additions & 2 deletions dwds/lib/src/services/debug_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ class DebugService {
String hostname,
ChromeConnection chromeConnection,
Future<String> Function(String) assetHandler,
String appInstanceId, {
String appInstanceId,
WipDebugger wipDebugger, {
void Function(Map<String, dynamic>) onRequest,
void Function(Map<String, dynamic>) onResponse,
}) async {
var chromeProxyService = await ChromeProxyService.create(
chromeConnection, assetHandler, appInstanceId);
chromeConnection, assetHandler, appInstanceId, wipDebugger);
var serviceExtensionRegistry = ServiceExtensionRegistry();
var authToken = _makeAuthToken();
var innerHandler = webSocketHandler(_createNewConnectionHandler(
Expand Down
8 changes: 6 additions & 2 deletions dwds/test/fixtures/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:build_daemon/client.dart';
import 'package:build_daemon/data/build_status.dart';
import 'package:build_daemon/data/build_target.dart';
import 'package:dwds/dwds.dart';
import 'package:dwds/src/servers/extension_backend.dart';
import 'package:dwds/src/services/chrome_proxy_service.dart';
import 'package:dwds/src/utilities/shared.dart';
import 'package:http/http.dart' as http;
Expand All @@ -30,6 +31,8 @@ class TestContext {
AppConnection appConnection;
DebugConnection debugConnection;
ChromeProxyService chromeProxyService;
ExtensionBackend extensionBackend;
WipDebugger wipDebugger;
int port;
File _entryFile;
String _entryContents;
Expand Down Expand Up @@ -99,6 +102,7 @@ class TestContext {
() async => connection,
reloadConfiguration,
serveDevTools,
wipDebugger,
);

appUrl = 'http://localhost:$port/$path';
Expand All @@ -115,8 +119,8 @@ class TestContext {
var result = await http.get('http://localhost:$port/$path');
return result.body;
};
chromeProxyService = await ChromeProxyService.create(
connection, assetHandler, appConnection.request.instanceId);
chromeProxyService = await ChromeProxyService.create(connection,
assetHandler, appConnection.request.instanceId, wipDebugger);
}

Future<Null> tearDown() async {
Expand Down
2 changes: 2 additions & 0 deletions dwds/test/fixtures/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class TestServer {
Future<ChromeConnection> Function() chromeConnection,
ReloadConfiguration reloadConfiguration,
bool serveDevTools,
WipDebugger wipDebugger,
) async {
var pipeline = const Pipeline();

Expand All @@ -64,6 +65,7 @@ class TestServer {
reloadConfiguration: reloadConfiguration,
serveDevTools: serveDevTools,
verbose: true,
wipDebugger: wipDebugger,
);

var server = await HttpMultiServer.bind('localhost', port);
Expand Down