| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 typedef Object ComputeValue(); | 5 typedef Object ComputeValue(); |
| 6 | 6 |
| 7 class _MeasurementRequest<T> { | 7 class _MeasurementRequest<T> { |
| 8 final ComputeValue computeValue; | 8 final ComputeValue computeValue; |
| 9 final Completer<T> completer; | 9 final Completer<T> completer; |
| 10 Object value; | 10 Object value; |
| 11 bool exception = false; | 11 bool exception = false; |
| 12 _MeasurementRequest(this.computeValue, this.completer); | 12 _MeasurementRequest(this.computeValue, this.completer); |
| 13 } | 13 } |
| 14 | 14 |
| 15 final _MEASUREMENT_MESSAGE = "DART-MEASURE"; | 15 const _MEASUREMENT_MESSAGE = "DART-MEASURE"; |
| 16 List<_MeasurementRequest> _pendingRequests; | 16 List<_MeasurementRequest> _pendingRequests; |
| 17 List<TimeoutHandler> _pendingMeasurementFrameCallbacks; | 17 List<TimeoutHandler> _pendingMeasurementFrameCallbacks; |
| 18 bool _nextMeasurementFrameScheduled = false; | 18 bool _nextMeasurementFrameScheduled = false; |
| 19 bool _firstMeasurementRequest = true; | 19 bool _firstMeasurementRequest = true; |
| 20 | 20 |
| 21 void _maybeScheduleMeasurementFrame() { | 21 void _maybeScheduleMeasurementFrame() { |
| 22 if (_nextMeasurementFrameScheduled) return; | 22 if (_nextMeasurementFrameScheduled) return; |
| 23 | 23 |
| 24 _nextMeasurementFrameScheduled = true; | 24 _nextMeasurementFrameScheduled = true; |
| 25 // postMessage gives us a way to receive a callback after the current | 25 // postMessage gives us a way to receive a callback after the current |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 if (readyMeasurementFrameCallbacks !== null) { | 114 if (readyMeasurementFrameCallbacks !== null) { |
| 115 for (TimeoutHandler handler in readyMeasurementFrameCallbacks) { | 115 for (TimeoutHandler handler in readyMeasurementFrameCallbacks) { |
| 116 // TODO(jacobr): wrap each call to a handler in a try-catch block. | 116 // TODO(jacobr): wrap each call to a handler in a try-catch block. |
| 117 handler(); | 117 handler(); |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 } | 120 } |
| OLD | NEW |