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

Unified Diff: pkg/analysis_services/lib/src/refactoring/progress_monitor.dart

Issue 458063002: Initial work on refactorings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_services/lib/src/refactoring/progress_monitor.dart
diff --git a/pkg/analysis_services/lib/src/refactoring/progress_monitor.dart b/pkg/analysis_services/lib/src/refactoring/progress_monitor.dart
new file mode 100644
index 0000000000000000000000000000000000000000..8d71776509cbe33b235c4359b20334453b5acd24
--- /dev/null
+++ b/pkg/analysis_services/lib/src/refactoring/progress_monitor.dart
@@ -0,0 +1,97 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// This code was auto-generated, is not intended to be edited, and is subject to
+// significant change. Please see the README file for more information.
+
+library services.src.refactoring.progress_monitor;
+
+import 'package:analysis_services/refactoring/progress_monitor.dart';
+
+
+/**
+ * A [ProgressMonitor] which represents a part of a bigger [ProgressMonitor].
+ */
+class SubProgressMonitor implements ProgressMonitor {
+ final ProgressMonitor _parent;
+ final int _parentTicks;
+
+ int _nestedBeginTasks = 0;
+
+ double _scale = 0.0;
+
+ int _sentToParent = 0;
+
+ bool _usedUp = false;
+
+ bool _hasSubTask = false;
+
+ SubProgressMonitor(this._parent, this._parentTicks);
+
+ @override
+ bool get isCanceled => _parent.isCanceled;
+
+ @override
+ void beginTask(String name, int totalWork) {
+ _nestedBeginTasks++;
+ // ignore nested begin task calls
+ if (_nestedBeginTasks > 1) {
+ return;
+ }
+ // prepare scale to convert this PM to parent PM
+ _scale = totalWork <= 0 ? 0.0 : _parentTicks / totalWork;
+ _sentToParent = 0;
+ _usedUp = false;
+ }
+
+ @override
+ void done() {
+ // ignore if already done
+ if (_nestedBeginTasks == 0 || --_nestedBeginTasks > 0) {
+ return;
+ }
+ // send any remaining ticks
+ double remaining = (_parentTicks - _sentToParent).toDouble();
+ if (remaining > 0) {
+ _parent.internalWorked(remaining);
+ }
+ // clear the sub task if there was one
+ if (_hasSubTask) {
+ _parent.subTask("");
+ }
+ }
+
+ @override
+ void internalWorked(double work) {
+ // may be ignore
+ if (_usedUp || _nestedBeginTasks != 1) {
+ return;
+ }
+ // send to parent
+ double parentWork = work > 0.0 ? _scale * work : 0.0;
+ _parent.internalWorked(parentWork);
+ _sentToParent += parentWork;
+ // may be used up
+ if (_sentToParent >= _parentTicks) {
+ _usedUp = true;
+ }
+ }
+
+ @override
+ void setCanceled() {
+ _parent.setCanceled();
+ }
+
+ @override
+ void subTask(String name) {
+ _hasSubTask = true;
+ _parent.subTask(name);
+ }
+
+ @override
+ void worked(int work) {
+ double workDouble = work.toDouble();
+ internalWorked(workDouble);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698