| 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 IsolateSampleProfileRepository _isolateSampleProfileRepository |
| 8 = new IsolateSampleProfileRepository(); |
| 9 |
| 7 class IsolateNotFound implements Exception { | 10 class IsolateNotFound implements Exception { |
| 8 String isolateId; | 11 String isolateId; |
| 9 IsolateNotFound(this.isolateId); | 12 IsolateNotFound(this.isolateId); |
| 10 String toString() => "IsolateNotFound: $isolateId"; | 13 String toString() => "IsolateNotFound: $isolateId"; |
| 11 } | 14 } |
| 12 | 15 |
| 13 /// A [Page] controls the user interface of Observatory. At any given time | 16 /// A [Page] controls the user interface of Observatory. At any given time |
| 14 /// one page will be the current page. Pages are registered at startup. | 17 /// one page will be the current page. Pages are registered at startup. |
| 15 /// When the user navigates within the application, each page is asked if it | 18 /// When the user navigates within the application, each page is asked if it |
| 16 /// can handle the current location, the first page to say yes, wins. | 19 /// can handle the current location, the first page to say yes, wins. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 40 _visit(uri); | 43 _visit(uri); |
| 41 } | 44 } |
| 42 | 45 |
| 43 // Overridden by subclasses. | 46 // Overridden by subclasses. |
| 44 void _visit(Uri uri); | 47 void _visit(Uri uri); |
| 45 | 48 |
| 46 /// Called to test whether this page can visit [uri]. | 49 /// Called to test whether this page can visit [uri]. |
| 47 bool canVisit(Uri uri); | 50 bool canVisit(Uri uri); |
| 48 } | 51 } |
| 49 | 52 |
| 50 /// A [SimplePage] matches a single uri path and displays a single element. | 53 /// A [MatchingPage] matches a single uri path. |
| 51 class SimplePage extends Page { | 54 abstract class MatchingPage extends Page { |
| 52 final String path; | 55 final String path; |
| 53 final String elementTagName; | 56 MatchingPage(this.path, app) : super(app); |
| 54 SimplePage(this.path, this.elementTagName, app) : super(app); | |
| 55 | |
| 56 void onInstall() { | |
| 57 if (element == null) { | |
| 58 element = new Element.tag(elementTagName); | |
| 59 } | |
| 60 } | |
| 61 | 57 |
| 62 void _visit(Uri uri) { | 58 void _visit(Uri uri) { |
| 63 assert(uri != null); | 59 assert(uri != null); |
| 64 assert(canVisit(uri)); | 60 assert(canVisit(uri)); |
| 65 } | 61 } |
| 66 | 62 |
| 67 Future<Isolate> getIsolate(Uri uri) { | 63 Future<Isolate> getIsolate(Uri uri) { |
| 68 var isolateId = uri.queryParameters['isolateId']; | 64 var isolateId = uri.queryParameters['isolateId']; |
| 69 return app.vm.getIsolate(isolateId).then((isolate) { | 65 return app.vm.getIsolate(isolateId).then((isolate) { |
| 70 if (isolate == null) { | 66 if (isolate == null) { |
| 71 throw new IsolateNotFound(isolateId); | 67 throw new IsolateNotFound(isolateId); |
| 72 } | 68 } |
| 73 return isolate; | 69 return isolate; |
| 74 }); | 70 }); |
| 75 } | 71 } |
| 76 | 72 |
| 77 bool canVisit(Uri uri) => uri.path == path; | 73 bool canVisit(Uri uri) => uri.path == path; |
| 78 } | 74 } |
| 79 | 75 |
| 76 /// A [SimplePage] matches a single uri path and displays a single element. |
| 77 class SimplePage extends MatchingPage { |
| 78 final String elementTagName; |
| 79 SimplePage(String path, this.elementTagName, app) : super(path, app); |
| 80 |
| 81 void onInstall() { |
| 82 if (element == null) { |
| 83 element = new Element.tag(elementTagName); |
| 84 } |
| 85 } |
| 86 } |
| 87 |
| 80 /// Error page for unrecognized paths. | 88 /// Error page for unrecognized paths. |
| 81 class ErrorPage extends Page { | 89 class ErrorPage extends Page { |
| 82 ErrorPage(app) : super(app); | 90 ErrorPage(app) : super(app); |
| 83 | 91 |
| 84 void onInstall() { | 92 void onInstall() { |
| 85 if (element == null) { | 93 if (element == null) { |
| 86 // Lazily create page. | 94 // Lazily create page. |
| 87 element = new GeneralErrorElement(app.notifications, queue: app.queue); | 95 element = new GeneralErrorElement(app.notifications, queue: app.queue); |
| 88 } | 96 } |
| 89 } | 97 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 if (element != null) { | 217 if (element != null) { |
| 210 /// Update the page. | 218 /// Update the page. |
| 211 ObjectStoreViewElement page = element; | 219 ObjectStoreViewElement page = element; |
| 212 page.objectStore = objectStore; | 220 page.objectStore = objectStore; |
| 213 } | 221 } |
| 214 }); | 222 }); |
| 215 }); | 223 }); |
| 216 } | 224 } |
| 217 } | 225 } |
| 218 | 226 |
| 219 class CpuProfilerPage extends SimplePage { | 227 class CpuProfilerPage extends MatchingPage { |
| 220 CpuProfilerPage(app) : super('profiler', 'cpu-profile', app); | 228 CpuProfilerPage(app) : super('profiler', app); |
| 229 |
| 230 DivElement container = new DivElement(); |
| 221 | 231 |
| 222 void _visit(Uri uri) { | 232 void _visit(Uri uri) { |
| 223 super._visit(uri); | 233 super._visit(uri); |
| 224 getIsolate(uri).then((isolate) { | 234 getIsolate(uri).then((isolate) { |
| 225 if (element != null) { | 235 container.children = [ |
| 226 /// Update the page. | 236 new CpuProfileElement(isolate.vm, isolate, app.events, |
| 227 CpuProfileElement page = element; | 237 app.notifications, |
| 228 page.isolate = isolate; | 238 _isolateSampleProfileRepository) |
| 229 } | 239 ]; |
| 230 }); | 240 }); |
| 231 } | 241 } |
| 242 |
| 243 void onInstall() { |
| 244 if (element == null) { |
| 245 element = container; |
| 246 } |
| 247 assert(element != null); |
| 248 } |
| 232 } | 249 } |
| 233 | 250 |
| 234 class TableCpuProfilerPage extends SimplePage { | 251 class TableCpuProfilerPage extends SimplePage { |
| 235 TableCpuProfilerPage(app) | 252 TableCpuProfilerPage(app) |
| 236 : super('profiler-table', 'cpu-profile-table', app); | 253 : super('profiler-table', 'cpu-profile-table', app); |
| 237 | 254 |
| 238 void _visit(Uri uri) { | 255 void _visit(Uri uri) { |
| 239 super._visit(uri); | 256 super._visit(uri); |
| 240 getIsolate(uri).then((isolate) { | 257 getIsolate(uri).then((isolate) { |
| 241 if (element != null) { | 258 if (element != null) { |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 assert(element != null); | 495 assert(element != null); |
| 479 } | 496 } |
| 480 | 497 |
| 481 void _visit(Uri uri) { | 498 void _visit(Uri uri) { |
| 482 assert(element != null); | 499 assert(element != null); |
| 483 assert(canVisit(uri)); | 500 assert(canVisit(uri)); |
| 484 } | 501 } |
| 485 | 502 |
| 486 bool canVisit(Uri uri) => uri.path == 'timeline'; | 503 bool canVisit(Uri uri) => uri.path == 'timeline'; |
| 487 } | 504 } |
| OLD | NEW |