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

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

Issue 143973005: Code coverage in Observatory (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 static String isolateIdFromRequest(String url) { 96 static String isolateIdFromRequest(String url) {
97 var prefix = isolatePrefixFromRequest(url); 97 var prefix = isolatePrefixFromRequest(url);
98 if (prefix == null) { 98 if (prefix == null) {
99 return null; 99 return null;
100 } 100 }
101 // Chop off the '/'. 101 // Chop off the '/'.
102 return prefix.substring(1); 102 return prefix.substring(1);
103 } 103 }
104 104
105 static final RegExp _scriptMatcher = new RegExp(r'/isolates/\d+/scripts/.+');
106 static bool isScriptRequest(url) => _scriptMatcher.hasMatch(url);
107 static final RegExp _scriptPrefixMatcher =
108 new RegExp(r'/isolates/\d+/');
109 static String scriptUrlFromRequest(String url) {
110 var m = _scriptPrefixMatcher.matchAsPrefix(url);
111 if (m == null) {
112 return null;
113 }
114 return m.input.substring(m.end);
115 }
116
105 void _setModelResponse(String type, String modelName, dynamic model) { 117 void _setModelResponse(String type, String modelName, dynamic model) {
106 var response = { 118 var response = {
107 'type': type, 119 'type': type,
108 modelName: model 120 modelName: model
109 }; 121 };
110 setResponses([response]); 122 setResponses([response]);
111 } 123 }
112 124
113 /// Handle 'Code' requests 125 /// Handle 'Code' requests
114 void _getCode(String requestString) { 126 void _getCode(String requestString) {
(...skipping 26 matching lines...) Expand all
141 } 153 }
142 assert(map['type'] == 'Code'); 154 assert(map['type'] == 'Code');
143 var code = new Code.fromMap(map); 155 var code = new Code.fromMap(map);
144 Logger.root.info( 156 Logger.root.info(
145 'Added code with 0x${address.toRadixString(16)} to isolate.'); 157 'Added code with 0x${address.toRadixString(16)} to isolate.');
146 isolate.codes.add(code); 158 isolate.codes.add(code);
147 _setModelResponse('Code', 'code', code); 159 _setModelResponse('Code', 'code', code);
148 }).catchError(_requestCatchError); 160 }).catchError(_requestCatchError);
149 } 161 }
150 162
163 void _getScript(String requestString) {
164 var isolateId = isolateIdFromRequest(requestString);
165 if (isolateId == null) {
166 setResponseError('$isolateId is not an isolate id.');
167 return;
168 }
169 var isolate = _application.isolateManager.getIsolate(isolateId);
170 if (isolate == null) {
171 setResponseError('$isolateId could not be found.');
172 return;
173 }
174 var url = scriptUrlFromRequest(requestString);
175 if (url == null) {
176 setResponseError('$requestString is not a valid script request.');
177 return;
178 }
179 var script = isolate.scripts[url];
180 if ((script != null) && !script.needsSource) {
181 Logger.root.info('Found script ${script.scriptRef['name']} in isolate');
182 _setModelResponse('Script', 'script', script);
183 return;
184 }
185 if (script != null) {
186 // The isolate has the script but no script source code.
187 requestMap(requestString).then((response) {
188 assert(response['type'] == 'Script');
189 script._processSource(response['source']);
190 Logger.root.info(
191 'Grabbed script ${script.scriptRef['name']} source.');
192 _setModelResponse('Script', 'script', script);
193 });
194 return;
195 }
196 // New script.
197 requestMap(requestString).then((response) {
198 assert(response['type'] == 'Script');
199 var script = new Script.fromMap(response);
200 Logger.root.info(
201 'Added script ${script.scriptRef['name']} to isolate.');
202 _setModelResponse('Script', 'script', script);
203 isolate.scripts[url] = script;
204 });
205 }
206
151 void _requestCatchError(e, st) { 207 void _requestCatchError(e, st) {
152 if (e is HttpRequest) { 208 if (e is HttpRequest) {
153 setResponseRequestError(e.target); 209 setResponseRequestError(e.target);
154 } else { 210 } else {
155 setResponseError('$e $st'); 211 setResponseError('$e $st');
156 } 212 }
157 } 213 }
158 214
159 /// Request [request] from the VM service. Updates [responses]. 215 /// Request [request] from the VM service. Updates [responses].
160 /// Will trigger [interceptor] if one is set. 216 /// Will trigger [interceptor] if one is set.
161 void get(String requestString) { 217 void get(String requestString) {
162 if (isCodeRequest(requestString)) { 218 if (isCodeRequest(requestString)) {
163 _getCode(requestString); 219 _getCode(requestString);
164 return; 220 return;
165 } 221 }
222 if (isScriptRequest(requestString)) {
223 _getScript(requestString);
224 return;
225 }
166 request(requestString).then((responseString) { 226 request(requestString).then((responseString) {
167 parseResponses(responseString); 227 parseResponses(responseString);
168 }).catchError(_requestCatchError); 228 }).catchError(_requestCatchError);
169 } 229 }
170 230
171 /// Abstract method. Given the [requestString], return a String in the 231 /// Abstract method. Given the [requestString], return a String in the
172 /// future which contains the reply from the VM service. 232 /// future which contains the reply from the VM service.
173 Future<String> request(String requestString); 233 Future<String> request(String requestString);
174 234
175 Future<Map> requestMap(String requestString) { 235 Future<Map> requestMap(String requestString) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 message['query'] = requestString; 284 message['query'] = requestString;
225 _requestSerial++; 285 _requestSerial++;
226 286
227 var completer = new Completer(); 287 var completer = new Completer();
228 _outstandingRequests[idString] = completer; 288 _outstandingRequests[idString] = completer;
229 289
230 window.parent.postMessage(JSON.encode(message), '*'); 290 window.parent.postMessage(JSON.encode(message), '*');
231 return completer.future; 291 return completer.future;
232 } 292 }
233 } 293 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698