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

Side by Side Diff: runtime/bin/vmservice/client/lib/src/service/object.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 /// State for a VM being inspected.
128 abstract class VM extends Observable {
129 @reflectable IsolateList _isolates;
130 @reflectable IsolateList get isolates => _isolates;
131
132 void _initOnce() {
133 assert(_isolates == null);
134 _isolates = new IsolateList(this);
135 }
136
137 VM() {
138 _initOnce();
139 }
140
141 /// Get [id] as an [ObservableMap] from the service directly.
142 Future<ObservableMap> getAsMap(String id) {
143 return getString(id).then((response) {
144 try {
145 var map = JSON.decode(response);
146 Logger.root.info('Decoded $id');
147 return toObservable(map);
148 } catch (e, st) {
149 return toObservable({
150 'type': 'Error',
151 'id': '',
152 'kind': 'DecodeError',
153 'message': '$e',
154 });
155 }
156 }).catchError((error) {
157 return toObservable({
158 'type': 'Error',
159 'id': '',
160 'kind': 'LastResort',
161 'message': '$error'
162 });
163 });
164 }
165
166 /// Get [id] as a [String] from the service directly. See [getAsMap].
167 Future<String> getString(String id);
168 }
169
7 /// State for a running isolate. 170 /// State for a running isolate.
8 class Isolate extends ServiceObject { 171 class Isolate extends ServiceObject {
9 final VM vm; 172 final VM vm;
10 String get link => _id; 173 String get link => _id;
11 String get hashLink => '#/$_id'; 174 String get hashLink => '#/$_id';
12 175
13 ScriptCache _scripts; 176 ScriptCache _scripts;
14 /// Script cache. 177 /// Script cache.
15 ScriptCache get scripts => _scripts; 178 ScriptCache get scripts => _scripts;
16 CodeCache _codes; 179 CodeCache _codes;
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 799
637 int _callCount(List<CodeCallCount> calls, Code code) { 800 int _callCount(List<CodeCallCount> calls, Code code) {
638 for (CodeCallCount caller in calls) { 801 for (CodeCallCount caller in calls) {
639 if (caller.code == code) { 802 if (caller.code == code) {
640 return caller.count; 803 return caller.count;
641 } 804 }
642 } 805 }
643 return 0; 806 return 0;
644 } 807 }
645 } 808 }
OLDNEW
« no previous file with comments | « runtime/bin/vmservice/client/lib/service.dart ('k') | runtime/bin/vmservice/client/lib/src/service/service.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698