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

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

Issue 8469015: Switch BackgroundContents to use TabContents instead of RenderViewHost. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix unittest Created 9 years, 1 month 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 <string> 7 #include <string>
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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 //////////////////////////////////////////////////////////////////////////////// 489 ////////////////////////////////////////////////////////////////////////////////
490 // TaskManagerBackgroundContentsResource class 490 // TaskManagerBackgroundContentsResource class
491 //////////////////////////////////////////////////////////////////////////////// 491 ////////////////////////////////////////////////////////////////////////////////
492 492
493 SkBitmap* TaskManagerBackgroundContentsResource::default_icon_ = NULL; 493 SkBitmap* TaskManagerBackgroundContentsResource::default_icon_ = NULL;
494 494
495 TaskManagerBackgroundContentsResource::TaskManagerBackgroundContentsResource( 495 TaskManagerBackgroundContentsResource::TaskManagerBackgroundContentsResource(
496 BackgroundContents* background_contents, 496 BackgroundContents* background_contents,
497 const string16& application_name) 497 const string16& application_name)
498 : TaskManagerRendererResource( 498 : TaskManagerRendererResource(
499 background_contents->render_view_host()->process()->GetHandle(), 499 background_contents->tab_contents()->GetRenderProcessHost()->
500 background_contents->render_view_host()), 500 GetHandle(),
501 background_contents->tab_contents()->render_view_host()),
501 background_contents_(background_contents), 502 background_contents_(background_contents),
502 application_name_(application_name) { 503 application_name_(application_name) {
503 // Just use the same icon that other extension resources do. 504 // Just use the same icon that other extension resources do.
504 // TODO(atwilson): Use the favicon when that's available. 505 // TODO(atwilson): Use the favicon when that's available.
505 if (!default_icon_) { 506 if (!default_icon_) {
506 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 507 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
507 default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); 508 default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN);
508 } 509 }
509 // Ensure that the string has the appropriate direction markers (see comment 510 // Ensure that the string has the appropriate direction markers (see comment
510 // in TaskManagerTabContentsResource::GetTitle()). 511 // in TaskManagerTabContentsResource::GetTitle()).
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 552
552 TaskManagerBackgroundContentsResourceProvider:: 553 TaskManagerBackgroundContentsResourceProvider::
553 ~TaskManagerBackgroundContentsResourceProvider() { 554 ~TaskManagerBackgroundContentsResourceProvider() {
554 } 555 }
555 556
556 TaskManager::Resource* 557 TaskManager::Resource*
557 TaskManagerBackgroundContentsResourceProvider::GetResource( 558 TaskManagerBackgroundContentsResourceProvider::GetResource(
558 int origin_pid, 559 int origin_pid,
559 int render_process_host_id, 560 int render_process_host_id,
560 int routing_id) { 561 int routing_id) {
561 BackgroundContents* contents = BackgroundContents::GetBackgroundContentsByID(
562 render_process_host_id, routing_id);
563 if (!contents) // This resource no longer exists.
564 return NULL;
565
566 // If an origin PID was specified, the request is from a plugin, not the 562 // If an origin PID was specified, the request is from a plugin, not the
567 // render view host process 563 // render view host process
568 if (origin_pid) 564 if (origin_pid)
569 return NULL; 565 return NULL;
570 566
571 std::map<BackgroundContents*, 567 for (Resources::iterator i = resources_.begin(); i != resources_.end(); i++) {
572 TaskManagerBackgroundContentsResource*>::iterator res_iter = 568 TabContents* tab = i->first->tab_contents();
573 resources_.find(contents); 569 if (tab->render_view_host()->process()->id() == render_process_host_id &&
574 if (res_iter == resources_.end()) 570 tab->render_view_host()->routing_id() == routing_id) {
575 // Can happen if the page went away while a network request was being 571 return i->second;
576 // performed. 572 }
577 return NULL; 573 }
578 574
579 return res_iter->second; 575 // Can happen if the page went away while a network request was being
576 // performed.
577 return NULL;
580 } 578 }
581 579
582 void TaskManagerBackgroundContentsResourceProvider::StartUpdating() { 580 void TaskManagerBackgroundContentsResourceProvider::StartUpdating() {
583 DCHECK(!updating_); 581 DCHECK(!updating_);
584 updating_ = true; 582 updating_ = true;
585 583
586 // Add all the existing BackgroundContents from every profile, including 584 // Add all the existing BackgroundContents from every profile, including
587 // incognito profiles. 585 // incognito profiles.
588 ProfileManager* profile_manager = g_browser_process->profile_manager(); 586 ProfileManager* profile_manager = g_browser_process->profile_manager();
589 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); 587 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 resources_[background_contents] = resource; 652 resources_[background_contents] = resource;
655 task_manager_->AddResource(resource); 653 task_manager_->AddResource(resource);
656 } 654 }
657 655
658 void TaskManagerBackgroundContentsResourceProvider::Add( 656 void TaskManagerBackgroundContentsResourceProvider::Add(
659 BackgroundContents* contents, const string16& application_name) { 657 BackgroundContents* contents, const string16& application_name) {
660 if (!updating_) 658 if (!updating_)
661 return; 659 return;
662 660
663 // Don't add contents whose process is dead. 661 // Don't add contents whose process is dead.
664 if (!contents->render_view_host()->process()->GetHandle()) 662 if (!contents->tab_contents()->GetRenderProcessHost()->GetHandle())
665 return; 663 return;
666 664
667 // Should never add the same BackgroundContents twice. 665 // Should never add the same BackgroundContents twice.
668 DCHECK(resources_.find(contents) == resources_.end()); 666 DCHECK(resources_.find(contents) == resources_.end());
669 AddToTaskManager(contents, application_name); 667 AddToTaskManager(contents, application_name);
670 } 668 }
671 669
672 void TaskManagerBackgroundContentsResourceProvider::Remove( 670 void TaskManagerBackgroundContentsResourceProvider::Remove(
673 BackgroundContents* contents) { 671 BackgroundContents* contents) {
674 if (!updating_) 672 if (!updating_)
675 return; 673 return;
676 std::map<BackgroundContents*, 674 Resources::iterator iter = resources_.find(contents);
677 TaskManagerBackgroundContentsResource*>::iterator iter =
678 resources_.find(contents);
679 DCHECK(iter != resources_.end()); 675 DCHECK(iter != resources_.end());
680 676
681 // Remove the resource from the Task Manager. 677 // Remove the resource from the Task Manager.
682 TaskManagerBackgroundContentsResource* resource = iter->second; 678 TaskManagerBackgroundContentsResource* resource = iter->second;
683 task_manager_->RemoveResource(resource); 679 task_manager_->RemoveResource(resource);
684 // And from the provider. 680 // And from the provider.
685 resources_.erase(iter); 681 resources_.erase(iter);
686 // Finally, delete the resource. 682 // Finally, delete the resource.
687 delete resource; 683 delete resource;
688 } 684 }
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 1389
1394 return &resource_; 1390 return &resource_;
1395 } 1391 }
1396 1392
1397 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { 1393 void TaskManagerBrowserProcessResourceProvider::StartUpdating() {
1398 task_manager_->AddResource(&resource_); 1394 task_manager_->AddResource(&resource_);
1399 } 1395 }
1400 1396
1401 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { 1397 void TaskManagerBrowserProcessResourceProvider::StopUpdating() {
1402 } 1398 }
OLDNEW
« no previous file with comments | « chrome/browser/task_manager/task_manager_resource_providers.h ('k') | chrome/browser/translate/translate_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698