| OLD | NEW |
| 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 app; | 5 part of app; |
| 6 | 6 |
| 7 /// A [Page] controls the user interface of Observatory. At any given time | 7 /// A [Page] controls the user interface of Observatory. At any given time |
| 8 /// one page will be the current page. Pages are registered at startup. | 8 /// one page will be the current page. Pages are registered at startup. |
| 9 /// When the user navigates within the application, each page is asked if it | 9 /// When the user navigates within the application, each page is asked if it |
| 10 /// can handle the current location, the first page to say yes, wins. | 10 /// can handle the current location, the first page to say yes, wins. |
| 11 abstract class Page extends Observable { | 11 abstract class Page extends Observable { |
| 12 final ObservatoryApplication app; | 12 final ObservatoryApplication app; |
| 13 | 13 final ObservableMap<String, String> internalArguments = |
| 14 new ObservableMap<String, String>(); |
| 14 @observable ObservatoryElement element; | 15 @observable ObservatoryElement element; |
| 15 @observable ObservableMap args; | |
| 16 | 16 |
| 17 Page(this.app); | 17 Page(this.app); |
| 18 | 18 |
| 19 /// Called when the page is installed, this callback must initialize | 19 /// Called when the page is installed, this callback must initialize |
| 20 /// [element]. | 20 /// [element]. |
| 21 void onInstall(); | 21 void onInstall(); |
| 22 | 22 |
| 23 /// Called when the page is uninstalled, this callback must clear | 23 /// Called when the page is uninstalled, this callback must clear |
| 24 /// [element]. | 24 /// [element]. |
| 25 void onUninstall() { | 25 void onUninstall() { |
| 26 element = null; | 26 element = null; |
| 27 } | 27 } |
| 28 | 28 |
| 29 /// Called when the page should update its state based on [uri]. | 29 /// Called when the page should update its state based on [uri]. |
| 30 /// NOTE: Only called when the page is installed. | 30 void visit(Uri uri, Map internalArguments) { |
| 31 void visit(Uri uri, Map argsMap) { | 31 this.internalArguments.clear(); |
| 32 args = toObservable(argsMap); | 32 this.internalArguments.addAll(internalArguments); |
| 33 _visit(uri); | 33 _visit(uri); |
| 34 } | 34 } |
| 35 | 35 |
| 36 // Overridden by subclasses. | 36 // Overridden by subclasses. |
| 37 void _visit(Uri uri); | 37 void _visit(Uri uri); |
| 38 | 38 |
| 39 /// Called to test whether this page can visit [uri]. | 39 /// Called to test whether this page can visit [uri]. |
| 40 bool canVisit(Uri uri); | 40 bool canVisit(Uri uri); |
| 41 } | 41 } |
| 42 | 42 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 getIsolate(uri).then((isolate) { | 197 getIsolate(uri).then((isolate) { |
| 198 if (element != null) { | 198 if (element != null) { |
| 199 /// Update the page. | 199 /// Update the page. |
| 200 CpuProfileElement page = element; | 200 CpuProfileElement page = element; |
| 201 page.isolate = isolate; | 201 page.isolate = isolate; |
| 202 } | 202 } |
| 203 }); | 203 }); |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 class TableCpuProfilerPage extends SimplePage { |
| 208 TableCpuProfilerPage(app) |
| 209 : super('profiler-table', 'cpu-profile-table', app); |
| 210 |
| 211 void _visit(Uri uri) { |
| 212 super._visit(uri); |
| 213 getIsolate(uri).then((isolate) { |
| 214 if (element != null) { |
| 215 /// Update the page. |
| 216 CpuProfileTableElement page = element; |
| 217 page.isolate = isolate; |
| 218 // TODO(johnmccutchan): Provide a more general mechanism to notify |
| 219 // elements of URI parameter changes. Possibly via a stream off of |
| 220 // LocationManager. With a stream individual elements (not just pages) |
| 221 // could be notified. |
| 222 page.checkParameters(); |
| 223 } |
| 224 }); |
| 225 } |
| 226 } |
| 227 |
| 207 class AllocationProfilerPage extends SimplePage { | 228 class AllocationProfilerPage extends SimplePage { |
| 208 AllocationProfilerPage(app) | 229 AllocationProfilerPage(app) |
| 209 : super('allocation-profiler', 'heap-profile', app); | 230 : super('allocation-profiler', 'heap-profile', app); |
| 210 | 231 |
| 211 void _visit(Uri uri) { | 232 void _visit(Uri uri) { |
| 212 super._visit(uri); | 233 super._visit(uri); |
| 213 getIsolate(uri).then((isolate) { | 234 getIsolate(uri).then((isolate) { |
| 214 if (element != null) { | 235 if (element != null) { |
| 215 /// Update the page. | 236 /// Update the page. |
| 216 HeapProfileElement page = element; | 237 HeapProfileElement page = element; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 void _visit(Uri uri) { | 346 void _visit(Uri uri) { |
| 326 assert(element != null); | 347 assert(element != null); |
| 327 assert(canVisit(uri)); | 348 assert(canVisit(uri)); |
| 328 app.vm.getIsolate(uri.queryParameters['isolateId']).then((i) { | 349 app.vm.getIsolate(uri.queryParameters['isolateId']).then((i) { |
| 329 (element as MetricsPageElement).isolate = i; | 350 (element as MetricsPageElement).isolate = i; |
| 330 }); | 351 }); |
| 331 } | 352 } |
| 332 | 353 |
| 333 bool canVisit(Uri uri) => uri.path == 'metrics'; | 354 bool canVisit(Uri uri) => uri.path == 'metrics'; |
| 334 } | 355 } |
| OLD | NEW |