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

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

Issue 6328010: Fix Task Manager to correctly display network usage of plug-in processes. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Redo patch set for changes to trunk. Created 9 years, 10 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/file_version_info.h" 10 #include "base/file_version_info.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 227 }
228 228
229 TaskManagerTabContentsResourceProvider:: 229 TaskManagerTabContentsResourceProvider::
230 ~TaskManagerTabContentsResourceProvider() { 230 ~TaskManagerTabContentsResourceProvider() {
231 } 231 }
232 232
233 TaskManager::Resource* TaskManagerTabContentsResourceProvider::GetResource( 233 TaskManager::Resource* TaskManagerTabContentsResourceProvider::GetResource(
234 int origin_pid, 234 int origin_pid,
235 int render_process_host_id, 235 int render_process_host_id,
236 int routing_id) { 236 int routing_id) {
237
238 TabContents* tab_contents = 237 TabContents* tab_contents =
239 tab_util::GetTabContentsByID(render_process_host_id, routing_id); 238 tab_util::GetTabContentsByID(render_process_host_id, routing_id);
240 if (!tab_contents) // Not one of our resource. 239 if (!tab_contents) // Not one of our resource.
241 return NULL; 240 return NULL;
242 241
243 base::ProcessHandle process_handle = 242 // If an origin PID was specified then the request originated in a plugin
244 tab_contents->GetRenderProcessHost()->GetHandle(); 243 // working on the TabContent's behalf, so ignore it.
245 if (!process_handle) { 244 if (origin_pid)
246 // We should not be holding on to a dead tab (it should have been removed
247 // through the NOTIFY_TAB_CONTENTS_DISCONNECTED notification.
248 NOTREACHED();
249 return NULL;
250 }
251
252 int pid = base::GetProcId(process_handle);
253 if (pid != origin_pid)
254 return NULL; 245 return NULL;
255 246
256 std::map<TabContents*, TaskManagerTabContentsResource*>::iterator 247 std::map<TabContents*, TaskManagerTabContentsResource*>::iterator
257 res_iter = resources_.find(tab_contents); 248 res_iter = resources_.find(tab_contents);
258 if (res_iter == resources_.end()) { 249 if (res_iter == resources_.end()) {
259 // Can happen if the tab was closed while a network request was being 250 // Can happen if the tab was closed while a network request was being
260 // performed. 251 // performed.
261 return NULL; 252 return NULL;
262 } 253 }
263 return res_iter->second; 254 return res_iter->second;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 437
447 TaskManagerBackgroundContentsResourceProvider:: 438 TaskManagerBackgroundContentsResourceProvider::
448 ~TaskManagerBackgroundContentsResourceProvider() { 439 ~TaskManagerBackgroundContentsResourceProvider() {
449 } 440 }
450 441
451 TaskManager::Resource* 442 TaskManager::Resource*
452 TaskManagerBackgroundContentsResourceProvider::GetResource( 443 TaskManagerBackgroundContentsResourceProvider::GetResource(
453 int origin_pid, 444 int origin_pid,
454 int render_process_host_id, 445 int render_process_host_id,
455 int routing_id) { 446 int routing_id) {
456
457 BackgroundContents* contents = BackgroundContents::GetBackgroundContentsByID( 447 BackgroundContents* contents = BackgroundContents::GetBackgroundContentsByID(
458 render_process_host_id, routing_id); 448 render_process_host_id, routing_id);
459 if (!contents) // This resource no longer exists. 449 if (!contents) // This resource no longer exists.
460 return NULL; 450 return NULL;
461 451
462 base::ProcessHandle process_handle = 452 // If an origin PID was specified, the request is from a plugin, not the
463 contents->render_view_host()->process()->GetHandle(); 453 // render view host process
464 if (!process_handle) // Process crashed. 454 if (origin_pid)
465 return NULL;
466
467 int pid = base::GetProcId(process_handle);
468 if (pid != origin_pid)
469 return NULL; 455 return NULL;
470 456
471 std::map<BackgroundContents*, 457 std::map<BackgroundContents*,
472 TaskManagerBackgroundContentsResource*>::iterator res_iter = 458 TaskManagerBackgroundContentsResource*>::iterator res_iter =
473 resources_.find(contents); 459 resources_.find(contents);
474 if (res_iter == resources_.end()) 460 if (res_iter == resources_.end())
475 // Can happen if the page went away while a network request was being 461 // Can happen if the page went away while a network request was being
476 // performed. 462 // performed.
477 return NULL; 463 return NULL;
478 464
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 //////////////////////////////////////////////////////////////////////////////// 621 ////////////////////////////////////////////////////////////////////////////////
636 SkBitmap* TaskManagerChildProcessResource::default_icon_ = NULL; 622 SkBitmap* TaskManagerChildProcessResource::default_icon_ = NULL;
637 623
638 TaskManagerChildProcessResource::TaskManagerChildProcessResource( 624 TaskManagerChildProcessResource::TaskManagerChildProcessResource(
639 const ChildProcessInfo& child_proc) 625 const ChildProcessInfo& child_proc)
640 : child_process_(child_proc), 626 : child_process_(child_proc),
641 title_(), 627 title_(),
642 network_usage_support_(false) { 628 network_usage_support_(false) {
643 // We cache the process id because it's not cheap to calculate, and it won't 629 // We cache the process id because it's not cheap to calculate, and it won't
644 // be available when we get the plugin disconnected notification. 630 // be available when we get the plugin disconnected notification.
645 pid_ = child_proc.id(); 631 pid_ = child_proc.pid();
646 if (!default_icon_) { 632 if (!default_icon_) {
647 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 633 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
648 default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); 634 default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN);
649 // TODO(jabdelmalek): use different icon for web workers. 635 // TODO(jabdelmalek): use different icon for web workers.
650 } 636 }
651 } 637 }
652 638
653 TaskManagerChildProcessResource::~TaskManagerChildProcessResource() { 639 TaskManagerChildProcessResource::~TaskManagerChildProcessResource() {
654 } 640 }
655 641
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 } 1199 }
1214 1200
1215 //////////////////////////////////////////////////////////////////////////////// 1201 ////////////////////////////////////////////////////////////////////////////////
1216 // TaskManagerBrowserProcessResource class 1202 // TaskManagerBrowserProcessResource class
1217 //////////////////////////////////////////////////////////////////////////////// 1203 ////////////////////////////////////////////////////////////////////////////////
1218 1204
1219 SkBitmap* TaskManagerBrowserProcessResource::default_icon_ = NULL; 1205 SkBitmap* TaskManagerBrowserProcessResource::default_icon_ = NULL;
1220 1206
1221 TaskManagerBrowserProcessResource::TaskManagerBrowserProcessResource() 1207 TaskManagerBrowserProcessResource::TaskManagerBrowserProcessResource()
1222 : title_() { 1208 : title_() {
1223 pid_ = base::GetCurrentProcId(); 1209 int pid = base::GetCurrentProcId();
1224 bool success = base::OpenPrivilegedProcessHandle(pid_, &process_); 1210 bool success = base::OpenPrivilegedProcessHandle(pid, &process_);
1225 DCHECK(success); 1211 DCHECK(success);
1226 #if defined(OS_WIN) 1212 #if defined(OS_WIN)
1227 if (!default_icon_) { 1213 if (!default_icon_) {
1228 HICON icon = GetAppIcon(); 1214 HICON icon = GetAppIcon();
1229 if (icon) { 1215 if (icon) {
1230 ICONINFO icon_info = {0}; 1216 ICONINFO icon_info = {0};
1231 BITMAP bitmap_info = {0}; 1217 BITMAP bitmap_info = {0};
1232 1218
1233 GetIconInfo(icon, &icon_info); 1219 GetIconInfo(icon, &icon_info);
1234 GetObject(icon_info.hbmMask, sizeof(bitmap_info), &bitmap_info); 1220 GetObject(icon_info.hbmMask, sizeof(bitmap_info), &bitmap_info);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 } 1291 }
1306 1292
1307 TaskManagerBrowserProcessResourceProvider:: 1293 TaskManagerBrowserProcessResourceProvider::
1308 ~TaskManagerBrowserProcessResourceProvider() { 1294 ~TaskManagerBrowserProcessResourceProvider() {
1309 } 1295 }
1310 1296
1311 TaskManager::Resource* TaskManagerBrowserProcessResourceProvider::GetResource( 1297 TaskManager::Resource* TaskManagerBrowserProcessResourceProvider::GetResource(
1312 int origin_pid, 1298 int origin_pid,
1313 int render_process_host_id, 1299 int render_process_host_id,
1314 int routing_id) { 1300 int routing_id) {
1315 if (origin_pid != resource_.process_id()) { 1301 if (origin_pid || render_process_host_id != -1) {
1316 return NULL; 1302 return NULL;
1317 } 1303 }
1318 1304
1319 return &resource_; 1305 return &resource_;
1320 } 1306 }
1321 1307
1322 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { 1308 void TaskManagerBrowserProcessResourceProvider::StartUpdating() {
1323 task_manager_->AddResource(&resource_); 1309 task_manager_->AddResource(&resource_);
1324 } 1310 }
1325 1311
1326 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { 1312 void TaskManagerBrowserProcessResourceProvider::StopUpdating() {
1327 } 1313 }
OLDNEW
« no previous file with comments | « chrome/browser/task_manager/task_manager_resource_providers.h ('k') | chrome/common/child_process_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698