Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: runtime/bin/vmservice/client/lib/src/elements/observatory_element.dart

Issue 335463008: Allow Observatory to run as a hosted web service (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 library observatory_element; 5 library observatory_element;
6 6
7 import 'dart:async';
7 import 'dart:html'; 8 import 'dart:html';
8 import 'package:observatory/app.dart'; 9 import 'package:observatory/app.dart';
9 import 'package:polymer/polymer.dart'; 10 import 'package:polymer/polymer.dart';
10 11
11 /// Base class for all Observatory custom elements. 12 /// Base class for all Observatory custom elements.
12 @CustomTag('observatory-element') 13 @CustomTag('observatory-element')
13 class ObservatoryElement extends PolymerElement { 14 class ObservatoryElement extends PolymerElement {
14 ObservatoryElement.created() : super.created(); 15 ObservatoryElement.created() : super.created();
15 16
17 ObservatoryApplication get app => ObservatoryApplication.app;
18
16 @override 19 @override
17 void attached() { 20 void attached() {
18 super.attached(); 21 super.attached();
22 _startPoll();
19 } 23 }
20 24
21 @override 25 @override
22 void attributeChanged(String name, var oldValue, var newValue) { 26 void attributeChanged(String name, var oldValue, var newValue) {
23 super.attributeChanged(name, oldValue, newValue); 27 super.attributeChanged(name, oldValue, newValue);
24 } 28 }
25 29
26 @override 30 @override
27 void detached() { 31 void detached() {
28 super.detached(); 32 super.detached();
33 _stopPoll();
29 } 34 }
30 35
36 @override
31 void ready() { 37 void ready() {
32 super.ready(); 38 super.ready();
33 } 39 }
34 40
35 void goto(MouseEvent event, var detail, Element target) { 41 /// Set to a non-null value to enable polling on this element. When the poll
36 location.onGoto(event, detail, target); 42 /// timer fires, onPoll will be called.
43 @observable Duration pollPeriod;
44 Timer _pollTimer;
turnidge 2014/07/01 00:27:47 I wonder if there is a way to make this simpler.
Cutch 2014/07/01 17:14:51 Perhaps it makes more sense on a pane-level. That
45
46 /// Called every [pollPeriod] while the element is attached to the DOM.
47 void onPoll() { }
48
49 void pollPeriodChanged(oldValue) {
50 if (pollPeriod != null) {
51 _startPoll();
52 } else {
53 _stopPoll();
54 }
37 } 55 }
38 56
39 String gotoLink(String url) { 57 void _startPoll() {
40 return location.makeLink(url); 58 if (pollPeriod == null) {
59 return;
60 }
61 if (_pollTimer != null) {
62 _pollTimer.cancel();
63 }
64 _pollTimer = new Timer(pollPeriod, _onPoll);
41 } 65 }
42 66
67 void _stopPoll() {
68 if (_pollTimer != null) {
69 _pollTimer.cancel();
70 }
71 _pollTimer = null;
72 }
43 73
74 void _onPoll() {
75 onPoll();
76 if (pollPeriod == null) {
77 // Stop polling.
78 _stopPoll();
79 return;
80 }
81 // Restart timer.
82 _pollTimer = new Timer(pollPeriod, _onPoll);
83 }
84
85 /// Utility method for handling on-click of <a> tags. Navigates
86 /// within the application using the [LocationManager].
87 void goto(MouseEvent event, var detail, Element target) {
88 app.locationManager.onGoto(event, detail, target);
89 }
90
91 /// Create a link that can be consumed by [goto].
92 String gotoLink(String url) {
93 return app.locationManager.makeLink(url);
94 }
44 95
45 String formatTimePrecise(double time) => Utils.formatTimePrecise(time); 96 String formatTimePrecise(double time) => Utils.formatTimePrecise(time);
46 97
47 String formatTime(double time) => Utils.formatTime(time); 98 String formatTime(double time) => Utils.formatTime(time);
48 99
49 String formatSeconds(double x) => Utils.formatSeconds(x); 100 String formatSeconds(double x) => Utils.formatSeconds(x);
50 101
51 102
52 String formatSize(int bytes) => Utils.formatSize(bytes); 103 String formatSize(int bytes) => Utils.formatSize(bytes);
53 104
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 'Bool', 155 'Bool',
105 'String', 156 'String',
106 'Double', 157 'Double',
107 'Instance', 158 'Instance',
108 'GrowableObjectArray', 159 'GrowableObjectArray',
109 'Array', 160 'Array',
110 'Type', 161 'Type',
111 'Error'].contains(type)); 162 'Error'].contains(type));
112 } 163 }
113 } 164 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698