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

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)
228 this.delayedInitLabels_.pop().call();
211 } 229 }
212 230
213 this.initTable_(); 231 this.isFinishedInitDelayed_ = true;
214 this.initColumnMenu_();
215 this.initTableMenu_();
216 this.table_.redraw();
217 }, 232 },
218 233
219 initColumnModel_: function () { 234 initColumnModel_: function () {
220 var table_columns = new Array(); 235 var table_columns = new Array();
221 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { 236 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) {
222 if (!this.is_column_shown_[i]) 237 if (!this.is_column_shown_[i])
223 continue; 238 continue;
224 239
225 var column = DEFAULT_COLUMNS[i]; 240 var column = DEFAULT_COLUMNS[i];
226 table_columns.push(new cr.ui.table.TableColumn(column[0], 241 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)); 360 cm.getRenderFunction(i).call(null, dataItem, cm.getId(i), table));
346 361
347 listItem.appendChild(cell); 362 listItem.appendChild(cell);
348 } 363 }
349 listItem.data = dataItem; 364 listItem.data = dataItem;
350 365
351 return listItem; 366 return listItem;
352 }, 367 },
353 368
354 renderColumn_: function(entry, columnId, table) { 369 renderColumn_: function(entry, columnId, table) {
370 this.delayedInitLabels_ = [];
371
355 var container = this.document_.createElement('div'); 372 var container = this.document_.createElement('div');
356 container.id = 'detail-container-' + columnId + '-pid' + entry.processId; 373 container.id = 'detail-container-' + columnId + '-pid' + entry.processId;
357 container.className = 'detail-container-' + columnId; 374 container.className = 'detail-container-' + columnId;
358 375
359 if (entry[columnId]) { 376 if (entry[columnId]) {
360 for (var i = 0; i < entry[columnId].length; i++) { 377 for (var i = 0; i < entry[columnId].length; i++) {
361 var label = document.createElement('div'); 378 var label = document.createElement('div');
362 if (columnId == 'title') { 379 if (columnId == 'title') {
363 var image = this.document_.createElement('img'); 380 var image = this.document_.createElement('img');
364 image.className = 'detail-title-image'; 381 image.className = 'detail-title-image';
365 image.src = entry['icon'][i]; 382 image.src = entry['icon'][i];
366 label.appendChild(image); 383 label.appendChild(image);
367 var text = this.document_.createElement('div'); 384 var text = this.document_.createElement('div');
368 text.className = 'detail-title-text'; 385 text.className = 'detail-title-text';
369 text.textContent = entry['title'][i]; 386 text.textContent = entry['title'][i];
370 label.appendChild(text); 387 label.appendChild(text);
371 388
372 cr.ui.contextMenuHandler.addContextMenuProperty(label); 389 var addContextMenu = function() {
373 label.contextMenu = this.tableContextMenu_; 390 cr.ui.contextMenuHandler.addContextMenuProperty(label);
391 label.contextMenu = this.tableContextMenu_;
392 };
393
394 if (this.isFinishedInitDelayed_)
395 addContextMenu.call(this);
396 else
397 this.delayedInitLabels_.push(addContextMenu.bind(this));
374 398
375 label.addEventListener('dblclick', (function(uniqueId) { 399 label.addEventListener('dblclick', (function(uniqueId) {
376 this.activatePage(uniqueId); 400 this.activatePage(uniqueId);
377 }).bind(this, entry['uniqueId'][i])); 401 }).bind(this, entry['uniqueId'][i]));
378 402
379 label.data = entry; 403 label.data = entry;
380 label.index_in_group = i; 404 label.index_in_group = i;
381 } else { 405 } else {
382 label.textContent = entry[columnId][i]; 406 label.textContent = entry[columnId][i];
383 } 407 }
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 taskmanager.onTaskChange(start, length, tasks); 586 taskmanager.onTaskChange(start, length, tasks);
563 } 587 }
564 588
565 function taskRemoved(start, length) { 589 function taskRemoved(start, length) {
566 // Sometimes this can get called too early. 590 // Sometimes this can get called too early.
567 if (!taskmanager) 591 if (!taskmanager)
568 return; 592 return;
569 taskmanager.onTaskRemove(start, length); 593 taskmanager.onTaskRemove(start, length);
570 } 594 }
571 595
OLDNEW
« no previous file with comments | « chrome/browser/resources/task_manager/main.html ('k') | chrome/browser/ui/webui/chrome_url_data_manager_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698