OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 Loading... | |
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 |
jam
2011/02/03 22:58:07
I don't understand this line and below on 453. wh
| |
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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 | 438 |
448 TaskManagerBackgroundContentsResourceProvider:: | 439 TaskManagerBackgroundContentsResourceProvider:: |
449 ~TaskManagerBackgroundContentsResourceProvider() { | 440 ~TaskManagerBackgroundContentsResourceProvider() { |
450 } | 441 } |
451 | 442 |
452 TaskManager::Resource* | 443 TaskManager::Resource* |
453 TaskManagerBackgroundContentsResourceProvider::GetResource( | 444 TaskManagerBackgroundContentsResourceProvider::GetResource( |
454 int origin_pid, | 445 int origin_pid, |
455 int render_process_host_id, | 446 int render_process_host_id, |
456 int routing_id) { | 447 int routing_id) { |
457 | |
458 BackgroundContents* contents = BackgroundContents::GetBackgroundContentsByID( | 448 BackgroundContents* contents = BackgroundContents::GetBackgroundContentsByID( |
459 render_process_host_id, routing_id); | 449 render_process_host_id, routing_id); |
460 if (!contents) // This resource no longer exists. | 450 if (!contents) // This resource no longer exists. |
461 return NULL; | 451 return NULL; |
462 | 452 |
463 base::ProcessHandle process_handle = | 453 // If an origin PID was specified, the request is from a plugin, not the |
464 contents->render_view_host()->process()->GetHandle(); | 454 // render view host process |
465 if (!process_handle) // Process crashed. | 455 if (origin_pid) |
466 return NULL; | |
467 | |
468 int pid = base::GetProcId(process_handle); | |
469 if (pid != origin_pid) | |
470 return NULL; | 456 return NULL; |
471 | 457 |
472 std::map<BackgroundContents*, | 458 std::map<BackgroundContents*, |
473 TaskManagerBackgroundContentsResource*>::iterator res_iter = | 459 TaskManagerBackgroundContentsResource*>::iterator res_iter = |
474 resources_.find(contents); | 460 resources_.find(contents); |
475 if (res_iter == resources_.end()) | 461 if (res_iter == resources_.end()) |
476 // Can happen if the page went away while a network request was being | 462 // Can happen if the page went away while a network request was being |
477 // performed. | 463 // performed. |
478 return NULL; | 464 return NULL; |
479 | 465 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
636 //////////////////////////////////////////////////////////////////////////////// | 622 //////////////////////////////////////////////////////////////////////////////// |
637 SkBitmap* TaskManagerChildProcessResource::default_icon_ = NULL; | 623 SkBitmap* TaskManagerChildProcessResource::default_icon_ = NULL; |
638 | 624 |
639 TaskManagerChildProcessResource::TaskManagerChildProcessResource( | 625 TaskManagerChildProcessResource::TaskManagerChildProcessResource( |
640 const ChildProcessInfo& child_proc) | 626 const ChildProcessInfo& child_proc) |
641 : child_process_(child_proc), | 627 : child_process_(child_proc), |
642 title_(), | 628 title_(), |
643 network_usage_support_(false) { | 629 network_usage_support_(false) { |
644 // We cache the process id because it's not cheap to calculate, and it won't | 630 // We cache the process id because it's not cheap to calculate, and it won't |
645 // be available when we get the plugin disconnected notification. | 631 // be available when we get the plugin disconnected notification. |
646 pid_ = child_proc.id(); | 632 pid_ = child_proc.process_id(); |
647 if (!default_icon_) { | 633 if (!default_icon_) { |
648 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 634 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
649 default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); | 635 default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); |
650 // TODO(jabdelmalek): use different icon for web workers. | 636 // TODO(jabdelmalek): use different icon for web workers. |
651 } | 637 } |
652 } | 638 } |
653 | 639 |
654 TaskManagerChildProcessResource::~TaskManagerChildProcessResource() { | 640 TaskManagerChildProcessResource::~TaskManagerChildProcessResource() { |
655 } | 641 } |
656 | 642 |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1216 } | 1202 } |
1217 | 1203 |
1218 //////////////////////////////////////////////////////////////////////////////// | 1204 //////////////////////////////////////////////////////////////////////////////// |
1219 // TaskManagerBrowserProcessResource class | 1205 // TaskManagerBrowserProcessResource class |
1220 //////////////////////////////////////////////////////////////////////////////// | 1206 //////////////////////////////////////////////////////////////////////////////// |
1221 | 1207 |
1222 SkBitmap* TaskManagerBrowserProcessResource::default_icon_ = NULL; | 1208 SkBitmap* TaskManagerBrowserProcessResource::default_icon_ = NULL; |
1223 | 1209 |
1224 TaskManagerBrowserProcessResource::TaskManagerBrowserProcessResource() | 1210 TaskManagerBrowserProcessResource::TaskManagerBrowserProcessResource() |
1225 : title_() { | 1211 : title_() { |
1226 pid_ = base::GetCurrentProcId(); | 1212 int pid = base::GetCurrentProcId(); |
1227 bool success = base::OpenPrivilegedProcessHandle(pid_, &process_); | 1213 bool success = base::OpenPrivilegedProcessHandle(pid, &process_); |
1228 DCHECK(success); | 1214 DCHECK(success); |
1229 #if defined(OS_WIN) | 1215 #if defined(OS_WIN) |
1230 if (!default_icon_) { | 1216 if (!default_icon_) { |
1231 HICON icon = GetAppIcon(); | 1217 HICON icon = GetAppIcon(); |
1232 if (icon) { | 1218 if (icon) { |
1233 ICONINFO icon_info = {0}; | 1219 ICONINFO icon_info = {0}; |
1234 BITMAP bitmap_info = {0}; | 1220 BITMAP bitmap_info = {0}; |
1235 | 1221 |
1236 GetIconInfo(icon, &icon_info); | 1222 GetIconInfo(icon, &icon_info); |
1237 GetObject(icon_info.hbmMask, sizeof(bitmap_info), &bitmap_info); | 1223 GetObject(icon_info.hbmMask, sizeof(bitmap_info), &bitmap_info); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1309 } | 1295 } |
1310 | 1296 |
1311 TaskManagerBrowserProcessResourceProvider:: | 1297 TaskManagerBrowserProcessResourceProvider:: |
1312 ~TaskManagerBrowserProcessResourceProvider() { | 1298 ~TaskManagerBrowserProcessResourceProvider() { |
1313 } | 1299 } |
1314 | 1300 |
1315 TaskManager::Resource* TaskManagerBrowserProcessResourceProvider::GetResource( | 1301 TaskManager::Resource* TaskManagerBrowserProcessResourceProvider::GetResource( |
1316 int origin_pid, | 1302 int origin_pid, |
1317 int render_process_host_id, | 1303 int render_process_host_id, |
1318 int routing_id) { | 1304 int routing_id) { |
1319 if (origin_pid != resource_.process_id()) { | 1305 if (origin_pid || render_process_host_id != -1) { |
1320 return NULL; | 1306 return NULL; |
1321 } | 1307 } |
1322 | 1308 |
1323 return &resource_; | 1309 return &resource_; |
1324 } | 1310 } |
1325 | 1311 |
1326 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { | 1312 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { |
1327 task_manager_->AddResource(&resource_); | 1313 task_manager_->AddResource(&resource_); |
1328 } | 1314 } |
1329 | 1315 |
1330 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { | 1316 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { |
1331 } | 1317 } |
OLD | NEW |