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

Side by Side Diff: runtime/bin/vmservice/client/lib/src/service/object.dart

Issue 335463008: Allow Observatory to run as a hosted web service (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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) 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 part of service; 5 part of service;
6 6
7 /// A [ServiceObject] is an object known to the VM service and is tied 7 /// A [ServiceObject] is an object known to the VM service and is tied
8 /// to an owning [Isolate]. 8 /// to an owning [Isolate].
9 abstract class ServiceObject extends Observable { 9 abstract class ServiceObject extends Observable {
10 /// The owner of this [ServiceObject]. This can be an [Isolate], a 10 /// The owner of this [ServiceObject]. This can be an [Isolate], a
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 'message': 'Could not decode JSON: $e', 370 'message': 'Could not decode JSON: $e',
371 }))); 371 })));
372 } 372 }
373 373
374 /// Gets [id] as an [ObservableMap] from the service directly. If 374 /// Gets [id] as an [ObservableMap] from the service directly. If
375 /// an error occurs, the future is completed as an error with a 375 /// an error occurs, the future is completed as an error with a
376 /// ServiceError or ServiceException. Therefore any chained then() calls 376 /// ServiceError or ServiceException. Therefore any chained then() calls
377 /// will only receive a map encoding a valid ServiceObject. 377 /// will only receive a map encoding a valid ServiceObject.
378 Future<ObservableMap> getAsMap(String id) { 378 Future<ObservableMap> getAsMap(String id) {
379 return getString(id).then((response) { 379 return getString(id).then((response) {
380 var map; 380 var map = _parseJSON(response);
381 try {
382 map = _parseJSON(response);
383 } catch (e, st) {
384 print('Hit V8 bug.');
385 return _decodeError(e);
386 }
387 return _processMap(map); 381 return _processMap(map);
388 }).catchError((error) { 382 }).catchError((error) {
389 // ServiceError, forward to VM's ServiceError stream. 383 // ServiceError, forward to VM's ServiceError stream.
390 errors.add(error); 384 errors.add(error);
391 return new Future.error(error); 385 return new Future.error(error);
392 }, test: (e) => e is ServiceError).catchError((exception) { 386 }, test: (e) => e is ServiceError).catchError((exception) {
393 // ServiceException, forward to VM's ServiceException stream. 387 // ServiceException, forward to VM's ServiceException stream.
394 exceptions.add(exception); 388 exceptions.add(exception);
395 return new Future.error(exception); 389 return new Future.error(exception);
396 }, test: (e) => e is ServiceException); 390 }, test: (e) => e is ServiceException);
397 } 391 }
398 392
399 /// Get [id] as a [String] from the service directly. See [getAsMap]. 393 /// Get [id] as a [String] from the service directly. See [getAsMap].
400 Future<String> getString(String id); 394 Future<String> getString(String id);
395 /// Force the VM to disconnect.
396 void disconnect();
397 /// Completes when the VM first connects.
398 Future get onConnect;
399 /// Completes when the VM disconnects or there was an error connecting.
400 Future get onDisconnect;
401 401
402 void _update(ObservableMap map, bool mapIsRef) { 402 void _update(ObservableMap map, bool mapIsRef) {
403 if (mapIsRef) { 403 if (mapIsRef) {
404 return; 404 return;
405 } 405 }
406 _loaded = true; 406 _loaded = true;
407 version = map['version']; 407 version = map['version'];
408 architecture = map['architecture']; 408 architecture = map['architecture'];
409 uptime = map['uptime']; 409 uptime = map['uptime'];
410 var dateInMillis = int.parse(map['date']); 410 var dateInMillis = int.parse(map['date']);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 662
663 Future<ServiceObject> get(String id) { 663 Future<ServiceObject> get(String id) {
664 // Do not allow null ids or empty ids. 664 // Do not allow null ids or empty ids.
665 assert(id != null && id != ''); 665 assert(id != null && id != '');
666 var obj = _cache[id]; 666 var obj = _cache[id];
667 if (obj != null) { 667 if (obj != null) {
668 return obj.reload(); 668 return obj.reload();
669 } 669 }
670 // Cache miss. Get the object from the vm directly. 670 // Cache miss. Get the object from the vm directly.
671 return vm.getAsMap(relativeLink(id)).then((ObservableMap map) { 671 return vm.getAsMap(relativeLink(id)).then((ObservableMap map) {
672 var obj = new ServiceObject._fromMap(this, map); 672 var obj = new ServiceObject._fromMap(this, map);
673 if (obj.canCache) { 673 if (obj.canCache) {
674 _cache.putIfAbsent(id, () => obj); 674 _cache.putIfAbsent(id, () => obj);
675 } 675 }
676 return obj; 676 return obj;
677 }); 677 });
678 } 678 }
679 679
680 @observable Class objectClass; 680 @observable Class objectClass;
681 @observable final rootClasses = new ObservableList<Class>(); 681 @observable final rootClasses = new ObservableList<Class>();
682 682
683 @observable Library rootLib; 683 @observable Library rootLib;
684 @observable ObservableList<Library> libraries = 684 @observable ObservableList<Library> libraries =
685 new ObservableList<Library>(); 685 new ObservableList<Library>();
686 @observable ObservableMap topFrame; 686 @observable ObservableMap topFrame;
687 687
(...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 var v = list[i]; 1840 var v = list[i];
1841 if ((v is ObservableMap) && _isServiceMap(v)) { 1841 if ((v is ObservableMap) && _isServiceMap(v)) {
1842 list[i] = owner.getFromMap(v); 1842 list[i] = owner.getFromMap(v);
1843 } else if (v is ObservableList) { 1843 } else if (v is ObservableList) {
1844 _upgradeObservableList(v, owner); 1844 _upgradeObservableList(v, owner);
1845 } else if (v is ObservableMap) { 1845 } else if (v is ObservableMap) {
1846 _upgradeObservableMap(v, owner); 1846 _upgradeObservableMap(v, owner);
1847 } 1847 }
1848 } 1848 }
1849 } 1849 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698