| 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 notifications.deleteDisconnectEvents(); |
| 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) { | |
| 82 notifications.removeWhere((notification) { | |
| 83 var event = notification.event; | |
| 84 return (event != null && | |
| 85 event.isolate == isolate && | |
| 86 event.isPauseEvent); | |
| 87 }); | |
| 88 } | |
| 89 | |
| 90 void _onEvent(ServiceEvent event) { | 71 void _onEvent(ServiceEvent event) { |
| 91 assert(event.kind != ServiceEvent.kNone); | 72 assert(event.kind != ServiceEvent.kNone); |
| 92 | 73 |
| 93 switch(event.kind) { | 74 switch(event.kind) { |
| 94 case ServiceEvent.kVMUpdate: | 75 case ServiceEvent.kVMUpdate: |
| 95 case ServiceEvent.kIsolateStart: | 76 case ServiceEvent.kIsolateStart: |
| 96 case ServiceEvent.kIsolateRunnable: | 77 case ServiceEvent.kIsolateRunnable: |
| 97 case ServiceEvent.kIsolateUpdate: | 78 case ServiceEvent.kIsolateUpdate: |
| 98 case ServiceEvent.kBreakpointAdded: | 79 case ServiceEvent.kBreakpointAdded: |
| 99 case ServiceEvent.kBreakpointResolved: | 80 case ServiceEvent.kBreakpointResolved: |
| 100 case ServiceEvent.kBreakpointRemoved: | 81 case ServiceEvent.kBreakpointRemoved: |
| 101 case ServiceEvent.kDebuggerSettingsUpdate: | 82 case ServiceEvent.kDebuggerSettingsUpdate: |
| 102 // Ignore for now. | 83 // Ignore for now. |
| 103 break; | 84 break; |
| 104 | 85 |
| 105 case ServiceEvent.kIsolateReload: | 86 case ServiceEvent.kIsolateReload: |
| 106 notifications.add(new Notification.fromEvent(event)); | 87 notifications.add(new EventNotification.fromServiceEvent(event)); |
| 107 break; | 88 break; |
| 108 | 89 |
| 109 case ServiceEvent.kIsolateExit: | 90 case ServiceEvent.kIsolateExit: |
| 110 case ServiceEvent.kResume: | 91 case ServiceEvent.kResume: |
| 111 removePauseEvents(event.isolate); | 92 notifications.deletePauseEvents(isolate: event.isolate); |
| 112 break; | 93 break; |
| 113 | 94 |
| 114 case ServiceEvent.kPauseStart: | 95 case ServiceEvent.kPauseStart: |
| 115 case ServiceEvent.kPauseExit: | 96 case ServiceEvent.kPauseExit: |
| 116 case ServiceEvent.kPauseBreakpoint: | 97 case ServiceEvent.kPauseBreakpoint: |
| 117 case ServiceEvent.kPauseInterrupted: | 98 case ServiceEvent.kPauseInterrupted: |
| 118 case ServiceEvent.kPauseException: | 99 case ServiceEvent.kPauseException: |
| 119 removePauseEvents(event.isolate); | 100 notifications.deletePauseEvents(isolate: event.isolate); |
| 120 notifications.add(new Notification.fromEvent(event)); | 101 notifications.add(new EventNotification.fromServiceEvent(event)); |
| 121 break; | 102 break; |
| 122 | 103 |
| 123 case ServiceEvent.kInspect: | 104 case ServiceEvent.kInspect: |
| 124 notifications.add(new Notification.fromEvent(event)); | 105 notifications.add(new EventNotification.fromServiceEvent(event)); |
| 125 break; | 106 break; |
| 126 | 107 |
| 127 default: | 108 default: |
| 128 // Ignore unrecognized events. | 109 // Ignore unrecognized events. |
| 129 Logger.root.severe('Unrecognized event: $event'); | 110 Logger.root.severe('Unrecognized event: $event'); |
| 130 break; | 111 break; |
| 131 } | 112 } |
| 132 } | 113 } |
| 133 | 114 |
| 134 void _registerPages() { | 115 void _registerPages() { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 currentPage = page; | 194 currentPage = page; |
| 214 } | 195 } |
| 215 | 196 |
| 216 ObservatoryApplication(this.rootElement) : | 197 ObservatoryApplication(this.rootElement) : |
| 217 targets = new TargetManager() { | 198 targets = new TargetManager() { |
| 218 _locationManager = new LocationManager(this); | 199 _locationManager = new LocationManager(this); |
| 219 vm = new WebSocketVM(targets.defaultTarget); | 200 vm = new WebSocketVM(targets.defaultTarget); |
| 220 _initOnce(); | 201 _initOnce(); |
| 221 } | 202 } |
| 222 | 203 |
| 223 void _removeDisconnectEvents() { | |
| 224 notifications.removeWhere((notification) { | |
| 225 var event = notification.event; | |
| 226 return (event != null && | |
| 227 event.kind == ServiceEvent.kConnectionClosed); | |
| 228 }); | |
| 229 } | |
| 230 | |
| 231 loadCrashDump(Map crashDump) { | 204 loadCrashDump(Map crashDump) { |
| 232 this.vm = new FakeVM(crashDump['result']); | 205 this.vm = new FakeVM(crashDump['result']); |
| 233 app.locationManager.go('#/vm'); | 206 app.locationManager.go('#/vm'); |
| 234 } | 207 } |
| 235 | 208 |
| 236 void handleException(e, st) { | 209 void handleException(e, st) { |
| 237 if (e is ServerRpcException) { | 210 if (e is ServerRpcException) { |
| 238 if (e.code == ServerRpcException.kFeatureDisabled) return; | 211 if (e.code == ServerRpcException.kFeatureDisabled) return; |
| 239 if (e.code == ServerRpcException.kIsolateMustBePaused) return; | 212 if (e.code == ServerRpcException.kIsolateMustBePaused) return; |
| 240 if (e.code == ServerRpcException.kCannotAddBreakpoint) return; | 213 if (e.code == ServerRpcException.kCannotAddBreakpoint) return; |
| 241 Logger.root.fine('Dropping exception: ${e}\n${st}'); | 214 Logger.root.fine('Dropping exception: ${e}\n${st}'); |
| 242 } | 215 } |
| 243 | 216 |
| 244 // TODO(turnidge): Report this failure via analytics. | 217 // TODO(turnidge): Report this failure via analytics. |
| 245 Logger.root.warning('Caught exception: ${e}\n${st}'); | 218 Logger.root.warning('Caught exception: ${e}\n${st}'); |
| 246 notifications.add(new Notification.fromException(e, st)); | 219 notifications.add(new ExceptionNotification(e, stacktrace: st)); |
| 247 } | 220 } |
| 248 | 221 |
| 249 // This map keeps track of which curly-blocks have been expanded by the user. | 222 // This map keeps track of which curly-blocks have been expanded by the user. |
| 250 Map<String,bool> expansions = {}; | 223 Map<String,bool> expansions = {}; |
| 251 } | 224 } |
| OLD | NEW |