summaryrefslogtreecommitdiffstats
path: root/chrome/browser/task_manager
diff options
context:
space:
mode:
authoratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-10 19:31:12 +0000
committeratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-10 19:31:12 +0000
commitda58f5b14586b6db155a22b8b1c8d4de8cf6d8f5 (patch)
treebbdc8f01e3a24d791abc41ce5404e3202e803def /chrome/browser/task_manager
parent4f35e4b08dbd1ed5221402a5aba29a69ef27fa58 (diff)
downloadchromium_src-da58f5b14586b6db155a22b8b1c8d4de8cf6d8f5.zip
chromium_src-da58f5b14586b6db155a22b8b1c8d4de8cf6d8f5.tar.gz
chromium_src-da58f5b14586b6db155a22b8b1c8d4de8cf6d8f5.tar.bz2
Added support for displaying BackgroundContents in the task manager.
Previously BackgroundContents would get created, but since they were not TabContents, they would not show up. BUG=62105 TEST=TaskManagerBrowserTest.NoticeBGContentsChanges Review URL: http://codereview.chromium.org/4760001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65690 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/task_manager')
-rw-r--r--chrome/browser/task_manager/task_manager.cc4
-rw-r--r--chrome/browser/task_manager/task_manager_browsertest.cc30
-rw-r--r--chrome/browser/task_manager/task_manager_resource_providers.cc353
-rw-r--r--chrome/browser/task_manager/task_manager_resource_providers.h110
4 files changed, 438 insertions, 59 deletions
diff --git a/chrome/browser/task_manager/task_manager.cc b/chrome/browser/task_manager/task_manager.cc
index 2711925..2080b34 100644
--- a/chrome/browser/task_manager/task_manager.cc
+++ b/chrome/browser/task_manager/task_manager.cc
@@ -82,6 +82,10 @@ TaskManagerModel::TaskManagerModel(TaskManager* task_manager)
new TaskManagerTabContentsResourceProvider(task_manager);
wc_provider->AddRef();
providers_.push_back(wc_provider);
+ TaskManagerBackgroundContentsResourceProvider* bc_provider =
+ new TaskManagerBackgroundContentsResourceProvider(task_manager);
+ bc_provider->AddRef();
+ providers_.push_back(bc_provider);
TaskManagerChildProcessResourceProvider* child_process_provider =
new TaskManagerChildProcessResourceProvider(task_manager);
child_process_provider->AddRef();
diff --git a/chrome/browser/task_manager/task_manager_browsertest.cc b/chrome/browser/task_manager/task_manager_browsertest.cc
index 9e3c181..7230254 100644
--- a/chrome/browser/task_manager/task_manager_browsertest.cc
+++ b/chrome/browser/task_manager/task_manager_browsertest.cc
@@ -7,6 +7,7 @@
#include "app/l10n_util.h"
#include "base/file_path.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/background_contents_service.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_navigator.h"
#include "chrome/browser/browser_process.h"
@@ -16,6 +17,7 @@
#include "chrome/browser/notifications/desktop_notification_service.h"
#include "chrome/browser/notifications/notification_test_util.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
+#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/infobar_delegate.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tabs/tab_strip_model.h"
@@ -118,6 +120,34 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) {
WaitForResourceChange(2);
}
+IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) {
+ EXPECT_EQ(0, model()->ResourceCount());
+
+ // Show the task manager. This populates the model, and helps with debugging
+ // (you see the task manager).
+ browser()->window()->ShowTaskManager();
+
+ // Browser and the New Tab Page.
+ EXPECT_EQ(2, model()->ResourceCount());
+
+ // Open a new background contents and make sure we notice that.
+ GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
+ FilePath(kTitle1File)));
+
+ BackgroundContentsService* service =
+ browser()->profile()->GetBackgroundContentsService();
+ string16 application_id(ASCIIToUTF16("test_app_id"));
+ service->LoadBackgroundContents(browser()->profile(),
+ url,
+ ASCIIToUTF16("background_page"),
+ application_id);
+ WaitForResourceChange(3);
+
+ // Close the background contents and verify that we notice.
+ service->ShutdownAssociatedBackgroundContents(application_id);
+ WaitForResourceChange(2);
+}
+
#if defined(OS_WIN)
// http://crbug.com/31663
#define MAYBE_NoticeExtensionChanges DISABLED_NoticeExtensionChanges
diff --git a/chrome/browser/task_manager/task_manager_resource_providers.cc b/chrome/browser/task_manager/task_manager_resource_providers.cc
index 0c3d5d8..13cd82f 100644
--- a/chrome/browser/task_manager/task_manager_resource_providers.cc
+++ b/chrome/browser/task_manager/task_manager_resource_providers.cc
@@ -15,13 +15,16 @@
#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "base/thread.h"
+#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/background_contents_service.h"
#include "chrome/browser/browser_child_process_host.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/extensions/extension_process_manager.h"
+#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/notifications/balloon_collection.h"
#include "chrome/browser/notifications/balloon_host.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
@@ -29,8 +32,9 @@
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/resource_message_filter.h"
-#include "chrome/browser/tab_contents/tab_util.h"
+#include "chrome/browser/tab_contents/background_contents.h"
#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/render_messages.h"
@@ -46,20 +50,20 @@
#include "gfx/icon_util.h"
#endif // defined(OS_WIN)
+
////////////////////////////////////////////////////////////////////////////////
-// TaskManagerTabContentsResource class
+// TaskManagerRendererResource class
////////////////////////////////////////////////////////////////////////////////
-
-TaskManagerTabContentsResource::TaskManagerTabContentsResource(
- TabContents* tab_contents)
- : tab_contents_(tab_contents),
+TaskManagerRendererResource::TaskManagerRendererResource(
+ base::ProcessHandle process, RenderViewHost* render_view_host)
+ : process_(process),
+ render_view_host_(render_view_host),
pending_stats_update_(false),
v8_memory_allocated_(0),
v8_memory_used_(0),
pending_v8_memory_allocated_update_(false) {
- // We cache the process as when the TabContents is closed the process
- // becomes NULL and the TaskManager still needs it.
- process_ = tab_contents_->GetRenderProcessHost()->GetHandle();
+ // We cache the process and pid as when a Tab/BackgroundContents is closed the
+ // process reference becomes NULL and the TaskManager still needs it.
pid_ = base::GetProcId(process_);
stats_.images.size = 0;
stats_.cssStyleSheets.size = 0;
@@ -68,76 +72,92 @@ TaskManagerTabContentsResource::TaskManagerTabContentsResource(
stats_.fonts.size = 0;
}
-TaskManagerTabContentsResource::~TaskManagerTabContentsResource() {
-}
-
-std::wstring TaskManagerTabContentsResource::GetTitle() const {
- // Fall back on the URL if there's no title.
- std::wstring tab_title(UTF16ToWideHack(tab_contents_->GetTitle()));
- if (tab_title.empty()) {
- tab_title = UTF8ToWide(tab_contents_->GetURL().spec());
- // Force URL to be LTR.
- tab_title = UTF16ToWide(base::i18n::GetDisplayStringInLTRDirectionality(
- WideToUTF16(tab_title)));
- } else {
- // Since the tab_title will be concatenated with
- // IDS_TASK_MANAGER_TAB_PREFIX, we need to explicitly set the tab_title to
- // be LTR format if there is no strong RTL charater in it. Otherwise, if
- // IDS_TASK_MANAGER_TAB_PREFIX is an RTL word, the concatenated result
- // might be wrong. For example, http://mail.yahoo.com, whose title is
- // "Yahoo! Mail: The best web-based Email!", without setting it explicitly
- // as LTR format, the concatenated result will be "!Yahoo! Mail: The best
- // web-based Email :BAT", in which the capital letters "BAT" stands for
- // the Hebrew word for "tab".
- base::i18n::AdjustStringForLocaleDirection(tab_title, &tab_title);
- }
-
- return l10n_util::GetStringF(IDS_TASK_MANAGER_TAB_PREFIX, tab_title);
+TaskManagerRendererResource::~TaskManagerRendererResource() {
}
-void TaskManagerTabContentsResource::Refresh() {
+void TaskManagerRendererResource::Refresh() {
if (!pending_stats_update_) {
- tab_contents_->render_view_host()->Send(new ViewMsg_GetCacheResourceStats);
+ render_view_host_->Send(new ViewMsg_GetCacheResourceStats);
pending_stats_update_ = true;
}
if (!pending_v8_memory_allocated_update_) {
- tab_contents_->render_view_host()->Send(new ViewMsg_GetV8HeapStats);
+ render_view_host_->Send(new ViewMsg_GetV8HeapStats);
pending_v8_memory_allocated_update_ = true;
}
}
WebKit::WebCache::ResourceTypeStats
- TaskManagerTabContentsResource::GetWebCoreCacheStats() const {
+TaskManagerRendererResource::GetWebCoreCacheStats() const {
return stats_;
}
-size_t TaskManagerTabContentsResource::GetV8MemoryAllocated() const {
+size_t TaskManagerRendererResource::GetV8MemoryAllocated() const {
return v8_memory_allocated_;
}
-size_t TaskManagerTabContentsResource::GetV8MemoryUsed() const {
+size_t TaskManagerRendererResource::GetV8MemoryUsed() const {
return v8_memory_used_;
}
-void TaskManagerTabContentsResource::NotifyResourceTypeStats(
+void TaskManagerRendererResource::NotifyResourceTypeStats(
const WebKit::WebCache::ResourceTypeStats& stats) {
stats_ = stats;
pending_stats_update_ = false;
}
-void TaskManagerTabContentsResource::NotifyV8HeapStats(
+void TaskManagerRendererResource::NotifyV8HeapStats(
size_t v8_memory_allocated, size_t v8_memory_used) {
v8_memory_allocated_ = v8_memory_allocated;
v8_memory_used_ = v8_memory_used;
pending_v8_memory_allocated_update_ = false;
}
-SkBitmap TaskManagerTabContentsResource::GetIcon() const {
- return tab_contents_->GetFavIcon();
+base::ProcessHandle TaskManagerRendererResource::GetProcess() const {
+ return process_;
}
-base::ProcessHandle TaskManagerTabContentsResource::GetProcess() const {
- return process_;
+////////////////////////////////////////////////////////////////////////////////
+// TaskManagerTabContentsResource class
+////////////////////////////////////////////////////////////////////////////////
+
+TaskManagerTabContentsResource::TaskManagerTabContentsResource(
+ TabContents* tab_contents)
+ : TaskManagerRendererResource(
+ tab_contents->GetRenderProcessHost()->GetHandle(),
+ tab_contents->render_view_host()),
+ tab_contents_(tab_contents) {
+}
+
+TaskManagerTabContentsResource::~TaskManagerTabContentsResource() {
+}
+
+std::wstring TaskManagerTabContentsResource::GetTitle() const {
+ // Fall back on the URL if there's no title.
+ std::wstring tab_title(UTF16ToWideHack(tab_contents_->GetTitle()));
+ if (tab_title.empty()) {
+ tab_title = UTF8ToWide(tab_contents_->GetURL().spec());
+ // Force URL to be LTR.
+ tab_title = UTF16ToWide(base::i18n::GetDisplayStringInLTRDirectionality(
+ WideToUTF16(tab_title)));
+ } else {
+ // Since the tab_title will be concatenated with
+ // IDS_TASK_MANAGER_TAB_PREFIX, we need to explicitly set the tab_title to
+ // be LTR format if there is no strong RTL charater in it. Otherwise, if
+ // IDS_TASK_MANAGER_TAB_PREFIX is an RTL word, the concatenated result
+ // might be wrong. For example, http://mail.yahoo.com, whose title is
+ // "Yahoo! Mail: The best web-based Email!", without setting it explicitly
+ // as LTR format, the concatenated result will be "!Yahoo! Mail: The best
+ // web-based Email :BAT", in which the capital letters "BAT" stands for
+ // the Hebrew word for "tab".
+ base::i18n::AdjustStringForLocaleDirection(tab_title, &tab_title);
+ }
+
+ return l10n_util::GetStringF(IDS_TASK_MANAGER_TAB_PREFIX, tab_title);
+}
+
+
+SkBitmap TaskManagerTabContentsResource::GetIcon() const {
+ return tab_contents_->GetFavIcon();
}
TabContents* TaskManagerTabContentsResource::GetTabContents() const {
@@ -183,11 +203,11 @@ TaskManager::Resource* TaskManagerTabContentsResourceProvider::GetResource(
std::map<TabContents*, TaskManagerTabContentsResource*>::iterator
res_iter = resources_.find(tab_contents);
- if (res_iter == resources_.end())
+ if (res_iter == resources_.end()) {
// Can happen if the tab was closed while a network request was being
// performed.
return NULL;
-
+ }
return res_iter->second;
}
@@ -316,6 +336,243 @@ void TaskManagerTabContentsResourceProvider::Observe(NotificationType type,
}
////////////////////////////////////////////////////////////////////////////////
+// TaskManagerBackgroundContentsResource class
+////////////////////////////////////////////////////////////////////////////////
+
+SkBitmap* TaskManagerBackgroundContentsResource::default_icon_ = NULL;
+
+TaskManagerBackgroundContentsResource::TaskManagerBackgroundContentsResource(
+ BackgroundContents* background_contents,
+ const std::wstring& application_name)
+ : TaskManagerRendererResource(
+ background_contents->render_view_host()->process()->GetHandle(),
+ background_contents->render_view_host()),
+ background_contents_(background_contents),
+ application_name_(application_name) {
+ // Just use the same icon that other extension resources do.
+ // TODO(atwilson): Use the favicon when that's available.
+ if (!default_icon_) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN);
+ }
+ // Ensure that the string has the appropriate direction markers (see comment
+ // in TaskManagerTabContentsResource::GetTitle()).
+ base::i18n::AdjustStringForLocaleDirection(application_name_,
+ &application_name_);
+}
+
+TaskManagerBackgroundContentsResource::~TaskManagerBackgroundContentsResource(
+ ) {
+}
+
+std::wstring TaskManagerBackgroundContentsResource::GetTitle() const {
+ std::wstring title = application_name_;
+
+ if (title.empty()) {
+ // No title (can't locate the parent app for some reason) so just display
+ // the URL (properly forced to be LTR).
+ title = UTF16ToWide(base::i18n::GetDisplayStringInLTRDirectionality(
+ UTF8ToUTF16(background_contents_->GetURL().spec())));
+ }
+ return l10n_util::GetStringF(IDS_TASK_MANAGER_BACKGROUND_PREFIX, title);
+}
+
+
+SkBitmap TaskManagerBackgroundContentsResource::GetIcon() const {
+ return *default_icon_;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// TaskManagerBackgroundContentsResourceProvider class
+////////////////////////////////////////////////////////////////////////////////
+
+TaskManagerBackgroundContentsResourceProvider::
+ TaskManagerBackgroundContentsResourceProvider(TaskManager* task_manager)
+ : updating_(false),
+ task_manager_(task_manager) {
+}
+
+TaskManagerBackgroundContentsResourceProvider::
+ ~TaskManagerBackgroundContentsResourceProvider() {
+}
+
+TaskManager::Resource*
+TaskManagerBackgroundContentsResourceProvider::GetResource(
+ int origin_pid,
+ int render_process_host_id,
+ int routing_id) {
+
+ BackgroundContents* contents = BackgroundContents::GetBackgroundContentsByID(
+ render_process_host_id, routing_id);
+ if (!contents) // This resource no longer exists.
+ return NULL;
+
+ base::ProcessHandle process_handle =
+ contents->render_view_host()->process()->GetHandle();
+ if (!process_handle) // Process crashed.
+ return NULL;
+
+ int pid = base::GetProcId(process_handle);
+ if (pid != origin_pid)
+ return NULL;
+
+ std::map<BackgroundContents*,
+ TaskManagerBackgroundContentsResource*>::iterator res_iter =
+ resources_.find(contents);
+ if (res_iter == resources_.end())
+ // Can happen if the page went away while a network request was being
+ // performed.
+ return NULL;
+
+ return res_iter->second;
+}
+
+void TaskManagerBackgroundContentsResourceProvider::StartUpdating() {
+ DCHECK(!updating_);
+ updating_ = true;
+
+ // Add all the existing BackgroundContents from every profile.
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ for (ProfileManager::const_iterator it = profile_manager->begin();
+ it != profile_manager->end(); ++it) {
+ BackgroundContentsService* background_contents_service =
+ (*it)->GetBackgroundContentsService();
+ ExtensionsService* extensions_service = (*it)->GetExtensionsService();
+ std::vector<BackgroundContents*> contents =
+ background_contents_service->GetBackgroundContents();
+ for (std::vector<BackgroundContents*>::iterator iterator = contents.begin();
+ iterator != contents.end(); ++iterator) {
+ std::wstring application_name;
+ // Lookup the name from the parent extension.
+ if (extensions_service) {
+ const string16& application_id =
+ background_contents_service->GetParentApplicationId(*iterator);
+ const Extension* extension = extensions_service->GetExtensionById(
+ UTF16ToUTF8(application_id), false);
+ if (extension)
+ application_name = UTF8ToWide(extension->name());
+ }
+ Add(*iterator, application_name);
+ }
+ }
+
+ // Then we register for notifications to get new BackgroundContents.
+ registrar_.Add(this, NotificationType::BACKGROUND_CONTENTS_OPENED,
+ NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::BACKGROUND_CONTENTS_NAVIGATED,
+ NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::BACKGROUND_CONTENTS_DELETED,
+ NotificationService::AllSources());
+}
+
+void TaskManagerBackgroundContentsResourceProvider::StopUpdating() {
+ DCHECK(updating_);
+ updating_ = false;
+
+ // Unregister for notifications
+ registrar_.Remove(this, NotificationType::BACKGROUND_CONTENTS_OPENED,
+ NotificationService::AllSources());
+ registrar_.Remove(this, NotificationType::BACKGROUND_CONTENTS_NAVIGATED,
+ NotificationService::AllSources());
+ registrar_.Remove(this, NotificationType::BACKGROUND_CONTENTS_DELETED,
+ NotificationService::AllSources());
+
+ // Delete all the resources.
+ STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end());
+
+ resources_.clear();
+}
+
+void TaskManagerBackgroundContentsResourceProvider::AddToTaskManager(
+ BackgroundContents* background_contents,
+ const std::wstring& application_name) {
+ TaskManagerBackgroundContentsResource* resource =
+ new TaskManagerBackgroundContentsResource(background_contents,
+ application_name);
+ resources_[background_contents] = resource;
+ task_manager_->AddResource(resource);
+}
+
+void TaskManagerBackgroundContentsResourceProvider::Add(
+ BackgroundContents* contents, const std::wstring& application_name) {
+ if (!updating_)
+ return;
+
+ // Don't add contents whose process is dead.
+ if (!contents->render_view_host()->process()->GetHandle())
+ return;
+
+ // Should never add the same BackgroundContents twice.
+ DCHECK(resources_.find(contents) == resources_.end());
+ AddToTaskManager(contents, application_name);
+}
+
+void TaskManagerBackgroundContentsResourceProvider::Remove(
+ BackgroundContents* contents) {
+ if (!updating_)
+ return;
+ std::map<BackgroundContents*,
+ TaskManagerBackgroundContentsResource*>::iterator iter =
+ resources_.find(contents);
+ DCHECK(iter != resources_.end());
+
+ // Remove the resource from the Task Manager.
+ TaskManagerBackgroundContentsResource* resource = iter->second;
+ task_manager_->RemoveResource(resource);
+ // And from the provider.
+ resources_.erase(iter);
+ // Finally, delete the resource.
+ delete resource;
+}
+
+void TaskManagerBackgroundContentsResourceProvider::Observe(
+ NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ switch (type.value) {
+ case NotificationType::BACKGROUND_CONTENTS_OPENED: {
+ // Get the name from the parent application. If no parent application is
+ // found, just pass an empty string - BackgroundContentsResource::GetTitle
+ // will display the URL instead in this case. This should never happen
+ // except in rare cases when an extension is being unloaded or chrome is
+ // exiting while the task manager is displayed.
+ std::wstring application_name;
+ ExtensionsService* service =
+ Source<Profile>(source)->GetExtensionsService();
+ if (service) {
+ std::string application_id = UTF16ToUTF8(
+ Details<BackgroundContentsOpenedDetails>(details)->application_id);
+ const Extension* extension =
+ service->GetExtensionById(application_id, false);
+ // Extension can be NULL when running unit tests.
+ if (extension)
+ application_name = UTF8ToWide(extension->name());
+ }
+ Add(Details<BackgroundContentsOpenedDetails>(details)->contents,
+ application_name);
+ break;
+ }
+ case NotificationType::BACKGROUND_CONTENTS_NAVIGATED: {
+ BackgroundContents* contents = Details<BackgroundContents>(details).ptr();
+ // Should never get a NAVIGATED before OPENED.
+ DCHECK(resources_.find(contents) != resources_.end());
+ // Preserve the application name.
+ std::wstring application_name(
+ resources_.find(contents)->second->application_name());
+ Remove(contents);
+ Add(contents, application_name);
+ break;
+ }
+ case NotificationType::BACKGROUND_CONTENTS_DELETED:
+ Remove(Details<BackgroundContents>(details).ptr());
+ break;
+ default:
+ NOTREACHED() << "Unexpected notification.";
+ return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
// TaskManagerChildProcessResource class
////////////////////////////////////////////////////////////////////////////////
SkBitmap* TaskManagerChildProcessResource::default_icon_ = NULL;
diff --git a/chrome/browser/task_manager/task_manager_resource_providers.h b/chrome/browser/task_manager/task_manager_resource_providers.h
index 5145a7e..62fbb53 100644
--- a/chrome/browser/task_manager/task_manager_resource_providers.h
+++ b/chrome/browser/task_manager/task_manager_resource_providers.h
@@ -17,33 +17,33 @@
#include "chrome/common/notification_registrar.h"
#include "third_party/WebKit/WebKit/chromium/public/WebCache.h"
+class BackgroundContents;
class BalloonHost;
class Extension;
class ExtensionHost;
+class RenderViewHost;
class TabContents;
// These file contains the resource providers used in the task manager.
-class TaskManagerTabContentsResource : public TaskManager::Resource {
+// Base class for various types of render process resources that provides common
+// functionality like stats tracking.
+class TaskManagerRendererResource : public TaskManager::Resource {
public:
- explicit TaskManagerTabContentsResource(TabContents* tab_contents);
- ~TaskManagerTabContentsResource();
+ TaskManagerRendererResource(base::ProcessHandle process,
+ RenderViewHost* render_view_host);
+ virtual ~TaskManagerRendererResource();
- // TaskManagerResource methods:
- std::wstring GetTitle() const;
- SkBitmap GetIcon() const;
+ // TaskManager::Resource methods:
base::ProcessHandle GetProcess() const;
Type GetType() const { return RENDERER; }
- TabContents* GetTabContents() const;
-
virtual bool ReportsCacheStats() const { return true; }
virtual WebKit::WebCache::ResourceTypeStats GetWebCoreCacheStats() const;
-
virtual bool ReportsV8MemoryStats() const { return true; }
virtual size_t GetV8MemoryAllocated() const;
virtual size_t GetV8MemoryUsed() const;
- // TabContents always provide the network usage.
+ // RenderResources always provide the network usage.
bool SupportNetworkUsage() const { return true; }
void SetSupportNetworkUsage() { }
@@ -56,9 +56,11 @@ class TaskManagerTabContentsResource : public TaskManager::Resource {
size_t v8_memory_used);
private:
- TabContents* tab_contents_;
base::ProcessHandle process_;
int pid_;
+
+ // RenderViewHost we use to fetch stats.
+ RenderViewHost* render_view_host_;
// The stats_ field holds information about resource usage in the renderer
// process and so it is updated asynchronously by the Refresh() call.
WebKit::WebCache::ResourceTypeStats stats_;
@@ -70,6 +72,22 @@ class TaskManagerTabContentsResource : public TaskManager::Resource {
size_t v8_memory_used_;
bool pending_v8_memory_allocated_update_;
+ DISALLOW_COPY_AND_ASSIGN(TaskManagerRendererResource);
+};
+
+class TaskManagerTabContentsResource : public TaskManagerRendererResource {
+ public:
+ explicit TaskManagerTabContentsResource(TabContents* tab_contents);
+ ~TaskManagerTabContentsResource();
+
+ // TaskManager::Resource methods:
+ std::wstring GetTitle() const;
+ SkBitmap GetIcon() const;
+ TabContents* GetTabContents() const;
+
+ private:
+ TabContents* tab_contents_;
+
DISALLOW_COPY_AND_ASSIGN(TaskManagerTabContentsResource);
};
@@ -114,6 +132,76 @@ class TaskManagerTabContentsResourceProvider
DISALLOW_COPY_AND_ASSIGN(TaskManagerTabContentsResourceProvider);
};
+class TaskManagerBackgroundContentsResource
+ : public TaskManagerRendererResource {
+ public:
+ TaskManagerBackgroundContentsResource(
+ BackgroundContents* background_contents,
+ const std::wstring& application_name);
+ ~TaskManagerBackgroundContentsResource();
+
+ // TaskManager::Resource methods:
+ std::wstring GetTitle() const;
+ const std::wstring& application_name() const { return application_name_; }
+ SkBitmap GetIcon() const;
+
+ private:
+ BackgroundContents* background_contents_;
+
+ std::wstring application_name_;
+
+ // The icon painted for BackgroundContents.
+ // TODO(atwilson): Use the favicon when there's a way to get the favicon for
+ // BackgroundContents.
+ static SkBitmap* default_icon_;
+
+ DISALLOW_COPY_AND_ASSIGN(TaskManagerBackgroundContentsResource);
+};
+
+class TaskManagerBackgroundContentsResourceProvider
+ : public TaskManager::ResourceProvider,
+ public NotificationObserver {
+ public:
+ explicit TaskManagerBackgroundContentsResourceProvider(
+ TaskManager* task_manager);
+
+ virtual TaskManager::Resource* GetResource(int origin_pid,
+ int render_process_host_id,
+ int routing_id);
+ virtual void StartUpdating();
+ virtual void StopUpdating();
+
+ // NotificationObserver method:
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ private:
+ virtual ~TaskManagerBackgroundContentsResourceProvider();
+
+ void Add(BackgroundContents* background_contents, const std::wstring& title);
+ void Remove(BackgroundContents* background_contents);
+
+ void AddToTaskManager(BackgroundContents* background_contents,
+ const std::wstring& title);
+
+ // Whether we are currently reporting to the task manager. Used to ignore
+ // notifications sent after StopUpdating().
+ bool updating_;
+
+ TaskManager* task_manager_;
+
+ // Maps the actual resources (the BackgroundContents) to the Task Manager
+ // resources.
+ std::map<BackgroundContents*, TaskManagerBackgroundContentsResource*>
+ resources_;
+
+ // A scoped container for notification registries.
+ NotificationRegistrar registrar_;
+
+ DISALLOW_COPY_AND_ASSIGN(TaskManagerBackgroundContentsResourceProvider);
+};
+
class TaskManagerChildProcessResource : public TaskManager::Resource {
public:
explicit TaskManagerChildProcessResource(const ChildProcessInfo& child_proc);