OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
13 * distribution. | 13 * distribution. |
14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
17 * | 17 * |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | |
31 /** | 30 /** |
32 * @interface | 31 * @interface |
33 */ | 32 */ |
34 WebInspector.Progress = function() | 33 WebInspector.Progress = function() {}; |
35 { | |
36 }; | |
37 | 34 |
38 WebInspector.Progress.prototype = { | 35 WebInspector.Progress.prototype = { |
39 /** | 36 /** |
40 * @param {number} totalWork | 37 * @param {number} totalWork |
41 */ | 38 */ |
42 setTotalWork: function(totalWork) { }, | 39 setTotalWork: function(totalWork) {}, |
43 | 40 |
44 /** | 41 /** |
45 * @param {string} title | 42 * @param {string} title |
46 */ | 43 */ |
47 setTitle: function(title) { }, | 44 setTitle: function(title) {}, |
48 | 45 |
49 /** | 46 /** |
50 * @param {number} worked | 47 * @param {number} worked |
51 * @param {string=} title | 48 * @param {string=} title |
52 */ | 49 */ |
53 setWorked: function(worked, title) { }, | 50 setWorked: function(worked, title) {}, |
54 | 51 |
55 /** | 52 /** |
56 * @param {number=} worked | 53 * @param {number=} worked |
57 */ | 54 */ |
58 worked: function(worked) { }, | 55 worked: function(worked) {}, |
59 | 56 |
60 done: function() { }, | 57 done: function() {}, |
61 | 58 |
62 /** | 59 /** |
63 * @return {boolean} | 60 * @return {boolean} |
64 */ | 61 */ |
65 isCanceled: function() { return false; }, | 62 isCanceled: function() { |
66 }; | 63 return false; |
67 | 64 }, |
68 /** | 65 }; |
69 * @constructor | 66 |
70 * @param {!WebInspector.Progress} parent | 67 /** |
71 */ | 68 * @unrestricted |
72 WebInspector.CompositeProgress = function(parent) | 69 */ |
73 { | 70 WebInspector.CompositeProgress = class { |
| 71 /** |
| 72 * @param {!WebInspector.Progress} parent |
| 73 */ |
| 74 constructor(parent) { |
74 this._parent = parent; | 75 this._parent = parent; |
75 this._children = []; | 76 this._children = []; |
76 this._childrenDone = 0; | 77 this._childrenDone = 0; |
77 this._parent.setTotalWork(1); | 78 this._parent.setTotalWork(1); |
78 this._parent.setWorked(0); | 79 this._parent.setWorked(0); |
79 }; | 80 } |
80 | 81 |
81 WebInspector.CompositeProgress.prototype = { | 82 _childDone() { |
82 _childDone: function() | 83 if (++this._childrenDone !== this._children.length) |
83 { | 84 return; |
84 if (++this._childrenDone !== this._children.length) | 85 this._parent.done(); |
85 return; | 86 } |
86 this._parent.done(); | 87 |
87 }, | 88 /** |
88 | 89 * @param {number=} weight |
89 /** | 90 * @return {!WebInspector.SubProgress} |
90 * @param {number=} weight | 91 */ |
91 * @return {!WebInspector.SubProgress} | 92 createSubProgress(weight) { |
92 */ | 93 var child = new WebInspector.SubProgress(this, weight); |
93 createSubProgress: function(weight) | 94 this._children.push(child); |
94 { | 95 return child; |
95 var child = new WebInspector.SubProgress(this, weight); | 96 } |
96 this._children.push(child); | 97 |
97 return child; | 98 _update() { |
98 }, | 99 var totalWeights = 0; |
99 | 100 var done = 0; |
100 _update: function() | 101 |
101 { | 102 for (var i = 0; i < this._children.length; ++i) { |
102 var totalWeights = 0; | 103 var child = this._children[i]; |
103 var done = 0; | 104 if (child._totalWork) |
104 | 105 done += child._weight * child._worked / child._totalWork; |
105 for (var i = 0; i < this._children.length; ++i) { | 106 totalWeights += child._weight; |
106 var child = this._children[i]; | |
107 if (child._totalWork) | |
108 done += child._weight * child._worked / child._totalWork; | |
109 totalWeights += child._weight; | |
110 } | |
111 this._parent.setWorked(done / totalWeights); | |
112 } | 107 } |
113 }; | 108 this._parent.setWorked(done / totalWeights); |
114 | 109 } |
115 /** | 110 }; |
116 * @constructor | 111 |
| 112 /** |
117 * @implements {WebInspector.Progress} | 113 * @implements {WebInspector.Progress} |
118 * @param {!WebInspector.CompositeProgress} composite | 114 * @unrestricted |
119 * @param {number=} weight | 115 */ |
120 */ | 116 WebInspector.SubProgress = class { |
121 WebInspector.SubProgress = function(composite, weight) | 117 /** |
122 { | 118 * @param {!WebInspector.CompositeProgress} composite |
| 119 * @param {number=} weight |
| 120 */ |
| 121 constructor(composite, weight) { |
123 this._composite = composite; | 122 this._composite = composite; |
124 this._weight = weight || 1; | 123 this._weight = weight || 1; |
125 this._worked = 0; | 124 this._worked = 0; |
126 }; | 125 } |
127 | 126 |
128 WebInspector.SubProgress.prototype = { | 127 /** |
129 /** | 128 * @override |
130 * @override | 129 * @return {boolean} |
131 * @return {boolean} | 130 */ |
132 */ | 131 isCanceled() { |
133 isCanceled: function() | 132 return this._composite._parent.isCanceled(); |
134 { | 133 } |
135 return this._composite._parent.isCanceled(); | 134 |
136 }, | 135 /** |
137 | 136 * @override |
138 /** | 137 * @param {string} title |
139 * @override | 138 */ |
140 * @param {string} title | 139 setTitle(title) { |
141 */ | 140 this._composite._parent.setTitle(title); |
142 setTitle: function(title) | 141 } |
143 { | 142 |
144 this._composite._parent.setTitle(title); | 143 /** |
145 }, | 144 * @override |
146 | 145 */ |
147 /** | 146 done() { |
148 * @override | 147 this.setWorked(this._totalWork); |
149 */ | 148 this._composite._childDone(); |
150 done: function() | 149 } |
151 { | 150 |
152 this.setWorked(this._totalWork); | 151 /** |
153 this._composite._childDone(); | 152 * @override |
154 }, | 153 * @param {number} totalWork |
155 | 154 */ |
156 /** | 155 setTotalWork(totalWork) { |
157 * @override | 156 this._totalWork = totalWork; |
158 * @param {number} totalWork | 157 this._composite._update(); |
159 */ | 158 } |
160 setTotalWork: function(totalWork) | 159 |
161 { | 160 /** |
162 this._totalWork = totalWork; | 161 * @override |
163 this._composite._update(); | 162 * @param {number} worked |
164 }, | 163 * @param {string=} title |
165 | 164 */ |
166 /** | 165 setWorked(worked, title) { |
167 * @override | 166 this._worked = worked; |
168 * @param {number} worked | 167 if (typeof title !== 'undefined') |
169 * @param {string=} title | 168 this.setTitle(title); |
170 */ | 169 this._composite._update(); |
171 setWorked: function(worked, title) | 170 } |
172 { | 171 |
173 this._worked = worked; | 172 /** |
174 if (typeof title !== "undefined") | 173 * @override |
175 this.setTitle(title); | 174 * @param {number=} worked |
176 this._composite._update(); | 175 */ |
177 }, | 176 worked(worked) { |
178 | 177 this.setWorked(this._worked + (worked || 1)); |
179 /** | 178 } |
180 * @override | 179 }; |
181 * @param {number=} worked | 180 |
182 */ | 181 /** |
183 worked: function(worked) | |
184 { | |
185 this.setWorked(this._worked + (worked || 1)); | |
186 } | |
187 }; | |
188 | |
189 /** | |
190 * @constructor | |
191 * @implements {WebInspector.Progress} | 182 * @implements {WebInspector.Progress} |
192 * @param {?WebInspector.Progress} delegate | 183 * @unrestricted |
193 * @param {function()=} doneCallback | 184 */ |
194 */ | 185 WebInspector.ProgressProxy = class { |
195 WebInspector.ProgressProxy = function(delegate, doneCallback) | 186 /** |
196 { | 187 * @param {?WebInspector.Progress} delegate |
| 188 * @param {function()=} doneCallback |
| 189 */ |
| 190 constructor(delegate, doneCallback) { |
197 this._delegate = delegate; | 191 this._delegate = delegate; |
198 this._doneCallback = doneCallback; | 192 this._doneCallback = doneCallback; |
199 }; | 193 } |
200 | 194 |
201 WebInspector.ProgressProxy.prototype = { | 195 /** |
202 /** | 196 * @override |
203 * @override | 197 * @return {boolean} |
204 * @return {boolean} | 198 */ |
205 */ | 199 isCanceled() { |
206 isCanceled: function() | 200 return this._delegate ? this._delegate.isCanceled() : false; |
207 { | 201 } |
208 return this._delegate ? this._delegate.isCanceled() : false; | 202 |
209 }, | 203 /** |
210 | 204 * @override |
211 /** | 205 * @param {string} title |
212 * @override | 206 */ |
213 * @param {string} title | 207 setTitle(title) { |
214 */ | 208 if (this._delegate) |
215 setTitle: function(title) | 209 this._delegate.setTitle(title); |
216 { | 210 } |
217 if (this._delegate) | 211 |
218 this._delegate.setTitle(title); | 212 /** |
219 }, | 213 * @override |
220 | 214 */ |
221 /** | 215 done() { |
222 * @override | 216 if (this._delegate) |
223 */ | 217 this._delegate.done(); |
224 done: function() | 218 if (this._doneCallback) |
225 { | 219 this._doneCallback(); |
226 if (this._delegate) | 220 } |
227 this._delegate.done(); | 221 |
228 if (this._doneCallback) | 222 /** |
229 this._doneCallback(); | 223 * @override |
230 }, | 224 * @param {number} totalWork |
231 | 225 */ |
232 /** | 226 setTotalWork(totalWork) { |
233 * @override | 227 if (this._delegate) |
234 * @param {number} totalWork | 228 this._delegate.setTotalWork(totalWork); |
235 */ | 229 } |
236 setTotalWork: function(totalWork) | 230 |
237 { | 231 /** |
238 if (this._delegate) | 232 * @override |
239 this._delegate.setTotalWork(totalWork); | 233 * @param {number} worked |
240 }, | 234 * @param {string=} title |
241 | 235 */ |
242 /** | 236 setWorked(worked, title) { |
243 * @override | 237 if (this._delegate) |
244 * @param {number} worked | 238 this._delegate.setWorked(worked, title); |
245 * @param {string=} title | 239 } |
246 */ | 240 |
247 setWorked: function(worked, title) | 241 /** |
248 { | 242 * @override |
249 if (this._delegate) | 243 * @param {number=} worked |
250 this._delegate.setWorked(worked, title); | 244 */ |
251 }, | 245 worked(worked) { |
252 | 246 if (this._delegate) |
253 /** | 247 this._delegate.worked(worked); |
254 * @override | 248 } |
255 * @param {number=} worked | 249 }; |
256 */ | |
257 worked: function(worked) | |
258 { | |
259 if (this._delegate) | |
260 this._delegate.worked(worked); | |
261 } | |
262 }; | |
OLD | NEW |