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

Unified Diff: runtime/bin/vmservice/client/lib/service_html.dart

Issue 192443004: Complete the switch to ServiceObject (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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
Index: runtime/bin/vmservice/client/lib/service_html.dart
diff --git a/runtime/bin/vmservice/client/lib/service_html.dart b/runtime/bin/vmservice/client/lib/service_html.dart
new file mode 100644
index 0000000000000000000000000000000000000000..83df4d299babf58f5e12ff43bb9dc189746a3615
--- /dev/null
+++ b/runtime/bin/vmservice/client/lib/service_html.dart
@@ -0,0 +1,73 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library service_html;
+
+import 'dart:async';
+import 'dart:convert';
+import 'dart:html';
+
+import 'package:logging/logging.dart';
+import 'package:observatory/service.dart';
+
+// Export the service library.
+export 'package:observatory/service.dart';
+
+class HttpVM extends VM {
+ final String address;
+
+ HttpVM(this.address) : super();
+
+ Future<String> getString(String id) {
+ Logger.root.info('Fetching $id from $address');
+ return HttpRequest.getString(address + id).catchError((error) {
+ // If we get an error here, the network request has failed.
+ Logger.root.severe('HttpRequest.getString failed.');
+ return JSON.encode({
+ 'type': 'Error',
+ 'id': '',
+ 'kind': 'NetworkError',
+ 'message': 'Could not connect to service. Check that you started the'
+ ' VM with the following flags:\n --enable-vm-service'
+ ' --pin-isolates'
+ });
+ });
+ }
+}
+
+class DartiumVM extends VM {
+ final Map _outstandingRequests = new Map();
+ int _requestSerial = 0;
+
+ DartiumVM() : super() {
+ window.onMessage.listen(_messageHandler);
+ Logger.root.info('Connected to DartiumVM');
+ }
+
+ void _messageHandler(msg) {
+ var id = msg.data['id'];
+ var name = msg.data['name'];
+ var data = msg.data['data'];
+ if (name != 'observatoryData') {
+ return;
+ }
+ var completer = _outstandingRequests[id];
+ assert(completer != null);
+ _outstandingRequests.remove(id);
+ completer.complete(data);
+ }
+
+ Future<String> getString(String path) {
+ var idString = '$_requestSerial';
+ Map message = {};
+ message['id'] = idString;
+ message['method'] = 'observatoryQuery';
+ message['query'] = '/$path';
+ _requestSerial++;
+ var completer = new Completer();
+ _outstandingRequests[idString] = completer;
+ window.parent.postMessage(JSON.encode(message), '*');
+ return completer.future;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698