| 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 observatory; | 5 part of app; |
| 6 |
| 7 /// A request response interceptor is called for each response. |
| 8 typedef void RequestResponseInterceptor(); |
| 6 | 9 |
| 7 /// The observatory application. Instances of this are created and owned | 10 /// The observatory application. Instances of this are created and owned |
| 8 /// by the observatory_application custom element. | 11 /// by the observatory_application custom element. |
| 9 class ObservatoryApplication extends Observable { | 12 class ObservatoryApplication extends Observable { |
| 10 @observable final LocationManager locationManager; | 13 @observable final LocationManager locationManager; |
| 11 @observable final RequestManager requestManager; | 14 @observable final VM vm; |
| 12 @observable final IsolateManager isolateManager; | 15 @observable Map response; |
| 16 @observable Isolate isolate; |
| 17 |
| 18 void setResponse(Map response) { |
| 19 this.response = toObservable(response); |
| 20 } |
| 21 |
| 22 void setResponseError(String message, [String errorType = 'ResponseError']) { |
| 23 this.response = toObservable({ |
| 24 'type': 'Error', |
| 25 'errorType': errorType, |
| 26 'text': message |
| 27 }); |
| 28 Logger.root.severe(message); |
| 29 } |
| 13 | 30 |
| 14 void _setup() { | 31 void _setup() { |
| 15 locationManager._application = this; | 32 vm._app = this; |
| 16 requestManager._application = this; | 33 locationManager._app = this; |
| 17 isolateManager._application = this; | |
| 18 Isolate._application = this; | |
| 19 requestManager.interceptor = isolateManager._responseInterceptor; | |
| 20 locationManager.init(); | 34 locationManager.init(); |
| 21 } | 35 } |
| 22 | 36 |
| 23 ObservatoryApplication.devtools() : | 37 ObservatoryApplication.devtools() : |
| 24 locationManager = new LocationManager(), | 38 locationManager = new LocationManager(), |
| 25 requestManager = new PostMessageRequestManager(), | 39 vm = new DartiumVM() { |
| 26 isolateManager = new IsolateManager() { | |
| 27 _setup(); | 40 _setup(); |
| 28 } | 41 } |
| 29 | 42 |
| 30 ObservatoryApplication() : | 43 ObservatoryApplication() : |
| 31 locationManager = new LocationManager(), | 44 locationManager = new LocationManager(), |
| 32 requestManager = new HttpRequestManager(), | 45 vm = new HttpVM('http://127.0.0.1:8181/') { |
| 33 isolateManager = new IsolateManager() { | |
| 34 _setup(); | 46 _setup(); |
| 35 } | 47 } |
| 36 | 48 |
| 37 /// Return the [Isolate] with [id]. | |
| 38 Isolate getIsolate(int id) { | |
| 39 return isolateManager.isolates[id]; | |
| 40 } | |
| 41 | |
| 42 /// Return the name of the isolate with [id]. | |
| 43 String getIsolateName(int id) { | |
| 44 var isolate = getIsolate(id); | |
| 45 if (isolate == null) { | |
| 46 return 'Null Isolate'; | |
| 47 } | |
| 48 return isolate.name; | |
| 49 } | |
| 50 | |
| 51 static const int KB = 1024; | 49 static const int KB = 1024; |
| 52 static const int MB = KB * 1024; | 50 static const int MB = KB * 1024; |
| 53 static String scaledSizeUnits(int x) { | 51 static String scaledSizeUnits(int x) { |
| 54 if (x > 2 * MB) { | 52 if (x > 2 * MB) { |
| 55 var y = x / MB; | 53 var y = x / MB; |
| 56 return '${y.toStringAsFixed(1)} MB'; | 54 return '${y.toStringAsFixed(1)} MB'; |
| 57 } else if (x > 2 * KB) { | 55 } else if (x > 2 * KB) { |
| 58 var y = x / KB; | 56 var y = x / KB; |
| 59 return '${y.toStringAsFixed(1)} KB'; | 57 return '${y.toStringAsFixed(1)} KB'; |
| 60 } | 58 } |
| 61 var y = x.toDouble(); | 59 var y = x.toDouble(); |
| 62 return '${y.toStringAsFixed(1)} B'; | 60 return '${y.toStringAsFixed(1)} B'; |
| 63 } | 61 } |
| 64 | 62 |
| 65 static String timeUnits(double x) { | 63 static String timeUnits(double x) { |
| 66 return x.toStringAsFixed(2); | 64 return x.toStringAsFixed(2); |
| 67 } | 65 } |
| 68 } | 66 } |
| OLD | NEW |