Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 import 'dart:html'; | |
| 6 import 'dart:async'; | |
| 7 import 'package:observatory/models.dart' as M; | |
| 8 import 'package:observatory/src/elements/curly_block.dart'; | |
| 9 import 'package:observatory/src/elements/instance_ref.dart'; | |
| 10 import 'package:observatory/src/elements/helpers/any_ref.dart'; | |
| 11 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; | |
| 12 import 'package:observatory/src/elements/helpers/tag.dart'; | |
| 13 import 'package:observatory/utils.dart'; | |
| 14 | |
| 15 class TopRetainingInstancesElement extends HtmlElement implements Renderable { | |
| 16 static const tag = const Tag<TopRetainingInstancesElement>( | |
| 17 'top-retainig-instances', | |
| 18 dependencies: const [ | |
| 19 CurlyBlockElement.tag, | |
| 20 InstanceRefElement.tag | |
| 21 ]); | |
| 22 | |
| 23 RenderingScheduler<TopRetainingInstancesElement> _r; | |
| 24 | |
| 25 Stream<RenderedEvent<TopRetainingInstancesElement>> get onRendered => | |
| 26 _r.onRendered; | |
| 27 | |
| 28 M.IsolateRef _isolate; | |
| 29 M.ClassRef _cls; | |
| 30 M.TopRetainingInstancesRepository _topRetainingInstances; | |
| 31 M.InstanceRepository _instances; | |
| 32 Iterable<M.RetainingObject> _topRetaining; | |
| 33 bool _expanded = false; | |
| 34 | |
| 35 M.IsolateRef get isolate => _isolate; | |
| 36 M.ClassRef get cls => _cls; | |
| 37 | |
| 38 factory TopRetainingInstancesElement(M.IsolateRef isolate, M.ClassRef cls, | |
| 39 M.TopRetainingInstancesRepository topRetainingInstances, | |
| 40 M.InstanceRepository instances, | |
| 41 {RenderingQueue queue}) { | |
| 42 assert(isolate != null); | |
| 43 assert(cls != null); | |
| 44 assert(topRetainingInstances != null); | |
| 45 assert(instances != null); | |
| 46 TopRetainingInstancesElement e = document.createElement(tag.name); | |
| 47 e._r = new RenderingScheduler(e, queue: queue); | |
| 48 e._isolate = isolate; | |
| 49 e._cls = cls; | |
| 50 e._topRetainingInstances = topRetainingInstances; | |
| 51 e._instances = instances; | |
| 52 return e; | |
| 53 } | |
| 54 | |
| 55 TopRetainingInstancesElement.created() : super.created(); | |
| 56 | |
| 57 @override | |
| 58 void attached() { | |
| 59 super.attached(); | |
| 60 _r.enable(); | |
| 61 } | |
| 62 | |
| 63 @override | |
| 64 void detached() { | |
| 65 super.detached(); | |
| 66 children = []; | |
| 67 _r.disable(notify: true); | |
| 68 } | |
| 69 | |
| 70 void render() { | |
| 71 children = [ | |
| 72 new CurlyBlockElement(expanded: _expanded, queue: _r.queue) | |
| 73 ..children = _createContent() | |
| 74 ..onToggle.listen((e) async { | |
| 75 _expanded = e.control.expanded; | |
| 76 if (_expanded) { | |
| 77 e.control.disabled = true; | |
| 78 await _refresh(); | |
| 79 e.control.disabled = false; | |
| 80 } | |
| 81 }) | |
| 82 ]; | |
| 83 } | |
| 84 | |
| 85 Future _refresh() async { | |
| 86 _topRetaining = null; | |
| 87 _topRetaining = await _topRetainingInstances.get(_isolate, _cls); | |
| 88 _r.dirty(); | |
| 89 } | |
| 90 | |
| 91 List<Element> _createContent() { | |
| 92 if (_topRetaining == null) { | |
| 93 return [ | |
| 94 new SpanElement()..text = 'Loading' | |
| 95 ]; | |
| 96 } | |
| 97 return _topRetaining.map((r) => | |
| 98 new DivElement() | |
| 99 ..children = [ | |
| 100 new SpanElement()..text = '${Utils.formatSize(r.retainedSize)} ', | |
|
rmacnak
2016/08/31 23:51:39
non-breaking space
cbernaschina
2016/09/01 00:04:08
Done.
| |
| 101 anyRef(_isolate, r.object, _instances, queue: _r.queue) | |
| 102 ] | |
| 103 ).toList(); | |
| 104 } | |
| 105 } | |
| OLD | NEW |