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

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

Issue 897193002: Finish moving service protocol to json rpc. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review 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/observatory/lib/elements.html ('k') | runtime/observatory/lib/src/app/application.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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 'networkAddress': networkAddress, 51 'networkAddress': networkAddress,
52 }; 52 };
53 } 53 }
54 } 54 }
55 55
56 class _WebSocketRequest { 56 class _WebSocketRequest {
57 final String method; 57 final String method;
58 final Map params; 58 final Map params;
59 final Completer<String> completer; 59 final Completer<String> completer;
60 60
61 _WebSocketRequest.old(this.method) 61 _WebSocketRequest(this.method, this.params)
62 : params = null, completer = new Completer<String>();
63
64 _WebSocketRequest.rpc(this.method, this.params)
65 : completer = new Completer<String>(); 62 : completer = new Completer<String>();
66 } 63 }
67 64
68 /// Minimal common interface for 'WebSocket' in [dart:io] and [dart:html]. 65 /// Minimal common interface for 'WebSocket' in [dart:io] and [dart:html].
69 abstract class CommonWebSocket { 66 abstract class CommonWebSocket {
70 void connect(String address, 67 void connect(String address,
71 void onOpen(), 68 void onOpen(),
72 void onMessage(dynamic data), 69 void onMessage(dynamic data),
73 void onError(), 70 void onError(),
74 void onClose()); 71 void onClose());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 Future get onDisconnect => _disconnected.future; 118 Future get onDisconnect => _disconnected.future;
122 119
123 void disconnect() { 120 void disconnect() {
124 if (_hasInitiatedConnect) { 121 if (_hasInitiatedConnect) {
125 _webSocket.close(); 122 _webSocket.close();
126 } 123 }
127 _cancelAllRequests(); 124 _cancelAllRequests();
128 _notifyDisconnect(); 125 _notifyDisconnect();
129 } 126 }
130 127
131 Future<String> getStringDeprecated(String id) {
132 if (!_hasInitiatedConnect) {
133 _hasInitiatedConnect = true;
134 _webSocket.connect(
135 target.networkAddress, _onOpen, _onMessage, _onError, _onClose);
136 }
137 return _makeRequest(id);
138 }
139
140 /// Add a request for [id] to pending requests.
141 Future<String> _makeRequest(String id) {
142 assert(_hasInitiatedConnect);
143 // Create request.
144 String serial = (_requestSerial++).toString();
145 var request = new _WebSocketRequest.old(id);
146 if (_webSocket.isOpen) {
147 // Already connected, send request immediately.
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) { 128 Future<String> invokeRpcRaw(String method, Map params) {
157 if (!_hasInitiatedConnect) { 129 if (!_hasInitiatedConnect) {
158 _hasInitiatedConnect = true; 130 _hasInitiatedConnect = true;
159 _webSocket.connect( 131 _webSocket.connect(
160 target.networkAddress, _onOpen, _onMessage, _onError, _onClose); 132 target.networkAddress, _onOpen, _onMessage, _onError, _onClose);
161 } 133 }
162 String serial = (_requestSerial++).toString(); 134 String serial = (_requestSerial++).toString();
163 var request = new _WebSocketRequest.rpc(method, params); 135 var request = new _WebSocketRequest(method, params);
164 if (_webSocket.isOpen) { 136 if (_webSocket.isOpen) {
165 // Already connected, send request immediately. 137 // Already connected, send request immediately.
166 _sendRequest(serial, request); 138 _sendRequest(serial, request);
167 } else { 139 } else {
168 // Not connected yet, add to delayed requests. 140 // Not connected yet, add to delayed requests.
169 _delayedRequests[serial] = request; 141 _delayedRequests[serial] = request;
170 } 142 }
171 return request.completer.future; 143 return request.completer.future;
172 } 144 }
173 145
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 Logger.root.info('Sending all delayed requests.'); 254 Logger.root.info('Sending all delayed requests.');
283 // Send all delayed requests. 255 // Send all delayed requests.
284 _delayedRequests.forEach(_sendRequest); 256 _delayedRequests.forEach(_sendRequest);
285 // Clear all delayed requests. 257 // Clear all delayed requests.
286 _delayedRequests.clear(); 258 _delayedRequests.clear();
287 } 259 }
288 260
289 /// Send the request over WebSocket. 261 /// Send the request over WebSocket.
290 void _sendRequest(String serial, _WebSocketRequest request) { 262 void _sendRequest(String serial, _WebSocketRequest request) {
291 assert (_webSocket.isOpen); 263 assert (_webSocket.isOpen);
292 if (request.method != 'getTagProfile') { 264 if (request.method != 'getTagProfile' &&
265 request.method != 'getIsolateMetric' &&
266 request.method != 'getVMMetric') {
293 Logger.root.info('GET ${request.method} from ${target.networkAddress}'); 267 Logger.root.info('GET ${request.method} from ${target.networkAddress}');
294 } 268 }
295 // Mark request as pending. 269 // Mark request as pending.
296 assert(_pendingRequests.containsKey(serial) == false); 270 assert(_pendingRequests.containsKey(serial) == false);
297 _pendingRequests[serial] = request; 271 _pendingRequests[serial] = request;
298 var message; 272 var message;
299 // Encode message. 273 // Encode message.
300 if (target.chrome) { 274 if (target.chrome) {
301 message = JSON.encode({ 275 message = JSON.encode({
302 'id': int.parse(serial), 276 'id': int.parse(serial),
303 'method': 'Dart.observatoryQuery', 277 'method': 'Dart.observatoryQuery',
304 'params': { 278 'params': {
305 'id': serial, 279 'id': serial,
306 'query': request.method 280 'query': request.method
307 } 281 }
308 }); 282 });
309 } else { 283 } else {
310 message = JSON.encode({'id': serial, 284 message = JSON.encode({'id': serial,
311 'method': request.method, 285 'method': request.method,
312 'params': request.params}); 286 'params': request.params});
313 } 287 }
314 // Send message. 288 // Send message.
315 _webSocket.send(message); 289 _webSocket.send(message);
316 } 290 }
317 } 291 }
OLDNEW
« no previous file with comments | « runtime/observatory/lib/elements.html ('k') | runtime/observatory/lib/src/app/application.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698