| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 var localStrings = new LocalStrings(); | 10 var localStrings = new LocalStrings(); |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 if (!dm || !sm) return; | 535 if (!dm || !sm) return; |
| 536 | 536 |
| 537 this.table_.list.startBatchUpdates(); | 537 this.table_.list.startBatchUpdates(); |
| 538 sm.beginChange(); | 538 sm.beginChange(); |
| 539 | 539 |
| 540 var type = task.type; | 540 var type = task.type; |
| 541 var start = task.start; | 541 var start = task.start; |
| 542 var length = task.length; | 542 var length = task.length; |
| 543 var tasks = task.tasks; | 543 var tasks = task.tasks; |
| 544 | 544 |
| 545 // We have to store the selected indexes and restore them after | 545 // We have to store the selected pids and restore them after |
| 546 // splice(), because it might replace some items but the replaced | 546 // splice(), because it might replace some items but the replaced |
| 547 // items would lose the selection. | 547 // items would lose the selection. |
| 548 var oldSelectedIndexes = sm.selectedIndexes; | 548 var oldSelectedIndexes = sm.selectedIndexes; |
| 549 | 549 |
| 550 // Create map of selected PIDs. |
| 551 var selectedPids = {}; |
| 552 for (var i = 0; i < oldSelectedIndexes.length; i++) { |
| 553 var item = dm.item(oldSelectedIndexes[i]); |
| 554 if (item) selectedPids[item['processId'][0]] = true; |
| 555 } |
| 556 |
| 550 var args = tasks.slice(); | 557 var args = tasks.slice(); |
| 551 args.unshift(start, dm.length); | 558 args.unshift(start, dm.length); |
| 552 dm.splice.apply(dm, args); | 559 dm.splice.apply(dm, args); |
| 553 | 560 |
| 554 sm.selectedIndexes = oldSelectedIndexes.filter(function(index) { | 561 // Create new array of selected indexes from map of old PIDs. |
| 555 return index < dm.length; | 562 var newSelectedIndexes = []; |
| 556 }); | 563 for (var i = 0; i < dm.length; i++) { |
| 564 if (selectedPids[dm.item(i)['processId'][0]]) |
| 565 newSelectedIndexes.push(i); |
| 566 } |
| 567 |
| 568 sm.selectedIndexes = newSelectedIndexes; |
| 557 | 569 |
| 558 var pids = []; | 570 var pids = []; |
| 559 for (var i = 0; i < dm.length; i++) { | 571 for (var i = 0; i < dm.length; i++) { |
| 560 pids.push(dm.item(i)['processId'][0]); | 572 pids.push(dm.item(i)['processId'][0]); |
| 561 } | 573 } |
| 562 | 574 |
| 563 // Sweeps unused caches, which elements no longer exist on the list. | 575 // Sweeps unused caches, which elements no longer exist on the list. |
| 564 for (var pid in this.elementsCache_) { | 576 for (var pid in this.elementsCache_) { |
| 565 if (pids.indexOf(pid) == -1) | 577 if (pids.indexOf(pid) == -1) |
| 566 delete this.elementsCache_[pid]; | 578 delete this.elementsCache_[pid]; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 var params = parseQueryParams(window.location); | 697 var params = parseQueryParams(window.location); |
| 686 var opt = {}; | 698 var opt = {}; |
| 687 opt['isShowTitle'] = params.showtitle; | 699 opt['isShowTitle'] = params.showtitle; |
| 688 opt['isBackgroundMode'] = params.background; | 700 opt['isBackgroundMode'] = params.background; |
| 689 opt['isShowCloseButton'] = params.showclose; | 701 opt['isShowCloseButton'] = params.showclose; |
| 690 taskmanager.initialize(document.body, opt); | 702 taskmanager.initialize(document.body, opt); |
| 691 } | 703 } |
| 692 | 704 |
| 693 document.addEventListener('DOMContentLoaded', init); | 705 document.addEventListener('DOMContentLoaded', init); |
| 694 document.addEventListener('Close', taskmanager.onClose.bind(taskmanager)); | 706 document.addEventListener('Close', taskmanager.onClose.bind(taskmanager)); |
| OLD | NEW |