Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 app; | |
| 6 | |
| 7 abstract class VM extends Observable { | |
| 8 @observable ObservatoryApplication get app => _app; | |
| 9 ObservatoryApplication _app; | |
| 10 | |
| 11 Future<String> fetchString(String path); | |
| 12 | |
| 13 Future<Map> fetchMap(String path) { | |
|
turnidge
2014/03/05 21:02:47
Error checking? Here or elsewhere?
Cutch
2014/03/05 21:54:23
Done.
| |
| 14 return fetchString(path).then((response) { | |
| 15 print(response); | |
|
turnidge
2014/03/05 21:02:47
debug
Cutch
2014/03/05 21:54:23
Done.
| |
| 16 return toObservable(JSON.decode(response)); | |
| 17 }); | |
| 18 } | |
| 19 | |
| 20 @observable final ObservableMap isolates = new ObservableMap(); | |
| 21 Isolate getIsolate(String id) => isolates[id]; | |
|
turnidge
2014/03/05 21:02:47
Confirm that loading the stacktrace page directly
Cutch
2014/03/05 21:54:23
Done.
| |
| 22 | |
| 23 static bool _foundIsolateInMembers(String id, List<Map> members) { | |
| 24 return members.any((E) => E['id'] == id); | |
| 25 } | |
| 26 | |
| 27 void _updateIsolates(List<Map> members) { | |
| 28 // Find dead isolates. | |
| 29 var deadIsolates = []; | |
| 30 isolates.forEach((k, v) { | |
| 31 if (!_foundIsolateInMembers(k, members)) { | |
| 32 deadIsolates.add(k); | |
| 33 } | |
| 34 }); | |
| 35 // Remove them. | |
| 36 deadIsolates.forEach((id) { | |
| 37 isolates.remove(id); | |
| 38 }); | |
| 39 // Add new isolates. | |
| 40 members.forEach((map) { | |
| 41 var id = map['id']; | |
| 42 var isolate = isolates[id]; | |
| 43 if (isolate == null) { | |
| 44 isolate = new Isolate.fromMap(this, map); | |
| 45 isolates[id] = isolate; | |
| 46 } | |
| 47 isolate.refresh(); | |
| 48 }); | |
| 49 } | |
| 50 | |
| 51 void refreshIsolates() { | |
| 52 fetchMap('isolates').then((map) { | |
| 53 assert(map['type'] == 'IsolateList'); | |
| 54 _updateIsolates(map['members']); | |
| 55 app.setResponse(map); | |
| 56 }); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 | |
| 61 class HttpVM extends VM { | |
| 62 final String address; | |
| 63 HttpVM(this.address); | |
| 64 | |
| 65 Future<String> fetchString(String path) { | |
| 66 Logger.root.info('Fetching $path from $address'); | |
| 67 return HttpRequest.getString(address + path); | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 class DartiumVM extends VM { | |
| 72 final Map _outstandingRequests = new Map(); | |
| 73 int _requestSerial = 0; | |
| 74 PostMessageRequestManager() { | |
| 75 window.onMessage.listen(_messageHandler); | |
| 76 } | |
| 77 | |
| 78 void _messageHandler(msg) { | |
| 79 var id = msg.data['id']; | |
| 80 var name = msg.data['name']; | |
| 81 var data = msg.data['data']; | |
| 82 if (name != 'observatoryData') { | |
| 83 return; | |
| 84 } | |
| 85 var completer = _outstandingRequests[id]; | |
| 86 assert(completer != null); | |
| 87 _outstandingRequests.remove(id); | |
| 88 completer.complete(data); | |
| 89 } | |
| 90 | |
| 91 Future<String> fetchString(String path) { | |
| 92 var idString = '$_requestSerial'; | |
| 93 Map message = {}; | |
| 94 message['id'] = idString; | |
| 95 message['method'] = 'observatoryQuery'; | |
| 96 message['query'] = path; | |
| 97 _requestSerial++; | |
| 98 var completer = new Completer(); | |
| 99 _outstandingRequests[idString] = completer; | |
| 100 window.parent.postMessage(JSON.encode(message), '*'); | |
| 101 return completer.future; | |
| 102 } | |
| 103 } | |
| OLD | NEW |