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.h" | 26 #include "chrome/browser/ui/browser_navigator.h" |
27 #include "chrome/browser/ui/browser_list.h" | |
28 #include "chrome/browser/ui/browser_window.h" | |
29 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 27 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
30 #include "chrome/common/chrome_view_type.h" | 28 #include "chrome/common/chrome_view_type.h" |
31 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
32 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
33 #include "content/public/browser/browser_child_process_host.h" | 31 #include "content/public/browser/browser_child_process_host.h" |
34 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
35 #include "content/public/browser/render_view_host.h" | 33 #include "content/public/browser/render_view_host.h" |
36 #include "content/public/browser/render_view_host_delegate.h" | 34 #include "content/public/browser/render_view_host_delegate.h" |
37 #include "content/public/browser/resource_request_info.h" | 35 #include "content/public/browser/resource_request_info.h" |
38 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
(...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 void TaskManager::ModelChanged() { | 1119 void TaskManager::ModelChanged() { |
1122 model_->ModelChanged(); | 1120 model_->ModelChanged(); |
1123 } | 1121 } |
1124 | 1122 |
1125 // static | 1123 // static |
1126 TaskManager* TaskManager::GetInstance() { | 1124 TaskManager* TaskManager::GetInstance() { |
1127 return Singleton<TaskManager>::get(); | 1125 return Singleton<TaskManager>::get(); |
1128 } | 1126 } |
1129 | 1127 |
1130 void TaskManager::OpenAboutMemory() { | 1128 void TaskManager::OpenAboutMemory() { |
1131 Browser* browser = BrowserList::GetLastActive(); | 1129 browser::NavigateParams params(NULL, |
1132 OpenURLParams params( | 1130 GURL(chrome::kChromeUIMemoryURL), |
1133 GURL(chrome::kChromeUIMemoryURL), Referrer(), NEW_FOREGROUND_TAB, | 1131 content::PAGE_TRANSITION_LINK); |
1134 content::PAGE_TRANSITION_LINK, false); | 1132 params.disposition = NEW_FOREGROUND_TAB; |
1135 | 1133 browser::Navigate(¶ms); |
1136 if (!browser) { | |
1137 // On OS X, the task manager can be open without any open browser windows. | |
1138 if (!g_browser_process || !g_browser_process->profile_manager()) | |
1139 return; | |
1140 Profile* profile = | |
1141 g_browser_process->profile_manager()->GetLastUsedProfile(); | |
1142 if (!profile) | |
1143 return; | |
1144 browser = Browser::Create(profile); | |
1145 browser->OpenURL(params); | |
1146 } else { | |
1147 browser->OpenURL(params); | |
1148 | |
1149 // In case the browser window is minimized, show it. If |browser| is a | |
1150 // non-tabbed window, the call to OpenURL above will have opened a | |
1151 // TabContentsWrapper in a tabbed browser, so we need to grab it with | |
1152 // GetLastActive before the call to show(). | |
1153 if (!browser->is_type_tabbed()) { | |
1154 browser = BrowserList::GetLastActive(); | |
1155 DCHECK(browser); | |
1156 } | |
1157 } | |
1158 browser->window()->Show(); | |
1159 } | 1134 } |
1160 | 1135 |
1161 bool TaskManagerModel::GetAndCacheMemoryMetrics(base::ProcessHandle handle, | 1136 bool TaskManagerModel::GetAndCacheMemoryMetrics(base::ProcessHandle handle, |
1162 MemoryUsageEntry* usage) const { | 1137 MemoryUsageEntry* usage) const { |
1163 MetricsMap::const_iterator iter = metrics_map_.find(handle); | 1138 MetricsMap::const_iterator iter = metrics_map_.find(handle); |
1164 if (iter == metrics_map_.end()) | 1139 if (iter == metrics_map_.end()) |
1165 return false; | 1140 return false; |
1166 | 1141 |
1167 if (!iter->second->GetMemoryBytes(&usage->first, &usage->second)) | 1142 if (!iter->second->GetMemoryBytes(&usage->first, &usage->second)) |
1168 return false; | 1143 return false; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1213 // Count the number of extensions with background pages (including | 1188 // Count the number of extensions with background pages (including |
1214 // incognito). | 1189 // incognito). |
1215 count += CountExtensionBackgroundPagesForProfile(profile); | 1190 count += CountExtensionBackgroundPagesForProfile(profile); |
1216 if (profile->HasOffTheRecordProfile()) { | 1191 if (profile->HasOffTheRecordProfile()) { |
1217 count += CountExtensionBackgroundPagesForProfile( | 1192 count += CountExtensionBackgroundPagesForProfile( |
1218 profile->GetOffTheRecordProfile()); | 1193 profile->GetOffTheRecordProfile()); |
1219 } | 1194 } |
1220 } | 1195 } |
1221 return count; | 1196 return count; |
1222 } | 1197 } |
OLD | NEW |