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

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

Issue 10113005: Remove EPM:all_hosts_ and use all_extension_views_ instead. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Comments addressed Created 8 years, 8 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
OLDNEW
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_resource_providers.h" 5 #include "chrome/browser/task_manager/task_manager_resource_providers.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/file_version_info.h" 11 #include "base/file_version_info.h"
12 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
13 #include "base/process_util.h" 13 #include "base/process_util.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 #include "chrome/app/chrome_command_ids.h" 19 #include "chrome/app/chrome_command_ids.h"
20 #include "chrome/browser/background/background_contents_service.h" 20 #include "chrome/browser/background/background_contents_service.h"
21 #include "chrome/browser/background/background_contents_service_factory.h" 21 #include "chrome/browser/background/background_contents_service_factory.h"
22 #include "chrome/browser/browser_process.h" 22 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/debugger/devtools_window.h" 23 #include "chrome/browser/debugger/devtools_window.h"
24 #include "chrome/browser/extensions/extension_host.h" 24 #include "chrome/browser/extensions/extension_host.h"
25 #include "chrome/browser/extensions/extension_process_manager.h" 25 #include "chrome/browser/extensions/extension_process_manager.h"
26 #include "chrome/browser/extensions/extension_service.h" 26 #include "chrome/browser/extensions/extension_service.h"
27 #include "chrome/browser/extensions/extension_system.h"
27 #include "chrome/browser/favicon/favicon_tab_helper.h" 28 #include "chrome/browser/favicon/favicon_tab_helper.h"
28 #include "chrome/browser/instant/instant_controller.h" 29 #include "chrome/browser/instant/instant_controller.h"
29 #include "chrome/browser/prerender/prerender_manager.h" 30 #include "chrome/browser/prerender/prerender_manager.h"
30 #include "chrome/browser/prerender/prerender_manager_factory.h" 31 #include "chrome/browser/prerender/prerender_manager_factory.h"
31 #include "chrome/browser/profiles/profile.h" 32 #include "chrome/browser/profiles/profile.h"
32 #include "chrome/browser/profiles/profile_info_cache.h" 33 #include "chrome/browser/profiles/profile_info_cache.h"
33 #include "chrome/browser/profiles/profile_manager.h" 34 #include "chrome/browser/profiles/profile_manager.h"
34 #include "chrome/browser/tab_contents/background_contents.h" 35 #include "chrome/browser/tab_contents/background_contents.h"
35 #include "chrome/browser/tab_contents/tab_util.h" 36 #include "chrome/browser/tab_contents/tab_util.h"
36 #include "chrome/browser/ui/browser_list.h" 37 #include "chrome/browser/ui/browser_list.h"
37 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 38 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
38 #include "chrome/common/chrome_notification_types.h" 39 #include "chrome/common/chrome_notification_types.h"
39 #include "chrome/common/chrome_switches.h" 40 #include "chrome/common/chrome_switches.h"
40 #include "chrome/common/chrome_view_type.h" 41 #include "chrome/common/chrome_view_type.h"
41 #include "chrome/common/extensions/extension.h" 42 #include "chrome/common/extensions/extension.h"
42 #include "chrome/common/render_messages.h" 43 #include "chrome/common/render_messages.h"
43 #include "chrome/common/url_constants.h" 44 #include "chrome/common/url_constants.h"
44 #include "content/public/browser/browser_child_process_host_iterator.h" 45 #include "content/public/browser/browser_child_process_host_iterator.h"
45 #include "content/public/browser/browser_thread.h" 46 #include "content/public/browser/browser_thread.h"
46 #include "content/public/browser/child_process_data.h" 47 #include "content/public/browser/child_process_data.h"
47 #include "content/public/browser/notification_service.h" 48 #include "content/public/browser/notification_service.h"
48 #include "content/public/browser/render_process_host.h" 49 #include "content/public/browser/render_process_host.h"
49 #include "content/public/browser/render_view_host.h" 50 #include "content/public/browser/render_view_host.h"
51 #include "content/public/browser/render_view_host_delegate.h"
50 #include "content/public/browser/web_contents.h" 52 #include "content/public/browser/web_contents.h"
51 #include "content/public/common/process_type.h" 53 #include "content/public/common/process_type.h"
54 #include "content/public/common/view_type.h"
52 #include "grit/generated_resources.h" 55 #include "grit/generated_resources.h"
53 #include "grit/theme_resources.h" 56 #include "grit/theme_resources.h"
54 #include "grit/theme_resources_standard.h" 57 #include "grit/theme_resources_standard.h"
55 #include "third_party/sqlite/sqlite3.h" 58 #include "third_party/sqlite/sqlite3.h"
56 #include "ui/base/l10n/l10n_util.h" 59 #include "ui/base/l10n/l10n_util.h"
57 #include "ui/base/resource/resource_bundle.h" 60 #include "ui/base/resource/resource_bundle.h"
58 #include "v8/include/v8.h" 61 #include "v8/include/v8.h"
59 62
60 #if defined(OS_MACOSX) 63 #if defined(OS_MACOSX)
61 #include "skia/ext/skia_utils_mac.h" 64 #include "skia/ext/skia_utils_mac.h"
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 Add(child_processes[i]); 1113 Add(child_processes[i]);
1111 } 1114 }
1112 1115
1113 //////////////////////////////////////////////////////////////////////////////// 1116 ////////////////////////////////////////////////////////////////////////////////
1114 // TaskManagerExtensionProcessResource class 1117 // TaskManagerExtensionProcessResource class
1115 //////////////////////////////////////////////////////////////////////////////// 1118 ////////////////////////////////////////////////////////////////////////////////
1116 1119
1117 SkBitmap* TaskManagerExtensionProcessResource::default_icon_ = NULL; 1120 SkBitmap* TaskManagerExtensionProcessResource::default_icon_ = NULL;
1118 1121
1119 TaskManagerExtensionProcessResource::TaskManagerExtensionProcessResource( 1122 TaskManagerExtensionProcessResource::TaskManagerExtensionProcessResource(
1120 ExtensionHost* extension_host) 1123 content::RenderViewHost* render_view_host)
1121 : extension_host_(extension_host) { 1124 : render_view_host_(render_view_host) {
1122 if (!default_icon_) { 1125 if (!default_icon_) {
1123 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1126 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1124 default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); 1127 default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN);
1125 } 1128 }
1126 process_handle_ = extension_host_->render_process_host()->GetHandle(); 1129 process_handle_ = render_view_host_->GetProcess()->GetHandle();
1127 unique_process_id_ = extension_host_->render_process_host()->GetID(); 1130 unique_process_id_ = render_view_host->GetProcess()->GetID();
1128 pid_ = base::GetProcId(process_handle_); 1131 pid_ = base::GetProcId(process_handle_);
1129 string16 extension_name = UTF8ToUTF16(GetExtension()->name()); 1132 string16 extension_name = UTF8ToUTF16(GetExtension()->name());
1130 DCHECK(!extension_name.empty()); 1133 DCHECK(!extension_name.empty());
1131 1134
1135 Profile* profile = Profile::FromBrowserContext(
1136 render_view_host->GetProcess()->GetBrowserContext());
1132 int message_id = GetMessagePrefixID(GetExtension()->is_app(), true, 1137 int message_id = GetMessagePrefixID(GetExtension()->is_app(), true,
1133 extension_host_->profile()->IsOffTheRecord(), false, false); 1138 profile->IsOffTheRecord(), false, false);
1134 title_ = l10n_util::GetStringFUTF16(message_id, extension_name); 1139 title_ = l10n_util::GetStringFUTF16(message_id, extension_name);
1135 } 1140 }
1136 1141
1137 TaskManagerExtensionProcessResource::~TaskManagerExtensionProcessResource() { 1142 TaskManagerExtensionProcessResource::~TaskManagerExtensionProcessResource() {
1138 } 1143 }
1139 1144
1140 string16 TaskManagerExtensionProcessResource::GetTitle() const { 1145 string16 TaskManagerExtensionProcessResource::GetTitle() const {
1141 return title_; 1146 return title_;
1142 } 1147 }
1143 1148
1144 string16 TaskManagerExtensionProcessResource::GetProfileName() const { 1149 string16 TaskManagerExtensionProcessResource::GetProfileName() const {
1145 ProfileInfoCache& cache = 1150 ProfileInfoCache& cache =
1146 g_browser_process->profile_manager()->GetProfileInfoCache(); 1151 g_browser_process->profile_manager()->GetProfileInfoCache();
1147 Profile* profile = extension_host_->profile()->GetOriginalProfile(); 1152 Profile* profile = Profile::FromBrowserContext(
1153 render_view_host_->GetProcess()->GetBrowserContext());
1154 profile = profile->GetOriginalProfile();
1148 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); 1155 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath());
1149 if (index == std::string::npos) 1156 if (index == std::string::npos)
1150 return string16(); 1157 return string16();
1151 else 1158 else
1152 return cache.GetNameOfProfileAtIndex(index); 1159 return cache.GetNameOfProfileAtIndex(index);
1153 } 1160 }
1154 1161
1155 SkBitmap TaskManagerExtensionProcessResource::GetIcon() const { 1162 SkBitmap TaskManagerExtensionProcessResource::GetIcon() const {
1156 return *default_icon_; 1163 return *default_icon_;
1157 } 1164 }
1158 1165
1159 base::ProcessHandle TaskManagerExtensionProcessResource::GetProcess() const { 1166 base::ProcessHandle TaskManagerExtensionProcessResource::GetProcess() const {
1160 return process_handle_; 1167 return process_handle_;
1161 } 1168 }
1162 1169
1163 int TaskManagerExtensionProcessResource::GetUniqueChildProcessId() const { 1170 int TaskManagerExtensionProcessResource::GetUniqueChildProcessId() const {
1164 return unique_process_id_; 1171 return unique_process_id_;
1165 } 1172 }
1166 1173
1167 TaskManager::Resource::Type 1174 TaskManager::Resource::Type
1168 TaskManagerExtensionProcessResource::GetType() const { 1175 TaskManagerExtensionProcessResource::GetType() const {
1169 return EXTENSION; 1176 return EXTENSION;
1170 } 1177 }
1171 1178
1172 bool TaskManagerExtensionProcessResource::CanInspect() const { 1179 bool TaskManagerExtensionProcessResource::CanInspect() const {
1173 return true; 1180 return true;
1174 } 1181 }
1175 1182
1176 void TaskManagerExtensionProcessResource::Inspect() const { 1183 void TaskManagerExtensionProcessResource::Inspect() const {
1177 DevToolsWindow::OpenDevToolsWindow(extension_host_->render_view_host()); 1184 DevToolsWindow::OpenDevToolsWindow(render_view_host_);
1178 } 1185 }
1179 1186
1180 bool TaskManagerExtensionProcessResource::SupportNetworkUsage() const { 1187 bool TaskManagerExtensionProcessResource::SupportNetworkUsage() const {
1181 return true; 1188 return true;
1182 } 1189 }
1183 1190
1184 void TaskManagerExtensionProcessResource::SetSupportNetworkUsage() { 1191 void TaskManagerExtensionProcessResource::SetSupportNetworkUsage() {
1185 NOTREACHED(); 1192 NOTREACHED();
1186 } 1193 }
1187 1194
1188 const Extension* TaskManagerExtensionProcessResource::GetExtension() const { 1195 const Extension* TaskManagerExtensionProcessResource::GetExtension() const {
1189 return extension_host_->extension(); 1196 Profile* profile = Profile::FromBrowserContext(
1197 render_view_host_->GetProcess()->GetBrowserContext());
1198 ExtensionProcessManager* process_manager =
1199 ExtensionSystem::Get(profile)->process_manager();
1200 return process_manager->GetExtensionForRenderViewHost(render_view_host_);
1190 } 1201 }
1191 1202
1192 bool TaskManagerExtensionProcessResource::IsBackground() const { 1203 bool TaskManagerExtensionProcessResource::IsBackground() const {
1193 return extension_host_->extension_host_type() == 1204 return render_view_host_->GetDelegate()->GetRenderViewType() ==
1194 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; 1205 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE;
1195 } 1206 }
1196 1207
1197 //////////////////////////////////////////////////////////////////////////////// 1208 ////////////////////////////////////////////////////////////////////////////////
1198 // TaskManagerExtensionProcessResourceProvider class 1209 // TaskManagerExtensionProcessResourceProvider class
1199 //////////////////////////////////////////////////////////////////////////////// 1210 ////////////////////////////////////////////////////////////////////////////////
1200 1211
1201 TaskManagerExtensionProcessResourceProvider:: 1212 TaskManagerExtensionProcessResourceProvider::
1202 TaskManagerExtensionProcessResourceProvider(TaskManager* task_manager) 1213 TaskManagerExtensionProcessResourceProvider(TaskManager* task_manager)
1203 : task_manager_(task_manager), 1214 : task_manager_(task_manager),
(...skipping 13 matching lines...) Expand all
1217 if (iter != pid_to_resources_.end()) 1228 if (iter != pid_to_resources_.end())
1218 return iter->second; 1229 return iter->second;
1219 else 1230 else
1220 return NULL; 1231 return NULL;
1221 } 1232 }
1222 1233
1223 void TaskManagerExtensionProcessResourceProvider::StartUpdating() { 1234 void TaskManagerExtensionProcessResourceProvider::StartUpdating() {
1224 DCHECK(!updating_); 1235 DCHECK(!updating_);
1225 updating_ = true; 1236 updating_ = true;
1226 1237
1227 // Add all the existing ExtensionHosts from all Profiles, including those from 1238 // Add all the existing extension views from all Profiles, including those
1228 // incognito split mode. 1239 // from incognito split mode.
1229 ProfileManager* profile_manager = g_browser_process->profile_manager(); 1240 ProfileManager* profile_manager = g_browser_process->profile_manager();
1230 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); 1241 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles());
1231 size_t num_default_profiles = profiles.size(); 1242 size_t num_default_profiles = profiles.size();
1232 for (size_t i = 0; i < num_default_profiles; ++i) { 1243 for (size_t i = 0; i < num_default_profiles; ++i) {
1233 if (profiles[i]->HasOffTheRecordProfile()) { 1244 if (profiles[i]->HasOffTheRecordProfile()) {
1234 profiles.push_back(profiles[i]->GetOffTheRecordProfile()); 1245 profiles.push_back(profiles[i]->GetOffTheRecordProfile());
1235 } 1246 }
1236 } 1247 }
1248
1237 for (size_t i = 0; i < profiles.size(); ++i) { 1249 for (size_t i = 0; i < profiles.size(); ++i) {
1238 ExtensionProcessManager* process_manager = 1250 ExtensionProcessManager* process_manager =
1239 profiles[i]->GetExtensionProcessManager(); 1251 profiles[i]->GetExtensionProcessManager();
1240 if (process_manager) { 1252 if (process_manager) {
1241 ExtensionProcessManager::const_iterator jt; 1253 const ExtensionProcessManager::ViewSet all_views =
1242 for (jt = process_manager->begin(); jt != process_manager->end(); ++jt) { 1254 process_manager->GetAllViews();
1255 ExtensionProcessManager::ViewSet::const_iterator jt = all_views.begin();
1256 for (; jt != all_views.end(); ++jt) {
1257 content::RenderViewHost* rvh = *jt;
1243 // Don't add dead extension processes. 1258 // Don't add dead extension processes.
1244 if ((*jt)->IsRenderViewLive()) 1259 if (!rvh->IsRenderViewLive())
1245 AddToTaskManager(*jt); 1260 continue;
1261
1262 // Don't add WebContents (those are handled by
1263 // TaskManagerTabContentsResourceProvider) or background contents
1264 // (handled by TaskManagerBackgroundResourceProvider).
1265 // TODO(benwells): create specific chrome::VIEW_TYPE_TAB_CONTENTS for
1266 // tab contents, as VIEW_TYPE_WEB_CONTENTS is the default.
1267 content::ViewType view_type = rvh->GetDelegate()->GetRenderViewType();
1268 if (view_type == content::VIEW_TYPE_WEB_CONTENTS ||
1269 view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1270 continue;
1271 }
1272
1273 AddToTaskManager(rvh);
1246 } 1274 }
1247 } 1275 }
1248 } 1276 }
1249 1277
1250 // Register for notifications about extension process changes. 1278 // Register for notifications about extension process changes.
1251 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED, 1279 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED,
1252 content::NotificationService::AllBrowserContextsAndSources()); 1280 content::NotificationService::AllBrowserContextsAndSources());
1253 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, 1281 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
1254 content::NotificationService::AllBrowserContextsAndSources()); 1282 content::NotificationService::AllBrowserContextsAndSources());
1255 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, 1283 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
(...skipping 21 matching lines...) Expand all
1277 resources_.clear(); 1305 resources_.clear();
1278 pid_to_resources_.clear(); 1306 pid_to_resources_.clear();
1279 } 1307 }
1280 1308
1281 void TaskManagerExtensionProcessResourceProvider::Observe( 1309 void TaskManagerExtensionProcessResourceProvider::Observe(
1282 int type, 1310 int type,
1283 const content::NotificationSource& source, 1311 const content::NotificationSource& source,
1284 const content::NotificationDetails& details) { 1312 const content::NotificationDetails& details) {
1285 switch (type) { 1313 switch (type) {
1286 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: 1314 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED:
1287 AddToTaskManager(content::Details<ExtensionHost>(details).ptr()); 1315 AddToTaskManager(
1316 content::Details<ExtensionHost>(details).ptr()->render_view_host());
1288 break; 1317 break;
1289 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: 1318 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED:
1290 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: 1319 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED:
1291 RemoveFromTaskManager(content::Details<ExtensionHost>(details).ptr()); 1320 RemoveFromTaskManager(
1321 content::Details<ExtensionHost>(details).ptr()->render_view_host());
1292 break; 1322 break;
1293 default: 1323 default:
1294 NOTREACHED() << "Unexpected notification."; 1324 NOTREACHED() << "Unexpected notification.";
1295 return; 1325 return;
1296 } 1326 }
1297 } 1327 }
1298 1328
1299 void TaskManagerExtensionProcessResourceProvider::AddToTaskManager( 1329 void TaskManagerExtensionProcessResourceProvider::AddToTaskManager(
1300 ExtensionHost* extension_host) { 1330 content::RenderViewHost* render_view_host) {
1301 TaskManagerExtensionProcessResource* resource = 1331 TaskManagerExtensionProcessResource* resource =
1302 new TaskManagerExtensionProcessResource(extension_host); 1332 new TaskManagerExtensionProcessResource(render_view_host);
1303 DCHECK(resources_.find(extension_host) == resources_.end()); 1333 DCHECK(resources_.find(render_view_host) == resources_.end());
1304 resources_[extension_host] = resource; 1334 resources_[render_view_host] = resource;
1305 pid_to_resources_[resource->process_id()] = resource; 1335 pid_to_resources_[resource->process_id()] = resource;
1306 task_manager_->AddResource(resource); 1336 task_manager_->AddResource(resource);
1307 } 1337 }
1308 1338
1309 void TaskManagerExtensionProcessResourceProvider::RemoveFromTaskManager( 1339 void TaskManagerExtensionProcessResourceProvider::RemoveFromTaskManager(
1310 ExtensionHost* extension_host) { 1340 content::RenderViewHost* render_view_host) {
1311 if (!updating_) 1341 if (!updating_)
1312 return; 1342 return;
1313 std::map<ExtensionHost*, TaskManagerExtensionProcessResource*> 1343 std::map<content::RenderViewHost*, TaskManagerExtensionProcessResource*>
1314 ::iterator iter = resources_.find(extension_host); 1344 ::iterator iter = resources_.find(render_view_host);
1315 if (iter == resources_.end()) 1345 if (iter == resources_.end())
1316 return; 1346 return;
1317 1347
1318 // Remove the resource from the Task Manager. 1348 // Remove the resource from the Task Manager.
1319 TaskManagerExtensionProcessResource* resource = iter->second; 1349 TaskManagerExtensionProcessResource* resource = iter->second;
1320 task_manager_->RemoveResource(resource); 1350 task_manager_->RemoveResource(resource);
1321 1351
1322 // Remove it from the provider. 1352 // Remove it from the provider.
1323 resources_.erase(iter); 1353 resources_.erase(iter);
1324 1354
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 1492
1463 return &resource_; 1493 return &resource_;
1464 } 1494 }
1465 1495
1466 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { 1496 void TaskManagerBrowserProcessResourceProvider::StartUpdating() {
1467 task_manager_->AddResource(&resource_); 1497 task_manager_->AddResource(&resource_);
1468 } 1498 }
1469 1499
1470 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { 1500 void TaskManagerBrowserProcessResourceProvider::StopUpdating() {
1471 } 1501 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698