OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 app; | 5 part of app; |
6 | 6 |
7 class Notification { | |
8 Notification.fromEvent(this.event); | |
9 Notification.fromException(this.exception, this.stacktrace); | |
10 | |
11 ServiceEvent event; | |
12 var exception; | |
13 var stacktrace; | |
14 } | |
15 | |
16 /// The observatory application. Instances of this are created and owned | 7 /// The observatory application. Instances of this are created and owned |
17 /// by the observatory_application custom element. | 8 /// by the observatory_application custom element. |
18 class ObservatoryApplication extends Observable { | 9 class ObservatoryApplication extends Observable { |
19 static ObservatoryApplication app; | 10 static ObservatoryApplication app; |
20 final RenderingQueue queue = new RenderingQueue(); | 11 final RenderingQueue queue = new RenderingQueue(); |
12 final NotificationRepository notifications = new NotificationRepository(); | |
21 final _pageRegistry = new List<Page>(); | 13 final _pageRegistry = new List<Page>(); |
22 LocationManager _locationManager; | 14 LocationManager _locationManager; |
23 LocationManager get locationManager => _locationManager; | 15 LocationManager get locationManager => _locationManager; |
24 @observable Page currentPage; | 16 @observable Page currentPage; |
25 VM _vm; | 17 VM _vm; |
26 VM get vm => _vm; | 18 VM get vm => _vm; |
27 | 19 |
28 set vm(VM vm) { | 20 set vm(VM vm) { |
29 if (_vm == vm) { | 21 if (_vm == vm) { |
30 // Do nothing. | 22 // Do nothing. |
31 return; | 23 return; |
32 } | 24 } |
33 if (_vm != null) { | 25 if (_vm != null) { |
34 // Disconnect from current VM. | 26 // Disconnect from current VM. |
35 notifications.clear(); | 27 notifications.deleteAll(); |
36 _vm.disconnect(); | 28 _vm.disconnect(); |
37 } | 29 } |
38 if (vm != null) { | 30 if (vm != null) { |
39 Logger.root.info('Registering new VM callbacks'); | 31 Logger.root.info('Registering new VM callbacks'); |
40 | 32 |
41 vm.onConnect.then((_) { | 33 vm.onConnect.then((_) { |
42 if (vm is WebSocketVM) { | 34 if (vm is WebSocketVM) { |
43 targets.add(vm.target); | 35 targets.add(vm.target); |
44 } | 36 } |
45 _removeDisconnectEvents(); | 37 _removeDisconnectEvents(); |
46 }); | 38 }); |
47 | 39 |
48 vm.onDisconnect.then((String reason) { | 40 vm.onDisconnect.then((String reason) { |
49 if (this.vm != vm) { | 41 if (this.vm != vm) { |
50 // This disconnect event occured *after* a new VM was installed. | 42 // This disconnect event occured *after* a new VM was installed. |
51 return; | 43 return; |
52 } | 44 } |
53 notifications.add( | 45 notifications.add( |
54 new Notification.fromEvent( | 46 new EventNotification.fromServiceEvent( |
55 new ServiceEvent.connectionClosed(reason))); | 47 new ServiceEvent.connectionClosed(reason))); |
56 }); | 48 }); |
57 | 49 |
58 vm.listenEventStream(VM.kIsolateStream, _onEvent); | 50 vm.listenEventStream(VM.kIsolateStream, _onEvent); |
59 vm.listenEventStream(VM.kDebugStream, _onEvent); | 51 vm.listenEventStream(VM.kDebugStream, _onEvent); |
60 } | 52 } |
61 _vm = vm; | 53 _vm = vm; |
62 } | 54 } |
63 final TargetManager targets; | 55 final TargetManager targets; |
64 @reflectable final ObservatoryApplicationElement rootElement; | 56 @reflectable final ObservatoryApplicationElement rootElement; |
65 | 57 |
66 TraceViewElement _traceView = null; | 58 TraceViewElement _traceView = null; |
67 | 59 |
68 @reflectable ServiceObject lastErrorOrException; | 60 @reflectable ServiceObject lastErrorOrException; |
69 @observable ObservableList<Notification> notifications = | |
70 new ObservableList<Notification>(); | |
71 | 61 |
72 void _initOnce() { | 62 void _initOnce() { |
73 assert(app == null); | 63 assert(app == null); |
74 app = this; | 64 app = this; |
75 _registerPages(); | 65 _registerPages(); |
76 Analytics.initialize(); | 66 Analytics.initialize(); |
77 // Visit the current page. | 67 // Visit the current page. |
78 locationManager._visit(); | 68 locationManager._visit(); |
79 } | 69 } |
80 | 70 |
81 void removePauseEvents(Isolate isolate) { | 71 void removePauseEvents(Isolate isolate) { |
Cutch
2016/07/22 13:58:43
Should this method be on the NotificationRepositor
cbernaschina
2016/07/22 18:27:24
Done.
| |
82 notifications.removeWhere((notification) { | 72 var remove = notifications.list().where((notification) { |
83 var event = notification.event; | 73 var event = notification.event; |
84 return (event != null && | 74 return notification is M.EventNotification && |
85 event.isolate == isolate && | 75 notification.event is M.IsolateEvent && |
86 event.isPauseEvent); | 76 notification.event.isolate == isolate && |
87 }); | 77 M.Event.isPauseEvent(notification.event); |
78 }).toList(growable: false); | |
79 remove.forEach((notification) { | |
80 notifications.delete(notification); | |
81 }); | |
88 } | 82 } |
89 | 83 |
90 void _onEvent(ServiceEvent event) { | 84 void _onEvent(ServiceEvent event) { |
91 assert(event.kind != ServiceEvent.kNone); | 85 assert(event.kind != ServiceEvent.kNone); |
92 | 86 |
93 switch(event.kind) { | 87 switch(event.kind) { |
94 case ServiceEvent.kVMUpdate: | 88 case ServiceEvent.kVMUpdate: |
95 case ServiceEvent.kIsolateStart: | 89 case ServiceEvent.kIsolateStart: |
96 case ServiceEvent.kIsolateRunnable: | 90 case ServiceEvent.kIsolateRunnable: |
97 case ServiceEvent.kIsolateUpdate: | 91 case ServiceEvent.kIsolateUpdate: |
98 case ServiceEvent.kBreakpointAdded: | 92 case ServiceEvent.kBreakpointAdded: |
99 case ServiceEvent.kBreakpointResolved: | 93 case ServiceEvent.kBreakpointResolved: |
100 case ServiceEvent.kBreakpointRemoved: | 94 case ServiceEvent.kBreakpointRemoved: |
101 case ServiceEvent.kDebuggerSettingsUpdate: | 95 case ServiceEvent.kDebuggerSettingsUpdate: |
102 // Ignore for now. | 96 // Ignore for now. |
103 break; | 97 break; |
104 | 98 |
105 case ServiceEvent.kIsolateReload: | 99 case ServiceEvent.kIsolateReload: |
106 notifications.add(new Notification.fromEvent(event)); | 100 notifications.add(new EventNotification.fromServiceEvent(event)); |
107 break; | 101 break; |
108 | 102 |
109 case ServiceEvent.kIsolateExit: | 103 case ServiceEvent.kIsolateExit: |
110 case ServiceEvent.kResume: | 104 case ServiceEvent.kResume: |
111 removePauseEvents(event.isolate); | 105 removePauseEvents(event.isolate); |
112 break; | 106 break; |
113 | 107 |
114 case ServiceEvent.kPauseStart: | 108 case ServiceEvent.kPauseStart: |
115 case ServiceEvent.kPauseExit: | 109 case ServiceEvent.kPauseExit: |
116 case ServiceEvent.kPauseBreakpoint: | 110 case ServiceEvent.kPauseBreakpoint: |
117 case ServiceEvent.kPauseInterrupted: | 111 case ServiceEvent.kPauseInterrupted: |
118 case ServiceEvent.kPauseException: | 112 case ServiceEvent.kPauseException: |
119 removePauseEvents(event.isolate); | 113 removePauseEvents(event.isolate); |
120 notifications.add(new Notification.fromEvent(event)); | 114 notifications.add(new EventNotification.fromServiceEvent(event)); |
121 break; | 115 break; |
122 | 116 |
123 case ServiceEvent.kInspect: | 117 case ServiceEvent.kInspect: |
124 notifications.add(new Notification.fromEvent(event)); | 118 notifications.add(new EventNotification.fromServiceEvent(event)); |
125 break; | 119 break; |
126 | 120 |
127 default: | 121 default: |
128 // Ignore unrecognized events. | 122 // Ignore unrecognized events. |
129 Logger.root.severe('Unrecognized event: $event'); | 123 Logger.root.severe('Unrecognized event: $event'); |
130 break; | 124 break; |
131 } | 125 } |
132 } | 126 } |
133 | 127 |
134 void _registerPages() { | 128 void _registerPages() { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 } | 208 } |
215 | 209 |
216 ObservatoryApplication(this.rootElement) : | 210 ObservatoryApplication(this.rootElement) : |
217 targets = new TargetManager() { | 211 targets = new TargetManager() { |
218 _locationManager = new LocationManager(this); | 212 _locationManager = new LocationManager(this); |
219 vm = new WebSocketVM(targets.defaultTarget); | 213 vm = new WebSocketVM(targets.defaultTarget); |
220 _initOnce(); | 214 _initOnce(); |
221 } | 215 } |
222 | 216 |
223 void _removeDisconnectEvents() { | 217 void _removeDisconnectEvents() { |
224 notifications.removeWhere((notification) { | 218 var remove = notifications.list().where((notification) { |
Cutch
2016/07/22 13:58:43
same question.
cbernaschina
2016/07/22 18:27:24
Done.
| |
225 var event = notification.event; | 219 return notification is EventNotification && |
226 return (event != null && | 220 notification.event is M.ConnectionClosedEvent; |
227 event.kind == ServiceEvent.kConnectionClosed); | 221 }).toList(growable: false); |
228 }); | 222 remove.forEach((notification){ |
223 notifications.delete(notification); | |
224 }); | |
229 } | 225 } |
230 | 226 |
231 loadCrashDump(Map crashDump) { | 227 loadCrashDump(Map crashDump) { |
232 this.vm = new FakeVM(crashDump['result']); | 228 this.vm = new FakeVM(crashDump['result']); |
233 app.locationManager.go('#/vm'); | 229 app.locationManager.go('#/vm'); |
234 } | 230 } |
235 | 231 |
236 void handleException(e, st) { | 232 void handleException(e, st) { |
237 if (e is ServerRpcException) { | 233 if (e is ServerRpcException) { |
238 if (e.code == ServerRpcException.kFeatureDisabled) return; | 234 if (e.code == ServerRpcException.kFeatureDisabled) return; |
239 if (e.code == ServerRpcException.kIsolateMustBePaused) return; | 235 if (e.code == ServerRpcException.kIsolateMustBePaused) return; |
240 if (e.code == ServerRpcException.kCannotAddBreakpoint) return; | 236 if (e.code == ServerRpcException.kCannotAddBreakpoint) return; |
241 Logger.root.fine('Dropping exception: ${e}\n${st}'); | 237 Logger.root.fine('Dropping exception: ${e}\n${st}'); |
242 } | 238 } |
243 | 239 |
244 // TODO(turnidge): Report this failure via analytics. | 240 // TODO(turnidge): Report this failure via analytics. |
245 Logger.root.warning('Caught exception: ${e}\n${st}'); | 241 Logger.root.warning('Caught exception: ${e}\n${st}'); |
246 notifications.add(new Notification.fromException(e, st)); | 242 notifications.add(new ExceptionNotification(e, stacktrace: st)); |
247 } | 243 } |
248 | 244 |
249 // This map keeps track of which curly-blocks have been expanded by the user. | 245 // This map keeps track of which curly-blocks have been expanded by the user. |
250 Map<String,bool> expansions = {}; | 246 Map<String,bool> expansions = {}; |
251 } | 247 } |
OLD | NEW |