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

Side by Side Diff: runtime/bin/vmservice/client/lib/src/observatory/request_manager.dart

Issue 105953008: Observatory frontend changes for Dartium DevTools. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of observatory; 5 part of observatory;
6 6
7 /// A request response interceptor is called for each response. 7 /// A request response interceptor is called for each response.
8 typedef void RequestResponseInterceptor(); 8 typedef void RequestResponseInterceptor();
9 9
10 abstract class RequestManager extends Observable { 10 abstract class RequestManager extends Observable {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 setResponses([{ 61 setResponses([{
62 'type': 'RequestError', 62 'type': 'RequestError',
63 'error': 'Source for $scriptName could not be loaded.' 63 'error': 'Source for $scriptName could not be loaded.'
64 }]); 64 }]);
65 } 65 }
66 }); 66 });
67 } else { 67 } else {
68 request(requestString).then((responseString) { 68 request(requestString).then((responseString) {
69 parseResponses(responseString); 69 parseResponses(responseString);
70 }).catchError((e) { 70 }).catchError((e) {
71 setResponseError(e.target); 71 if (e is FormatException) {
72 setResponseError(e.message);
73 } else {
74 setResponseError(e.target);
75 }
72 }); 76 });
73 } 77 }
74 } 78 }
75 79
76 Future<ScriptSource> getScriptSource(String name, String requestString) { 80 Future<ScriptSource> getScriptSource(String name, String requestString) {
77 int isolateId = _application.locationManager.currentIsolateId(); 81 int isolateId = _application.locationManager.currentIsolateId();
78 Isolate isolate = _application.isolateManager.getIsolate(isolateId); 82 Isolate isolate = _application.isolateManager.getIsolate(isolateId);
79 ScriptSource source = isolate.scripts[name]; 83 ScriptSource source = isolate.scripts[name];
80 if (source != null) { 84 if (source != null) {
81 return new Future.value(source); 85 return new Future.value(source);
(...skipping 13 matching lines...) Expand all
95 /// future which contains the reply from the VM service. 99 /// future which contains the reply from the VM service.
96 Future<String> request(String requestString); 100 Future<String> request(String requestString);
97 } 101 }
98 102
99 103
100 class HttpRequestManager extends RequestManager { 104 class HttpRequestManager extends RequestManager {
101 Future<String> request(String requestString) { 105 Future<String> request(String requestString) {
102 return HttpRequest.getString(prefix + requestString); 106 return HttpRequest.getString(prefix + requestString);
103 } 107 }
104 } 108 }
109
110 class PostMessageRequestManager extends RequestManager {
111 final Map _outstandingRequests = new Map();
112 int _requestSerial = 0;
113 PostMessageRequestManager() {
114 window.onMessage.listen(_messageHandler);
115 }
116
117 void _messageHandler(msg) {
118 var id = msg.data['id'];
119 var name = msg.data['name'];
120 var data = msg.data['data'];
121 if (name != 'observatoryData') {
122 return;
123 }
124 print('Got reply $id $data');
125 var completer = _outstandingRequests[id];
126 if (completer != null) {
127 _outstandingRequests.remove(id);
128 print('Completing $id');
129 completer.complete(data);
130 } else {
131 print('Could not find completer for $id');
132 }
133 }
134
135 Future<String> request(String requestString) {
136 var idString = '$_requestSerial';
137 Map message = {};
138 message['id'] = idString;
139 message['method'] = 'observatoryQuery';
140 message['query'] = requestString;
141 _requestSerial++;
142
143 var completer = new Completer();
144 _outstandingRequests[idString] = completer;
145
146 window.parent.postMessage(JSON.encode(message), '*');
147 return completer.future;
148 }
149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698