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

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

Issue 961483002: Fix isolate lifecycle handling in service library (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 | « no previous file | runtime/observatory/lib/src/elements/vm_view.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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 _notifyDisconnect(); 154 _notifyDisconnect();
155 } 155 }
156 156
157 // WebSocket open event handler. 157 // WebSocket open event handler.
158 void _onOpen() { 158 void _onOpen() {
159 target.lastConnectionTime = new DateTime.now().millisecondsSinceEpoch; 159 target.lastConnectionTime = new DateTime.now().millisecondsSinceEpoch;
160 _sendAllDelayedRequests(); 160 _sendAllDelayedRequests();
161 _notifyConnect(); 161 _notifyConnect();
162 } 162 }
163 163
164 // WebSocket message event handler. 164 void _onBinaryMessage(dynamic data) {
165 void _onMessage(dynamic data) { 165 _webSocket.nonStringToByteData(data).then((ByteData bytes) {
166 if (data is! String) { 166 // See format spec. in VMs Service::SendEvent.
167 _webSocket.nonStringToByteData(data).then((ByteData bytes) { 167 int offset = 0;
168 // See format spec. in VMs Service::SendEvent. 168 // Dart2JS workaround (no getUint64). Limit to 4 GB metadata.
169 int offset = 0; 169 assert(bytes.getUint32(offset, Endianness.BIG_ENDIAN) == 0);
170 // Dart2JS workaround (no getUint64). Limit to 4 GB metadata. 170 int metaSize = bytes.getUint32(offset + 4, Endianness.BIG_ENDIAN);
171 assert(bytes.getUint32(offset, Endianness.BIG_ENDIAN) == 0); 171 offset += 8;
172 int metaSize = bytes.getUint32(offset + 4, Endianness.BIG_ENDIAN); 172 var meta = _utf8Decoder.convert(new Uint8List.view(
173 offset += 8; 173 bytes.buffer, bytes.offsetInBytes + offset, metaSize));
174 var meta = _utf8Decoder.convert(new Uint8List.view( 174 offset += metaSize;
175 bytes.buffer, bytes.offsetInBytes + offset, metaSize)); 175 var data = new ByteData.view(
176 offset += metaSize; 176 bytes.buffer,
177 var data = new ByteData.view( 177 bytes.offsetInBytes + offset,
178 bytes.buffer, 178 bytes.lengthInBytes - offset);
179 bytes.offsetInBytes + offset, 179 postServiceEvent(meta, data);
180 bytes.lengthInBytes - offset); 180 });
181 postEventMessage(meta, data); 181 }
182 }); 182
183 return; 183 void _onStringMessage(String data) {
184 }
185 var map = JSON.decode(data); 184 var map = JSON.decode(data);
186 if (map == null) { 185 if (map == null) {
187 Logger.root.severe('WebSocketVM got empty message'); 186 Logger.root.severe('WebSocketVM got empty message');
188 return; 187 return;
189 } 188 }
190 // Extract serial and response. 189 // Extract serial and response.
191 var serial; 190 var serial;
192 var response; 191 var response;
193 if (target.chrome) { 192 serial = map['id'];
194 if (map['method'] != 'Dart.observatoryData') { 193 response = map['response'];
195 // ignore devtools protocol spam.
196 return;
197 }
198 serial = map['params']['id'].toString();
199 response = map['params']['data'];
200 } else {
201 serial = map['id'];
202 response = map['response'];
203 }
204 if (serial == null) { 194 if (serial == null) {
205 // Messages without sequence numbers are asynchronous events 195 // Messages without serial numbers are asynchronous events
206 // from the vm. 196 // from the vm.
207 postEventMessage(response); 197 postServiceEvent(response, null);
208 return; 198 return;
209 } 199 }
210 // Complete request. 200 // Complete request.
211 var request = _pendingRequests.remove(serial); 201 var request = _pendingRequests.remove(serial);
212 if (request == null) { 202 if (request == null) {
213 Logger.root.severe('Received unexpected message: ${map}'); 203 Logger.root.severe('Received unexpected message: ${map}');
214 return; 204 return;
215 } 205 }
216 request.completer.complete(response); 206 request.completer.complete(response);
217 } 207 }
218 208
209 // WebSocket message event handler.
210 void _onMessage(dynamic data) {
211 if (data is! String) {
212 _onBinaryMessage(data);
213 } else {
214 _onStringMessage(data);
215 }
216 }
217
219 String _generateNetworkError(String userMessage) { 218 String _generateNetworkError(String userMessage) {
220 return JSON.encode({ 219 return JSON.encode({
221 'type': 'ServiceException', 220 'type': 'ServiceException',
222 'id': '', 221 'id': '',
223 'kind': 'NetworkException', 222 'kind': 'NetworkException',
224 'message': userMessage 223 'message': userMessage
225 }); 224 });
226 } 225 }
227 226
228 void _cancelRequests(Map<String, _WebSocketRequest> requests) { 227 void _cancelRequests(Map<String, _WebSocketRequest> requests) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 }); 281 });
283 } else { 282 } else {
284 message = JSON.encode({'id': serial, 283 message = JSON.encode({'id': serial,
285 'method': request.method, 284 'method': request.method,
286 'params': request.params}); 285 'params': request.params});
287 } 286 }
288 // Send message. 287 // Send message.
289 _webSocket.send(message); 288 _webSocket.send(message);
290 } 289 }
291 } 290 }
OLDNEW
« no previous file with comments | « no previous file | runtime/observatory/lib/src/elements/vm_view.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698