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

Side by Side Diff: chrome/browser/resources/task_manager/main.js

Issue 8713016: WebUI TaskManager: Optimize initialization taskmanager and loading scripts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fix Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** @constructor */ 5 /** @constructor */
6 function TaskManager() { } 6 function TaskManager() { }
7 7
8 cr.addSingletonGetter(TaskManager); 8 cr.addSingletonGetter(TaskManager);
9 9
10 /* 10 /*
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 * @public 138 * @public
139 */ 139 */
140 initialize: function (dialogDom, opt) { 140 initialize: function (dialogDom, opt) {
141 if (!dialogDom) { 141 if (!dialogDom) {
142 console.log('ERROR: dialogDom is not defined.'); 142 console.log('ERROR: dialogDom is not defined.');
143 return; 143 return;
144 } 144 }
145 145
146 this.opt_ = opt; 146 this.opt_ = opt;
147 147
148 this.initialized_ = true;
149 this.enableTaskManager(); 148 this.enableTaskManager();
150 149
151 this.dialogDom_ = dialogDom; 150 this.dialogDom_ = dialogDom;
152 this.document_ = dialogDom.ownerDocument; 151 this.document_ = dialogDom.ownerDocument;
153 152
154 $('close-window').addEventListener('click', this.close.bind(this)); 153 var ary = this.dialogDom_.querySelectorAll('[visibleif]');
155 $('kill-process').addEventListener('click', this.killProcess.bind(this)); 154 for (var i = 0; i < ary.length; i++) {
156 $('about-memory-link').addEventListener('click', 155 var expr = ary[i].getAttribute('visibleif');
157 this.openAboutMemory.bind(this)); 156 if (!eval(expr))
157 ary[i].hidden = true;
158 }
158 159
159 this.is_column_shown_ = []; 160 this.is_column_shown_ = [];
160 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { 161 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) {
161 this.is_column_shown_[i] = DEFAULT_COLUMNS[i][3]; 162 this.is_column_shown_[i] = DEFAULT_COLUMNS[i][3];
162 } 163 }
163 164
164 this.localized_column_ = []; 165 this.localized_column_ = [];
165 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { 166 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) {
166 var column_label_id = DEFAULT_COLUMNS[i][1]; 167 var column_label_id = DEFAULT_COLUMNS[i][1];
167 var localized_label = localStrings.getString(column_label_id); 168 var localized_label = localStrings.getString(column_label_id);
(...skipping 28 matching lines...) Expand all
196 var aValues = a[value_id]; 197 var aValues = a[value_id];
197 var bValues = b[value_id]; 198 var bValues = b[value_id];
198 var aValue = aValues && aValues[0] || 0; 199 var aValue = aValues && aValues[0] || 0;
199 var bvalue = bValues && bValues[0] || 0; 200 var bvalue = bValues && bValues[0] || 0;
200 return dm.defaultValuesCompareFunction(aValue, bvalue); 201 return dm.defaultValuesCompareFunction(aValue, bvalue);
201 }; 202 };
202 }(); 203 }();
203 dm.setCompareFunction(column_id, compare_func); 204 dm.setCompareFunction(column_id, compare_func);
204 } 205 }
205 206
206 var ary = this.dialogDom_.querySelectorAll('[visibleif]'); 207 this.initTable_();
207 for (var i = 0; i < ary.length; i++) { 208 this.initialized_ = true;
208 var expr = ary[i].getAttribute('visibleif'); 209
209 if (!eval(expr)) 210 loadDelayedIncludes(this);
210 ary[i].hidden = true; 211 },
212
213 /**
214 * Additional initialization of taskmanager. This function is called when
215 * the loading of delayed scripts finished.
216 * @public
217 */
218 delayedInitialize: function () {
219 $('close-window').addEventListener('click', this.close.bind(this));
220 $('kill-process').addEventListener('click', this.killProcess.bind(this));
221 $('about-memory-link').addEventListener('click',
222 this.openAboutMemory.bind(this));
223 this.initColumnMenu_();
224 this.initTableMenu_();
225
226 if (this.delayedInitLabels_) {
227 while (this.delayedInitLabels_.length > 0) {
James Hawkins 2011/12/08 18:14:09 No braces for one-link blocks.
yoshiki 2011/12/09 05:51:11 Done.
228 this.delayedInitLabels_.pop().call();
229 }
211 } 230 }
212 231
213 this.initTable_(); 232 this.isFinishedInitDelayed_ = true;
214 this.initColumnMenu_();
215 this.initTableMenu_();
216 this.table_.redraw();
217 }, 233 },
218 234
219 initColumnModel_: function () { 235 initColumnModel_: function () {
220 var table_columns = new Array(); 236 var table_columns = new Array();
221 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { 237 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) {
222 if (!this.is_column_shown_[i]) 238 if (!this.is_column_shown_[i])
223 continue; 239 continue;
224 240
225 var column = DEFAULT_COLUMNS[i]; 241 var column = DEFAULT_COLUMNS[i];
226 table_columns.push(new cr.ui.table.TableColumn(column[0], 242 table_columns.push(new cr.ui.table.TableColumn(column[0],
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 cm.getRenderFunction(i).call(null, dataItem, cm.getId(i), table)); 361 cm.getRenderFunction(i).call(null, dataItem, cm.getId(i), table));
346 362
347 listItem.appendChild(cell); 363 listItem.appendChild(cell);
348 } 364 }
349 listItem.data = dataItem; 365 listItem.data = dataItem;
350 366
351 return listItem; 367 return listItem;
352 }, 368 },
353 369
354 renderColumn_: function(entry, columnId, table) { 370 renderColumn_: function(entry, columnId, table) {
371 this.delayedInitLabels_ = [];
372
355 var container = this.document_.createElement('div'); 373 var container = this.document_.createElement('div');
356 container.id = 'detail-container-' + columnId + '-pid' + entry.processId; 374 container.id = 'detail-container-' + columnId + '-pid' + entry.processId;
357 container.className = 'detail-container-' + columnId; 375 container.className = 'detail-container-' + columnId;
358 376
359 if (entry[columnId]) { 377 if (entry[columnId]) {
360 for (var i = 0; i < entry[columnId].length; i++) { 378 for (var i = 0; i < entry[columnId].length; i++) {
361 var label = document.createElement('div'); 379 var label = document.createElement('div');
362 if (columnId == 'title') { 380 if (columnId == 'title') {
363 var image = this.document_.createElement('img'); 381 var image = this.document_.createElement('img');
364 image.className = 'detail-title-image'; 382 image.className = 'detail-title-image';
365 image.src = entry['icon'][i]; 383 image.src = entry['icon'][i];
366 label.appendChild(image); 384 label.appendChild(image);
367 var text = this.document_.createElement('div'); 385 var text = this.document_.createElement('div');
368 text.className = 'detail-title-text'; 386 text.className = 'detail-title-text';
369 text.textContent = entry['title'][i]; 387 text.textContent = entry['title'][i];
370 label.appendChild(text); 388 label.appendChild(text);
371 389
372 cr.ui.contextMenuHandler.addContextMenuProperty(label); 390 var addContextMenu = function() {
373 label.contextMenu = this.tableContextMenu_; 391 cr.ui.contextMenuHandler.addContextMenuProperty(label);
392 label.contextMenu = this.tableContextMenu_;
393 };
394
395 if (this.isFinishedInitDelayed_)
396 addContextMenu.call(this);
397 else
398 this.delayedInitLabels_.push(addContextMenu.bind(this));
374 399
375 label.addEventListener('dblclick', (function(uniqueId) { 400 label.addEventListener('dblclick', (function(uniqueId) {
376 this.activatePage(uniqueId); 401 this.activatePage(uniqueId);
377 }).bind(this, entry['uniqueId'][i])); 402 }).bind(this, entry['uniqueId'][i]));
378 403
379 label.data = entry; 404 label.data = entry;
380 label.index_in_group = i; 405 label.index_in_group = i;
381 } else { 406 } else {
382 label.textContent = entry[columnId][i]; 407 label.textContent = entry[columnId][i];
383 } 408 }
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 taskmanager.onTaskChange(start, length, tasks); 587 taskmanager.onTaskChange(start, length, tasks);
563 } 588 }
564 589
565 function taskRemoved(start, length) { 590 function taskRemoved(start, length) {
566 // Sometimes this can get called too early. 591 // Sometimes this can get called too early.
567 if (!taskmanager) 592 if (!taskmanager)
568 return; 593 return;
569 taskmanager.onTaskRemove(start, length); 594 taskmanager.onTaskRemove(start, length);
570 } 595 }
571 596
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698