| 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_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" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "chrome/browser/instant/instant_controller.h" | 30 #include "chrome/browser/instant/instant_controller.h" |
| 31 #include "chrome/browser/prerender/prerender_manager.h" | 31 #include "chrome/browser/prerender/prerender_manager.h" |
| 32 #include "chrome/browser/prerender/prerender_manager_factory.h" | 32 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 33 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
| 34 #include "chrome/browser/profiles/profile_info_cache.h" | 34 #include "chrome/browser/profiles/profile_info_cache.h" |
| 35 #include "chrome/browser/profiles/profile_manager.h" | 35 #include "chrome/browser/profiles/profile_manager.h" |
| 36 #include "chrome/browser/tab_contents/background_contents.h" | 36 #include "chrome/browser/tab_contents/background_contents.h" |
| 37 #include "chrome/browser/tab_contents/tab_util.h" | 37 #include "chrome/browser/tab_contents/tab_util.h" |
| 38 #include "chrome/browser/ui/browser.h" | 38 #include "chrome/browser/ui/browser.h" |
| 39 #include "chrome/browser/ui/browser_list.h" | 39 #include "chrome/browser/ui/browser_list.h" |
| 40 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 40 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | 41 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
| 41 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | |
| 42 #include "chrome/browser/view_type_utils.h" | 42 #include "chrome/browser/view_type_utils.h" |
| 43 #include "chrome/common/chrome_notification_types.h" | 43 #include "chrome/common/chrome_notification_types.h" |
| 44 #include "chrome/common/chrome_switches.h" | 44 #include "chrome/common/chrome_switches.h" |
| 45 #include "chrome/common/extensions/extension.h" | 45 #include "chrome/common/extensions/extension.h" |
| 46 #include "chrome/common/render_messages.h" | 46 #include "chrome/common/render_messages.h" |
| 47 #include "chrome/common/url_constants.h" | 47 #include "chrome/common/url_constants.h" |
| 48 #include "content/public/browser/browser_child_process_host_iterator.h" | 48 #include "content/public/browser/browser_child_process_host_iterator.h" |
| 49 #include "content/public/browser/browser_thread.h" | 49 #include "content/public/browser/browser_thread.h" |
| 50 #include "content/public/browser/child_process_data.h" | 50 #include "content/public/browser/child_process_data.h" |
| 51 #include "content/public/browser/notification_service.h" | 51 #include "content/public/browser/notification_service.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 } | 220 } |
| 221 | 221 |
| 222 //////////////////////////////////////////////////////////////////////////////// | 222 //////////////////////////////////////////////////////////////////////////////// |
| 223 // TaskManagerTabContentsResource class | 223 // TaskManagerTabContentsResource class |
| 224 //////////////////////////////////////////////////////////////////////////////// | 224 //////////////////////////////////////////////////////////////////////////////// |
| 225 | 225 |
| 226 // static | 226 // static |
| 227 gfx::ImageSkia* TaskManagerTabContentsResource::prerender_icon_ = NULL; | 227 gfx::ImageSkia* TaskManagerTabContentsResource::prerender_icon_ = NULL; |
| 228 | 228 |
| 229 TaskManagerTabContentsResource::TaskManagerTabContentsResource( | 229 TaskManagerTabContentsResource::TaskManagerTabContentsResource( |
| 230 TabContentsWrapper* tab_contents) | 230 TabContents* tab_contents) |
| 231 : TaskManagerRendererResource( | 231 : TaskManagerRendererResource( |
| 232 tab_contents->web_contents()->GetRenderProcessHost()->GetHandle(), | 232 tab_contents->web_contents()->GetRenderProcessHost()->GetHandle(), |
| 233 tab_contents->web_contents()->GetRenderViewHost()), | 233 tab_contents->web_contents()->GetRenderViewHost()), |
| 234 tab_contents_(tab_contents), | 234 tab_contents_(tab_contents), |
| 235 is_instant_preview_(false) { | 235 is_instant_preview_(false) { |
| 236 if (!prerender_icon_) { | 236 if (!prerender_icon_) { |
| 237 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 237 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 238 prerender_icon_ = rb.GetImageSkiaNamed(IDR_PRERENDER); | 238 prerender_icon_ = rb.GetImageSkiaNamed(IDR_PRERENDER); |
| 239 } | 239 } |
| 240 for (BrowserList::const_iterator i = BrowserList::begin(); | 240 for (BrowserList::const_iterator i = BrowserList::begin(); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 else | 323 else |
| 324 return cache.GetNameOfProfileAtIndex(index); | 324 return cache.GetNameOfProfileAtIndex(index); |
| 325 } | 325 } |
| 326 | 326 |
| 327 gfx::ImageSkia TaskManagerTabContentsResource::GetIcon() const { | 327 gfx::ImageSkia TaskManagerTabContentsResource::GetIcon() const { |
| 328 if (IsPrerendering()) | 328 if (IsPrerendering()) |
| 329 return *prerender_icon_; | 329 return *prerender_icon_; |
| 330 return tab_contents_->favicon_tab_helper()->GetFavicon(); | 330 return tab_contents_->favicon_tab_helper()->GetFavicon(); |
| 331 } | 331 } |
| 332 | 332 |
| 333 TabContentsWrapper* TaskManagerTabContentsResource::GetTabContents() const { | 333 TabContents* TaskManagerTabContentsResource::GetTabContents() const { |
| 334 return tab_contents_; | 334 return tab_contents_; |
| 335 } | 335 } |
| 336 | 336 |
| 337 const Extension* TaskManagerTabContentsResource::GetExtension() const { | 337 const Extension* TaskManagerTabContentsResource::GetExtension() const { |
| 338 if (HostsExtension()) { | 338 if (HostsExtension()) { |
| 339 ExtensionService* extension_service = | 339 ExtensionService* extension_service = |
| 340 tab_contents_->profile()->GetExtensionService(); | 340 tab_contents_->profile()->GetExtensionService(); |
| 341 return extension_service->extensions()->GetByID( | 341 return extension_service->extensions()->GetByID( |
| 342 tab_contents_->web_contents()->GetURL().host()); | 342 tab_contents_->web_contents()->GetURL().host()); |
| 343 } | 343 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 366 WebContents* web_contents = | 366 WebContents* web_contents = |
| 367 tab_util::GetWebContentsByID(render_process_host_id, routing_id); | 367 tab_util::GetWebContentsByID(render_process_host_id, routing_id); |
| 368 if (!web_contents) // Not one of our resource. | 368 if (!web_contents) // Not one of our resource. |
| 369 return NULL; | 369 return NULL; |
| 370 | 370 |
| 371 // If an origin PID was specified then the request originated in a plugin | 371 // If an origin PID was specified then the request originated in a plugin |
| 372 // working on the WebContents's behalf, so ignore it. | 372 // working on the WebContents's behalf, so ignore it. |
| 373 if (origin_pid) | 373 if (origin_pid) |
| 374 return NULL; | 374 return NULL; |
| 375 | 375 |
| 376 TabContentsWrapper* wrapper = | 376 TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
| 377 TabContentsWrapper::GetCurrentWrapperForContents(web_contents); | 377 std::map<TabContents*, TaskManagerTabContentsResource*>::iterator |
| 378 std::map<TabContentsWrapper*, TaskManagerTabContentsResource*>::iterator | 378 res_iter = resources_.find(tab_contents); |
| 379 res_iter = resources_.find(wrapper); | |
| 380 if (res_iter == resources_.end()) { | 379 if (res_iter == resources_.end()) { |
| 381 // Can happen if the tab was closed while a network request was being | 380 // Can happen if the tab was closed while a network request was being |
| 382 // performed. | 381 // performed. |
| 383 return NULL; | 382 return NULL; |
| 384 } | 383 } |
| 385 return res_iter->second; | 384 return res_iter->second; |
| 386 } | 385 } |
| 387 | 386 |
| 388 void TaskManagerTabContentsResourceProvider::StartUpdating() { | 387 void TaskManagerTabContentsResourceProvider::StartUpdating() { |
| 389 DCHECK(!updating_); | 388 DCHECK(!updating_); |
| 390 updating_ = true; | 389 updating_ = true; |
| 391 | 390 |
| 392 // Add all the existing TabContentsWrappers. | 391 // Add all the existing TabContentses. |
| 393 for (TabContentsIterator iterator; !iterator.done(); ++iterator) | 392 for (TabContentsIterator iterator; !iterator.done(); ++iterator) |
| 394 Add(*iterator); | 393 Add(*iterator); |
| 395 | 394 |
| 396 // Then we register for notifications to get new tabs. | 395 // Then we register for notifications to get new tabs. |
| 397 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | 396 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
| 398 content::NotificationService::AllBrowserContextsAndSources()); | 397 content::NotificationService::AllBrowserContextsAndSources()); |
| 399 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, | 398 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
| 400 content::NotificationService::AllBrowserContextsAndSources()); | 399 content::NotificationService::AllBrowserContextsAndSources()); |
| 401 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 400 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 402 content::NotificationService::AllBrowserContextsAndSources()); | 401 content::NotificationService::AllBrowserContextsAndSources()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 422 this, chrome::NOTIFICATION_INSTANT_COMMITTED, | 421 this, chrome::NOTIFICATION_INSTANT_COMMITTED, |
| 423 content::NotificationService::AllBrowserContextsAndSources()); | 422 content::NotificationService::AllBrowserContextsAndSources()); |
| 424 | 423 |
| 425 // Delete all the resources. | 424 // Delete all the resources. |
| 426 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); | 425 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); |
| 427 | 426 |
| 428 resources_.clear(); | 427 resources_.clear(); |
| 429 } | 428 } |
| 430 | 429 |
| 431 void TaskManagerTabContentsResourceProvider::AddToTaskManager( | 430 void TaskManagerTabContentsResourceProvider::AddToTaskManager( |
| 432 TabContentsWrapper* tab_contents) { | 431 TabContents* tab_contents) { |
| 433 TaskManagerTabContentsResource* resource = | 432 TaskManagerTabContentsResource* resource = |
| 434 new TaskManagerTabContentsResource(tab_contents); | 433 new TaskManagerTabContentsResource(tab_contents); |
| 435 resources_[tab_contents] = resource; | 434 resources_[tab_contents] = resource; |
| 436 task_manager_->AddResource(resource); | 435 task_manager_->AddResource(resource); |
| 437 } | 436 } |
| 438 | 437 |
| 439 void TaskManagerTabContentsResourceProvider::Add( | 438 void TaskManagerTabContentsResourceProvider::Add(TabContents* tab_contents) { |
| 440 TabContentsWrapper* tab_contents) { | |
| 441 if (!updating_) | 439 if (!updating_) |
| 442 return; | 440 return; |
| 443 | 441 |
| 444 // Don't add dead tabs or tabs that haven't yet connected. | 442 // Don't add dead tabs or tabs that haven't yet connected. |
| 445 if (!tab_contents->web_contents()->GetRenderProcessHost()->GetHandle() || | 443 if (!tab_contents->web_contents()->GetRenderProcessHost()->GetHandle() || |
| 446 !tab_contents->web_contents()->WillNotifyDisconnection()) { | 444 !tab_contents->web_contents()->WillNotifyDisconnection()) { |
| 447 return; | 445 return; |
| 448 } | 446 } |
| 449 | 447 |
| 450 std::map<TabContentsWrapper*, TaskManagerTabContentsResource*>::const_iterator | 448 std::map<TabContents*, TaskManagerTabContentsResource*>::const_iterator |
| 451 iter = resources_.find(tab_contents); | 449 iter = resources_.find(tab_contents); |
| 452 if (iter != resources_.end()) { | 450 if (iter != resources_.end()) { |
| 453 // The case may happen that we have added a WebContents as part of the | 451 // The case may happen that we have added a WebContents as part of the |
| 454 // iteration performed during StartUpdating() call but the notification that | 452 // iteration performed during StartUpdating() call but the notification that |
| 455 // it has connected was not fired yet. So when the notification happens, we | 453 // it has connected was not fired yet. So when the notification happens, we |
| 456 // already know about this tab and just ignore it. | 454 // already know about this tab and just ignore it. |
| 457 return; | 455 return; |
| 458 } | 456 } |
| 459 AddToTaskManager(tab_contents); | 457 AddToTaskManager(tab_contents); |
| 460 } | 458 } |
| 461 | 459 |
| 462 void TaskManagerTabContentsResourceProvider::Remove( | 460 void TaskManagerTabContentsResourceProvider::Remove(TabContents* tab_contents) { |
| 463 TabContentsWrapper* tab_contents) { | |
| 464 if (!updating_) | 461 if (!updating_) |
| 465 return; | 462 return; |
| 466 std::map<TabContentsWrapper*, TaskManagerTabContentsResource*>::iterator | 463 std::map<TabContents*, TaskManagerTabContentsResource*>::iterator |
| 467 iter = resources_.find(tab_contents); | 464 iter = resources_.find(tab_contents); |
| 468 if (iter == resources_.end()) { | 465 if (iter == resources_.end()) { |
| 469 // Since WebContents are destroyed asynchronously (see TabContentsCollector | 466 // Since WebContents are destroyed asynchronously (see TabContentsCollector |
| 470 // in navigation_controller.cc), we can be notified of a tab being removed | 467 // in navigation_controller.cc), we can be notified of a tab being removed |
| 471 // that we don't know. This can happen if the user closes a tab and quickly | 468 // that we don't know. This can happen if the user closes a tab and quickly |
| 472 // opens the task manager, before the tab is actually destroyed. | 469 // opens the task manager, before the tab is actually destroyed. |
| 473 return; | 470 return; |
| 474 } | 471 } |
| 475 | 472 |
| 476 // Remove the resource from the Task Manager. | 473 // Remove the resource from the Task Manager. |
| 477 TaskManagerTabContentsResource* resource = iter->second; | 474 TaskManagerTabContentsResource* resource = iter->second; |
| 478 task_manager_->RemoveResource(resource); | 475 task_manager_->RemoveResource(resource); |
| 479 // And from the provider. | 476 // And from the provider. |
| 480 resources_.erase(iter); | 477 resources_.erase(iter); |
| 481 // Finally, delete the resource. | 478 // Finally, delete the resource. |
| 482 delete resource; | 479 delete resource; |
| 483 } | 480 } |
| 484 | 481 |
| 485 void TaskManagerTabContentsResourceProvider::Update( | 482 void TaskManagerTabContentsResourceProvider::Update(TabContents* tab_contents) { |
| 486 TabContentsWrapper* tab_contents) { | |
| 487 if (!updating_) | 483 if (!updating_) |
| 488 return; | 484 return; |
| 489 std::map<TabContentsWrapper*, TaskManagerTabContentsResource*>::iterator | 485 std::map<TabContents*, TaskManagerTabContentsResource*>::iterator |
| 490 iter = resources_.find(tab_contents); | 486 iter = resources_.find(tab_contents); |
| 491 DCHECK(iter != resources_.end()); | 487 DCHECK(iter != resources_.end()); |
| 492 if (iter != resources_.end()) | 488 if (iter != resources_.end()) |
| 493 iter->second->InstantCommitted(); | 489 iter->second->InstantCommitted(); |
| 494 } | 490 } |
| 495 | 491 |
| 496 void TaskManagerTabContentsResourceProvider::Observe(int type, | 492 void TaskManagerTabContentsResourceProvider::Observe(int type, |
| 497 const content::NotificationSource& source, | 493 const content::NotificationSource& source, |
| 498 const content::NotificationDetails& details) { | 494 const content::NotificationDetails& details) { |
| 499 TabContentsWrapper* tab_contents; | 495 TabContents* tab_contents; |
| 500 if (type == chrome::NOTIFICATION_INSTANT_COMMITTED) { | 496 if (type == chrome::NOTIFICATION_INSTANT_COMMITTED) { |
| 501 tab_contents = content::Source<TabContentsWrapper>(source).ptr(); | 497 tab_contents = content::Source<TabContents>(source).ptr(); |
| 502 } else { | 498 } else { |
| 503 tab_contents = TabContentsWrapper::GetCurrentWrapperForContents( | 499 tab_contents = TabContents::FromWebContents( |
| 504 content::Source<WebContents>(source).ptr()); | 500 content::Source<WebContents>(source).ptr()); |
| 505 } | 501 } |
| 506 // A background page does not have a TabContentsWrapper. | 502 // A background page does not have a TabContents. |
| 507 if (!tab_contents) | 503 if (!tab_contents) |
| 508 return; | 504 return; |
| 509 switch (type) { | 505 switch (type) { |
| 510 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: | 506 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: |
| 511 Add(tab_contents); | 507 Add(tab_contents); |
| 512 break; | 508 break; |
| 513 case content::NOTIFICATION_WEB_CONTENTS_SWAPPED: | 509 case content::NOTIFICATION_WEB_CONTENTS_SWAPPED: |
| 514 Remove(tab_contents); | 510 Remove(tab_contents); |
| 515 Add(tab_contents); | 511 Add(tab_contents); |
| 516 break; | 512 break; |
| (...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1494 | 1490 |
| 1495 return &resource_; | 1491 return &resource_; |
| 1496 } | 1492 } |
| 1497 | 1493 |
| 1498 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { | 1494 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { |
| 1499 task_manager_->AddResource(&resource_); | 1495 task_manager_->AddResource(&resource_); |
| 1500 } | 1496 } |
| 1501 | 1497 |
| 1502 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { | 1498 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { |
| 1503 } | 1499 } |
| OLD | NEW |