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

Side by Side Diff: runtime/bin/vmservice/client/lib/src/service/vm.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 part of service;
6
7 abstract class VM extends Observable {
8 IsolateList _isolates;
9 @observable IsolateList get isolates => _isolates;
10
11 VM() {
12 _isolates = new IsolateList(this);
13 }
14
15 /// Fetch [id] as an [ObservableMap] from the service.
16 Future<ObservableMap> fetchMap(String id) {
turnidge 2014/03/10 21:03:28 What do you think of renaming this to "getAsMap"?
Cutch 2014/03/11 03:17:48 Done.
17 return _fetchString(id).then((response) {
18 try {
19 var map = JSON.decode(response);
20 Logger.root.info('Decoded $id');
21 return toObservable(map);
22 } catch (e, st) {
23 return toObservable({
24 'type': 'Error',
25 'id': '',
26 'kind': 'DecodeError',
27 'message': '$e',
28 'stackTrace': st
29 });
30 }
31 }).catchError((error) {
32 if (error is ProgressEvent) {
33 return toObservable({
34 'type': 'Error',
35 'id': '',
36 'kind': 'FetchError',
37 'message': 'Could not connect to service. Check that you started the'
38 ' VM with the following flags:\n --enable-vm-service'
39 ' --pin-isolates'
40 });
41 }
42 return toObservable({
43 'type': 'Error',
44 'id': '',
45 'kind': 'FetchError',
46 'message': '$error'
47 });
48 });
49 }
50
51 /// get [id] and associate it with [isolate]. [isolate] may be null.
52 Future<ServiceObject> get(Isolate isolate, String id) {
53 return fetchMap(id).then((m) => _upgradeToServiceObject(this, isolate, m));
54 }
55
56 Future<String> _fetchString(String id);
turnidge 2014/03/10 21:03:28 again, "get" and "fetch" mean almost the same thin
Cutch 2014/03/11 03:17:48 Renamed to _getString
57 }
58
59
60 class HttpVM extends VM {
61 final String address;
62
63 HttpVM(this.address) : super();
64
65 Future<String> _fetchString(String id) {
66 Logger.root.info('Fetching $id from $address');
67 return HttpRequest.getString(address + id);
68 }
69 }
70
71 class DartiumVM extends VM {
72 final Map _outstandingRequests = new Map();
73 int _requestSerial = 0;
74
75 DartiumVM() : super() {
76 window.onMessage.listen(_messageHandler);
77 Logger.root.info('Connected to DartiumVM');
78 }
79
80 void _messageHandler(msg) {
81 var id = msg.data['id'];
82 var name = msg.data['name'];
83 var data = msg.data['data'];
84 if (name != 'observatoryData') {
85 return;
86 }
87 var completer = _outstandingRequests[id];
88 assert(completer != null);
89 _outstandingRequests.remove(id);
90 completer.complete(data);
91 }
92
93 Future<String> _fetchString(String path) {
94 var idString = '$_requestSerial';
95 Map message = {};
96 message['id'] = idString;
97 message['method'] = 'observatoryQuery';
98 message['query'] = '/$path';
99 _requestSerial++;
100 var completer = new Completer();
101 _outstandingRequests[idString] = completer;
102 window.parent.postMessage(JSON.encode(message), '*');
103 return completer.future;
104 }
105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698