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

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

Issue 203243006: Move all service objects to one file ahead of refactor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: gen js / fix bug Created 6 years, 9 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
8 /// to an owning [Isolate].
9 abstract class ServiceObject extends Observable {
10 Isolate _isolate;
11
12 /// Owning isolate.
13 @reflectable Isolate get isolate => _isolate;
14
15 /// Owning vm.
16 @reflectable VM get vm => _isolate.vm;
17
18 /// The complete service url of this object.
19 @reflectable String get link => isolate.relativeLink(_id);
20
21 /// The complete service url of this object with a '#/' prefix.
22 @reflectable String get hashLink => isolate.relativeHashLink(_id);
23 set hashLink(var o) { /* silence polymer */ }
24
25 String _id;
26 /// The id of this object.
27 @reflectable String get id => _id;
28
29 String _serviceType;
30 /// The service type of this object.
31 @reflectable String get serviceType => _serviceType;
32
33 bool _ref;
34
35 @observable String name;
36 @observable String vmName;
37
38 ServiceObject(this._isolate, this._id, this._serviceType) {
39 _ref = isRefType(_serviceType);
40 _serviceType = stripRef(_serviceType);
41 _created();
42 }
43
44 ServiceObject.fromMap(this._isolate, ObservableMap m) {
45 assert(isServiceMap(m));
46 _id = m['id'];
47 _ref = isRefType(m['type']);
48 _serviceType = stripRef(m['type']);
49 _created();
50 update(m);
51 }
52
53 /// If [this] was created from a reference, load the full object
54 /// from the service by calling [reload]. Else, return [this].
55 Future<ServiceObject> load() {
56 if (!_ref) {
57 // Not a reference.
58 return new Future.value(this);
59 }
60 // Call reload which will fill in the entire object.
61 return reload();
62 }
63
64 /// Reload [this]. Returns a future which completes to [this] or
65 /// a [ServiceError].
66 Future<ServiceObject> reload() {
67 assert(isolate != null);
68 if (id == '') {
69 // Errors don't have ids.
70 assert(serviceType == 'Error');
71 return new Future.value(this);
72 }
73 return isolate.vm.getAsMap(link).then(update);
74 }
75
76 /// Update [this] using [m] as a source. [m] can be a reference.
77 ServiceObject update(ObservableMap m) {
78 // Assert that m is a service map.
79 assert(ServiceObject.isServiceMap(m));
80 if ((m['type'] == 'Error') && (_serviceType != 'Error')) {
81 // Got an unexpected error. Don't update the object.
82 return _upgradeToServiceObject(vm, isolate, m);
83 }
84 // TODO(johnmccutchan): Should we allow for a ServiceObject's id
85 // or type to change?
86 _id = m['id'];
87 _serviceType = stripRef(m['type']);
88 _update(m);
89 return this;
90 }
91
92 // update internal state from [map]. [map] can be a reference.
93 void _update(ObservableMap map);
94
95 /// Returns true if [this] has only been partially initialized via
96 /// a reference. See [load].
97 bool isRef() => _ref;
98
99 void _created() {
100 var refNotice = _ref ? ' Created from reference.' : '';
101 Logger.root.info('Created ServiceObject for \'${_id}\' with type '
102 '\'${_serviceType}\'.' + refNotice);
103 }
104
105 /// Returns true if [map] is a service map. i.e. it has the following keys:
106 /// 'id' and a 'type'.
107 static bool isServiceMap(ObservableMap m) {
108 return (m != null) && (m['id'] != null) && (m['type'] != null);
109 }
110
111 /// Returns true if [type] is a reference type. i.e. it begins with an
112 /// '@' character.
113 static bool isRefType(String type) {
114 return type.startsWith('@');
115 }
116
117 /// Returns the unreffed version of [type].
118 static String stripRef(String type) {
119 if (!isRefType(type)) {
120 return type;
121 }
122 // Strip off the '@' character.
123 return type.substring(1);
124 }
125 }
126
127 /// Recursively upgrades all [ServiceObject]s inside [collection] which must 7 /// Recursively upgrades all [ServiceObject]s inside [collection] which must
128 /// be an [ObservableMap] or an [ObservableList]. Upgraded elements will be 8 /// be an [ObservableMap] or an [ObservableList]. Upgraded elements will be
129 /// associated with [vm] and [isolate]. 9 /// associated with [vm] and [isolate].
130 void upgradeCollection(collection, VM vm, Isolate isolate) { 10 void upgradeCollection(collection, VM vm, Isolate isolate) {
131 if (collection is ObservableMap) { 11 if (collection is ObservableMap) {
132 _upgradeObservableMap(collection, vm, isolate); 12 _upgradeObservableMap(collection, vm, isolate);
133 } else if (collection is ObservableList) { 13 } else if (collection is ObservableList) {
134 _upgradeObservableList(collection, vm, isolate); 14 _upgradeObservableList(collection, vm, isolate);
135 } 15 }
136 } 16 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 return isolate.codes.putIfAbsent(m); 64 return isolate.codes.putIfAbsent(m);
185 case 'Isolate': 65 case 'Isolate':
186 return vm.isolates.getIsolateFromMap(m); 66 return vm.isolates.getIsolateFromMap(m);
187 case 'Class': 67 case 'Class':
188 return isolate.classes.putIfAbsent(m); 68 return isolate.classes.putIfAbsent(m);
189 case 'Function': 69 case 'Function':
190 return isolate.functions.putIfAbsent(m); 70 return isolate.functions.putIfAbsent(m);
191 } 71 }
192 return new ServiceMap.fromMap(isolate, m); 72 return new ServiceMap.fromMap(isolate, m);
193 } 73 }
OLDNEW
« no previous file with comments | « runtime/bin/vmservice/client/lib/src/service/object.dart ('k') | runtime/bin/vmservice/client/lib/src/service/vm.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698