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

Side by Side Diff: chrome/browser/task_manager.cc

Issue 140044: Reorganize the way the task manager is constructed.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/task_manager.h ('k') | chrome/browser/task_manager_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "chrome/browser/task_manager.h" 5 #include "chrome/browser/task_manager.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 //////////////////////////////////////////////////////////////////////////////// 691 ////////////////////////////////////////////////////////////////////////////////
692 // TaskManager class 692 // TaskManager class
693 //////////////////////////////////////////////////////////////////////////////// 693 ////////////////////////////////////////////////////////////////////////////////
694 694
695 // static 695 // static
696 void TaskManager::RegisterPrefs(PrefService* prefs) { 696 void TaskManager::RegisterPrefs(PrefService* prefs) {
697 prefs->RegisterDictionaryPref(prefs::kTaskManagerWindowPlacement); 697 prefs->RegisterDictionaryPref(prefs::kTaskManagerWindowPlacement);
698 } 698 }
699 699
700 TaskManager::TaskManager() 700 TaskManager::TaskManager()
701 : ALLOW_THIS_IN_INITIALIZER_LIST(model_(new TaskManagerModel(this))), 701 : ALLOW_THIS_IN_INITIALIZER_LIST(model_(new TaskManagerModel(this))) {
702 view_(NULL) {
703 } 702 }
704 703
705 TaskManager::~TaskManager() { 704 TaskManager::~TaskManager() {
706 } 705 }
707 706
708 // static 707 bool TaskManager::IsBrowserProcess(int index) const {
709 void TaskManager::Open() { 708 // If some of the selection is out of bounds, ignore. This may happen when
710 TaskManager* task_manager = GetInstance(); 709 // killing a process that manages several pages.
711 if (task_manager->view_) { 710 return index < model_->ResourceCount() &&
712 task_manager->view_->ActivateWindow(); 711 model_->GetResourceProcessHandle(index) ==
713 } else { 712 base::GetCurrentProcessHandle();
714 task_manager->CreateView();
715 task_manager->view_->OpenWindow();
716 }
717 } 713 }
718 714
719 // static 715 void TaskManager::KillProcess(int index) {
720 void TaskManager::Close() { 716 base::ProcessHandle process = model_->GetResourceProcessHandle(index);
721 TaskManager* task_manager = GetInstance(); 717 DCHECK(process);
722 task_manager->view_->CloseWindow(); 718 if (process != base::GetCurrentProcessHandle())
719 base::KillProcess(process, base::PROCESS_END_KILLED_BY_USER, false);
723 } 720 }
724 721
725 bool TaskManager::BrowserProcessIsSelected() { 722 void TaskManager::ActivateProcess(int index) {
726 if (!view_)
727 return false;
728 std::vector<int> selection;
729 view_->GetSelection(&selection);
730 for (std::vector<int>::const_iterator iter = selection.begin();
731 iter != selection.end(); ++iter) {
732 // If some of the selection is out of bounds, ignore. This may happen when
733 // killing a process that manages several pages.
734 if (*iter >= model_->ResourceCount())
735 continue;
736 if (model_->GetResourceProcessHandle(*iter) ==
737 base::GetCurrentProcessHandle())
738 return true;
739 }
740 return false;
741 }
742
743 void TaskManager::KillSelectedProcesses() {
744 std::vector<int> selection;
745 view_->GetSelection(&selection);
746 for (std::vector<int>::const_iterator iter = selection.begin();
747 iter != selection.end(); ++iter) {
748 base::ProcessHandle process = model_->GetResourceProcessHandle(*iter);
749 DCHECK(process);
750 if (process == base::GetCurrentProcessHandle())
751 continue;
752 base::KillProcess(process, base::PROCESS_END_KILLED_BY_USER, false);
753 }
754 }
755
756 void TaskManager::ActivateFocusedTab() {
757 std::vector<int> focused;
758 view_->GetFocused(&focused);
759 int focused_size = static_cast<int>(focused.size());
760
761 DCHECK(focused_size == 1);
762
763 // Gracefully return if there is not exactly one item in focus.
764 if (focused_size != 1)
765 return;
766
767 // Otherwise, the one focused thing should be one the user intends to bring
768 // forth, so get see if GetTabContents returns non-null. If it does, activate
769 // those contents.
770 int index = focused[0];
771
772 // GetResourceTabContents returns a pointer to the relevant tab contents for 723 // GetResourceTabContents returns a pointer to the relevant tab contents for
773 // the resource. If the index doesn't correspond to a Tab (i.e. refers to 724 // the resource. If the index doesn't correspond to a Tab (i.e. refers to
774 // the Browser process or a plugin), GetTabContents will return NULL. 725 // the Browser process or a plugin), GetTabContents will return NULL.
775 TabContents* chosen_tab_contents = model_->GetResourceTabContents(index); 726 TabContents* chosen_tab_contents = model_->GetResourceTabContents(index);
776 727 if (chosen_tab_contents)
777 if (!chosen_tab_contents) 728 chosen_tab_contents->Activate();
778 return;
779
780 chosen_tab_contents->Activate();
781 } 729 }
782 730
783 void TaskManager::AddResourceProvider(ResourceProvider* provider) { 731 void TaskManager::AddResourceProvider(ResourceProvider* provider) {
784 model_->AddResourceProvider(provider); 732 model_->AddResourceProvider(provider);
785 } 733 }
786 734
787 void TaskManager::RemoveResourceProvider(ResourceProvider* provider) { 735 void TaskManager::RemoveResourceProvider(ResourceProvider* provider) {
788 model_->RemoveResourceProvider(provider); 736 model_->RemoveResourceProvider(provider);
789 } 737 }
790 738
791 void TaskManager::AddResource(Resource* resource) { 739 void TaskManager::AddResource(Resource* resource) {
792 model_->AddResource(resource); 740 model_->AddResource(resource);
793 } 741 }
794 742
795 void TaskManager::RemoveResource(Resource* resource) { 743 void TaskManager::RemoveResource(Resource* resource) {
796 model_->RemoveResource(resource); 744 model_->RemoveResource(resource);
797 } 745 }
798 746
799 void TaskManager::OnWindowClosed() { 747 void TaskManager::OnWindowClosed() {
800 model_->StopUpdating(); 748 model_->StopUpdating();
801 model_->Clear(); 749 model_->Clear();
802 view_ = NULL;
803 } 750 }
804 751
805 // static 752 // static
806 TaskManager* TaskManager::GetInstance() { 753 TaskManager* TaskManager::GetInstance() {
807 return Singleton<TaskManager>::get(); 754 return Singleton<TaskManager>::get();
808 } 755 }
OLDNEW
« no previous file with comments | « chrome/browser/task_manager.h ('k') | chrome/browser/task_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698