| 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 #include "chrome/browser/task_manager/task_manager.h" | 5 #include "chrome/browser/task_manager/task_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/i18n/number_formatting.h" | 9 #include "base/i18n/number_formatting.h" |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| 11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/background/background_contents_service.h" | 17 #include "chrome/browser/background/background_contents_service.h" |
| 18 #include "chrome/browser/background/background_contents_service_factory.h" | 18 #include "chrome/browser/background/background_contents_service_factory.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/extensions/extension_host.h" | 20 #include "chrome/browser/extensions/extension_host.h" |
| 21 #include "chrome/browser/extensions/extension_process_manager.h" | 21 #include "chrome/browser/extensions/extension_process_manager.h" |
| 22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
| 23 #include "chrome/browser/profiles/profile_manager.h" | 23 #include "chrome/browser/profiles/profile_manager.h" |
| 24 #include "chrome/browser/task_manager/task_manager_resource_providers.h" | 24 #include "chrome/browser/task_manager/task_manager_resource_providers.h" |
| 25 #include "chrome/browser/task_manager/task_manager_worker_resource_provider.h" | 25 #include "chrome/browser/task_manager/task_manager_worker_resource_provider.h" |
| 26 #include "chrome/browser/ui/browser_finder.h" | 26 #include "chrome/browser/ui/browser_finder.h" |
| 27 #include "chrome/browser/ui/browser_list.h" | 27 #include "chrome/browser/ui/browser_list.h" |
| 28 #include "chrome/browser/ui/browser_navigator.h" | 28 #include "chrome/browser/ui/browser_navigator.h" |
| 29 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
| 30 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 31 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
| 32 #include "chrome/common/view_type.h" | 31 #include "chrome/common/view_type.h" |
| 33 #include "content/public/browser/browser_child_process_host.h" | 32 #include "content/public/browser/browser_child_process_host.h" |
| 34 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| 35 #include "content/public/browser/render_view_host.h" | 34 #include "content/public/browser/render_view_host.h" |
| 36 #include "content/public/browser/resource_request_info.h" | 35 #include "content/public/browser/resource_request_info.h" |
| 37 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 38 #include "content/public/browser/web_contents_delegate.h" | 37 #include "content/public/browser/web_contents_delegate.h" |
| 39 #include "content/public/common/result_codes.h" | 38 #include "content/public/common/result_codes.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 : update_requests_(0), | 86 : update_requests_(0), |
| 88 listen_requests_(0), | 87 listen_requests_(0), |
| 89 update_state_(IDLE), | 88 update_state_(IDLE), |
| 90 goat_salt_(base::RandUint64()), | 89 goat_salt_(base::RandUint64()), |
| 91 last_unique_id_(0) { | 90 last_unique_id_(0) { |
| 92 AddResourceProvider( | 91 AddResourceProvider( |
| 93 new TaskManagerBrowserProcessResourceProvider(task_manager)); | 92 new TaskManagerBrowserProcessResourceProvider(task_manager)); |
| 94 AddResourceProvider( | 93 AddResourceProvider( |
| 95 new TaskManagerBackgroundContentsResourceProvider(task_manager)); | 94 new TaskManagerBackgroundContentsResourceProvider(task_manager)); |
| 96 AddResourceProvider(new TaskManagerTabContentsResourceProvider(task_manager)); | 95 AddResourceProvider(new TaskManagerTabContentsResourceProvider(task_manager)); |
| 96 AddResourceProvider(new TaskManagerPanelResourceProvider(task_manager)); |
| 97 AddResourceProvider( | 97 AddResourceProvider( |
| 98 new TaskManagerChildProcessResourceProvider(task_manager)); | 98 new TaskManagerChildProcessResourceProvider(task_manager)); |
| 99 AddResourceProvider( | 99 AddResourceProvider( |
| 100 new TaskManagerExtensionProcessResourceProvider(task_manager)); | 100 new TaskManagerExtensionProcessResourceProvider(task_manager)); |
| 101 | 101 |
| 102 #if defined(ENABLE_NOTIFICATIONS) | 102 #if defined(ENABLE_NOTIFICATIONS) |
| 103 TaskManager::ResourceProvider* provider = | 103 TaskManager::ResourceProvider* provider = |
| 104 TaskManagerNotificationResourceProvider::Create(task_manager); | 104 TaskManagerNotificationResourceProvider::Create(task_manager); |
| 105 if (provider) | 105 if (provider) |
| 106 AddResourceProvider(provider); | 106 AddResourceProvider(provider); |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 int TaskManagerModel::GetUniqueChildProcessId(int index) const { | 475 int TaskManagerModel::GetUniqueChildProcessId(int index) const { |
| 476 CHECK_LT(index, ResourceCount()); | 476 CHECK_LT(index, ResourceCount()); |
| 477 return resources_[index]->GetUniqueChildProcessId(); | 477 return resources_[index]->GetUniqueChildProcessId(); |
| 478 } | 478 } |
| 479 | 479 |
| 480 TaskManager::Resource::Type TaskManagerModel::GetResourceType(int index) const { | 480 TaskManager::Resource::Type TaskManagerModel::GetResourceType(int index) const { |
| 481 CHECK_LT(index, ResourceCount()); | 481 CHECK_LT(index, ResourceCount()); |
| 482 return resources_[index]->GetType(); | 482 return resources_[index]->GetType(); |
| 483 } | 483 } |
| 484 | 484 |
| 485 TabContents* TaskManagerModel::GetResourceTabContents(int index) const { | 485 WebContents* TaskManagerModel::GetResourceWebContents(int index) const { |
| 486 CHECK_LT(index, ResourceCount()); | 486 CHECK_LT(index, ResourceCount()); |
| 487 return resources_[index]->GetTabContents(); | 487 return resources_[index]->GetWebContents(); |
| 488 } | 488 } |
| 489 | 489 |
| 490 const extensions::Extension* TaskManagerModel::GetResourceExtension( | 490 const extensions::Extension* TaskManagerModel::GetResourceExtension( |
| 491 int index) const { | 491 int index) const { |
| 492 CHECK_LT(index, ResourceCount()); | 492 CHECK_LT(index, ResourceCount()); |
| 493 return resources_[index]->GetExtension(); | 493 return resources_[index]->GetExtension(); |
| 494 } | 494 } |
| 495 | 495 |
| 496 int64 TaskManagerModel::GetNetworkUsage(TaskManager::Resource* resource) | 496 int64 TaskManagerModel::GetNetworkUsage(TaskManager::Resource* resource) |
| 497 const { | 497 const { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 *result = 0; | 599 *result = 0; |
| 600 if (!resources_[index]->ReportsV8MemoryStats()) | 600 if (!resources_[index]->ReportsV8MemoryStats()) |
| 601 return false; | 601 return false; |
| 602 | 602 |
| 603 *result = resources_[index]->GetV8MemoryUsed(); | 603 *result = resources_[index]->GetV8MemoryUsed(); |
| 604 return true; | 604 return true; |
| 605 } | 605 } |
| 606 | 606 |
| 607 bool TaskManagerModel::CanActivate(int index) const { | 607 bool TaskManagerModel::CanActivate(int index) const { |
| 608 CHECK_LT(index, ResourceCount()); | 608 CHECK_LT(index, ResourceCount()); |
| 609 return GetResourceTabContents(index) != NULL; | 609 return GetResourceWebContents(index) != NULL; |
| 610 } | 610 } |
| 611 | 611 |
| 612 bool TaskManagerModel::CanInspect(int index) const { | 612 bool TaskManagerModel::CanInspect(int index) const { |
| 613 CHECK_LT(index, ResourceCount()); | 613 CHECK_LT(index, ResourceCount()); |
| 614 return resources_[index]->CanInspect(); | 614 return resources_[index]->CanInspect(); |
| 615 } | 615 } |
| 616 | 616 |
| 617 void TaskManagerModel::Inspect(int index) const { | 617 void TaskManagerModel::Inspect(int index) const { |
| 618 CHECK_LT(index, ResourceCount()); | 618 CHECK_LT(index, ResourceCount()); |
| 619 resources_[index]->Inspect(); | 619 resources_[index]->Inspect(); |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 } | 1089 } |
| 1090 | 1090 |
| 1091 void TaskManager::KillProcess(int index) { | 1091 void TaskManager::KillProcess(int index) { |
| 1092 base::ProcessHandle process = model_->GetResourceProcessHandle(index); | 1092 base::ProcessHandle process = model_->GetResourceProcessHandle(index); |
| 1093 DCHECK(process); | 1093 DCHECK(process); |
| 1094 if (process != base::GetCurrentProcessHandle()) | 1094 if (process != base::GetCurrentProcessHandle()) |
| 1095 base::KillProcess(process, content::RESULT_CODE_KILLED, false); | 1095 base::KillProcess(process, content::RESULT_CODE_KILLED, false); |
| 1096 } | 1096 } |
| 1097 | 1097 |
| 1098 void TaskManager::ActivateProcess(int index) { | 1098 void TaskManager::ActivateProcess(int index) { |
| 1099 // GetResourceTabContents returns a pointer to the relevant tab contents for | 1099 // GetResourceWebContents returns a pointer to the relevant web contents for |
| 1100 // the resource. If the index doesn't correspond to a Tab (i.e. refers to | 1100 // the resource. If the index doesn't correspond to any web contents |
| 1101 // the Browser process or a plugin), GetTabContents will return NULL. | 1101 // (i.e. refers to the Browser process or a plugin), GetWebContents will |
| 1102 TabContents* chosen_tab_contents = model_->GetResourceTabContents(index); | 1102 // return NULL. |
| 1103 if (chosen_tab_contents) { | 1103 WebContents* chosen_web_contents = model_->GetResourceWebContents(index); |
| 1104 WebContents* web_contents = chosen_tab_contents->web_contents(); | 1104 if (chosen_web_contents && chosen_web_contents->GetDelegate()) |
| 1105 if (web_contents->GetDelegate()) | 1105 chosen_web_contents->GetDelegate()->ActivateContents(chosen_web_contents); |
| 1106 web_contents->GetDelegate()->ActivateContents(web_contents); | |
| 1107 } | |
| 1108 } | 1106 } |
| 1109 | 1107 |
| 1110 void TaskManager::AddResource(Resource* resource) { | 1108 void TaskManager::AddResource(Resource* resource) { |
| 1111 model_->AddResource(resource); | 1109 model_->AddResource(resource); |
| 1112 } | 1110 } |
| 1113 | 1111 |
| 1114 void TaskManager::RemoveResource(Resource* resource) { | 1112 void TaskManager::RemoveResource(Resource* resource) { |
| 1115 model_->RemoveResource(resource); | 1113 model_->RemoveResource(resource); |
| 1116 } | 1114 } |
| 1117 | 1115 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 // Count the number of extensions with background pages (including | 1190 // Count the number of extensions with background pages (including |
| 1193 // incognito). | 1191 // incognito). |
| 1194 count += CountExtensionBackgroundPagesForProfile(profile); | 1192 count += CountExtensionBackgroundPagesForProfile(profile); |
| 1195 if (profile->HasOffTheRecordProfile()) { | 1193 if (profile->HasOffTheRecordProfile()) { |
| 1196 count += CountExtensionBackgroundPagesForProfile( | 1194 count += CountExtensionBackgroundPagesForProfile( |
| 1197 profile->GetOffTheRecordProfile()); | 1195 profile->GetOffTheRecordProfile()); |
| 1198 } | 1196 } |
| 1199 } | 1197 } |
| 1200 return count; | 1198 return count; |
| 1201 } | 1199 } |
| OLD | NEW |