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

Side by Side Diff: runtime/observatory/lib/service_common.dart

Issue 823403004: Begin migrating the vm service from a rest-style interface to a json-rpc style interface. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: remove old-style standalone tests. Created 5 years, 10 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
« no previous file with comments | « runtime/bin/vmservice/vmservice_dartium.dart ('k') | runtime/observatory/lib/service_html.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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 library service_common; 5 library service_common;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:typed_data'; 9 import 'dart:typed_data';
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 return { 47 return {
48 'lastConnectionTime': lastConnectionTime, 48 'lastConnectionTime': lastConnectionTime,
49 'chrome': chrome, 49 'chrome': chrome,
50 'name': name, 50 'name': name,
51 'networkAddress': networkAddress, 51 'networkAddress': networkAddress,
52 }; 52 };
53 } 53 }
54 } 54 }
55 55
56 class _WebSocketRequest { 56 class _WebSocketRequest {
57 final String id; 57 final String method;
58 final Map params;
58 final Completer<String> completer; 59 final Completer<String> completer;
59 _WebSocketRequest(this.id) 60
61 _WebSocketRequest.old(this.method)
62 : params = null, completer = new Completer<String>();
63
64 _WebSocketRequest.rpc(this.method, this.params)
60 : completer = new Completer<String>(); 65 : completer = new Completer<String>();
61 } 66 }
62 67
63 /// Minimal common interface for 'WebSocket' in [dart:io] and [dart:html]. 68 /// Minimal common interface for 'WebSocket' in [dart:io] and [dart:html].
64 abstract class CommonWebSocket { 69 abstract class CommonWebSocket {
65 void connect(String address, 70 void connect(String address,
66 void onOpen(), 71 void onOpen(),
67 void onMessage(dynamic data), 72 void onMessage(dynamic data),
68 void onError(), 73 void onError(),
69 void onClose()); 74 void onClose());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 target.networkAddress, _onOpen, _onMessage, _onError, _onClose); 135 target.networkAddress, _onOpen, _onMessage, _onError, _onClose);
131 } 136 }
132 return _makeRequest(id); 137 return _makeRequest(id);
133 } 138 }
134 139
135 /// Add a request for [id] to pending requests. 140 /// Add a request for [id] to pending requests.
136 Future<String> _makeRequest(String id) { 141 Future<String> _makeRequest(String id) {
137 assert(_hasInitiatedConnect); 142 assert(_hasInitiatedConnect);
138 // Create request. 143 // Create request.
139 String serial = (_requestSerial++).toString(); 144 String serial = (_requestSerial++).toString();
140 var request = new _WebSocketRequest(id); 145 var request = new _WebSocketRequest.old(id);
141 if (_webSocket.isOpen) { 146 if (_webSocket.isOpen) {
142 // Already connected, send request immediately. 147 // Already connected, send request immediately.
143 _sendRequest(serial, request); 148 _sendRequest(serial, request);
149 } else {
150 // Not connected yet, add to delayed requests.
151 _delayedRequests[serial] = request;
152 }
153 return request.completer.future;
154 }
155
156 Future<String> invokeRpcRaw(String method, Map params) {
157 if (!_hasInitiatedConnect) {
158 _hasInitiatedConnect = true;
159 _webSocket.connect(
160 target.networkAddress, _onOpen, _onMessage, _onError, _onClose);
161 }
162 String serial = (_requestSerial++).toString();
163 var request = new _WebSocketRequest.rpc(method, params);
164 if (_webSocket.isOpen) {
165 // Already connected, send request immediately.
166 _sendRequest(serial, request);
144 } else { 167 } else {
145 // Not connected yet, add to delayed requests. 168 // Not connected yet, add to delayed requests.
146 _delayedRequests[serial] = request; 169 _delayedRequests[serial] = request;
147 } 170 }
148 return request.completer.future; 171 return request.completer.future;
149 } 172 }
150 173
151 void _onClose() { 174 void _onClose() {
152 _cancelAllRequests(); 175 _cancelAllRequests();
153 _notifyDisconnect(); 176 _notifyDisconnect();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 var serial; 219 var serial;
197 var response; 220 var response;
198 if (target.chrome) { 221 if (target.chrome) {
199 if (map['method'] != 'Dart.observatoryData') { 222 if (map['method'] != 'Dart.observatoryData') {
200 // ignore devtools protocol spam. 223 // ignore devtools protocol spam.
201 return; 224 return;
202 } 225 }
203 serial = map['params']['id'].toString(); 226 serial = map['params']['id'].toString();
204 response = map['params']['data']; 227 response = map['params']['data'];
205 } else { 228 } else {
206 serial = map['seq']; 229 serial = map['id'];
207 response = map['response']; 230 response = map['response'];
208 } 231 }
209 if (serial == null) { 232 if (serial == null) {
210 // Messages without sequence numbers are asynchronous events 233 // Messages without sequence numbers are asynchronous events
211 // from the vm. 234 // from the vm.
212 postEventMessage(response); 235 postEventMessage(response);
213 return; 236 return;
214 } 237 }
215 // Complete request. 238 // Complete request.
216 var request = _pendingRequests.remove(serial); 239 var request = _pendingRequests.remove(serial);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 Logger.root.info('Sending all delayed requests.'); 282 Logger.root.info('Sending all delayed requests.');
260 // Send all delayed requests. 283 // Send all delayed requests.
261 _delayedRequests.forEach(_sendRequest); 284 _delayedRequests.forEach(_sendRequest);
262 // Clear all delayed requests. 285 // Clear all delayed requests.
263 _delayedRequests.clear(); 286 _delayedRequests.clear();
264 } 287 }
265 288
266 /// Send the request over WebSocket. 289 /// Send the request over WebSocket.
267 void _sendRequest(String serial, _WebSocketRequest request) { 290 void _sendRequest(String serial, _WebSocketRequest request) {
268 assert (_webSocket.isOpen); 291 assert (_webSocket.isOpen);
269 if (!request.id.endsWith('/profile/tag')) { 292 if (request.method != 'getTagProfile') {
270 Logger.root.info('GET ${request.id} from ${target.networkAddress}'); 293 Logger.root.info('GET ${request.method} from ${target.networkAddress}');
271 } 294 }
272 // Mark request as pending. 295 // Mark request as pending.
273 assert(_pendingRequests.containsKey(serial) == false); 296 assert(_pendingRequests.containsKey(serial) == false);
274 _pendingRequests[serial] = request; 297 _pendingRequests[serial] = request;
275 var message; 298 var message;
276 // Encode message. 299 // Encode message.
277 if (target.chrome) { 300 if (target.chrome) {
278 message = JSON.encode({ 301 message = JSON.encode({
279 'id': int.parse(serial), 302 'id': int.parse(serial),
280 'method': 'Dart.observatoryQuery', 303 'method': 'Dart.observatoryQuery',
281 'params': { 304 'params': {
282 'id': serial, 305 'id': serial,
283 'query': request.id 306 'query': request.method
284 } 307 }
285 }); 308 });
286 } else { 309 } else {
287 message = JSON.encode({'seq': serial, 'request': request.id}); 310 message = JSON.encode({'id': serial,
311 'method': request.method,
312 'params': request.params});
288 } 313 }
289 // Send message. 314 // Send message.
290 _webSocket.send(message); 315 _webSocket.send(message);
291 } 316 }
292 } 317 }
OLDNEW
« no previous file with comments | « runtime/bin/vmservice/vmservice_dartium.dart ('k') | runtime/observatory/lib/service_html.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698