diff options
author | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-16 00:28:52 +0000 |
---|---|---|
committer | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-16 00:28:52 +0000 |
commit | 20ca3fcf1bd5c2058d7aa664bace7cf48d7eab7e (patch) | |
tree | 8671b93063517ee7a1cb2a7b3328d06ed9ad467b /chrome | |
parent | 46b9e22831744393d35f937d4a0d94541056ba4d (diff) | |
download | chromium_src-20ca3fcf1bd5c2058d7aa664bace7cf48d7eab7e.zip chromium_src-20ca3fcf1bd5c2058d7aa664bace7cf48d7eab7e.tar.gz chromium_src-20ca3fcf1bd5c2058d7aa664bace7cf48d7eab7e.tar.bz2 |
Handles renderer-specific TaskManager resources consistently for TabContent and Extension processes
TEST=none
BUG=29307
Review URL: http://codereview.chromium.org/466025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34630 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/task_manager_renderer_resource.cc | 70 | ||||
-rw-r--r-- | chrome/browser/task_manager_renderer_resource.h | 61 | ||||
-rw-r--r-- | chrome/browser/task_manager_resource_providers.cc | 52 | ||||
-rw-r--r-- | chrome/browser/task_manager_resource_providers.h | 43 | ||||
-rwxr-xr-x | chrome/chrome_browser.gypi | 2 |
5 files changed, 144 insertions, 84 deletions
diff --git a/chrome/browser/task_manager_renderer_resource.cc b/chrome/browser/task_manager_renderer_resource.cc new file mode 100644 index 0000000..0f429e0 --- /dev/null +++ b/chrome/browser/task_manager_renderer_resource.cc @@ -0,0 +1,70 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/task_manager_renderer_resource.h" + +#include "base/basictypes.h" +#include "chrome/browser/renderer_host/render_widget_host.h" +#include "chrome/common/render_messages.h" + +//////////////////////////////////////////////////////////////////////////////// +// TaskManagerTabContentsResource class +//////////////////////////////////////////////////////////////////////////////// + +TaskManagerRendererResource::TaskManagerRendererResource( + RenderWidgetHost* render_widget_host) + : render_widget_host_(render_widget_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. + stats_.images.size = 0; + stats_.cssStyleSheets.size = 0; + stats_.scripts.size = 0; + stats_.xslStyleSheets.size = 0; + stats_.fonts.size = 0; +} + +TaskManagerRendererResource::~TaskManagerRendererResource() { +} + +void TaskManagerRendererResource::Refresh() { + if (!pending_stats_update_) { + render_widget_host_->Send(new ViewMsg_GetCacheResourceStats); + pending_stats_update_ = true; + } + if (!pending_v8_memory_allocated_update_) { + render_widget_host_->Send(new ViewMsg_GetV8HeapStats); + pending_v8_memory_allocated_update_ = true; + } +} + +WebKit::WebCache::ResourceTypeStats + TaskManagerRendererResource::GetWebCoreCacheStats() const { + return stats_; +} + +size_t TaskManagerRendererResource::GetV8MemoryAllocated() const { + return v8_memory_allocated_; +} + +size_t TaskManagerRendererResource::GetV8MemoryUsed() const { + return v8_memory_used_; +} + +void TaskManagerRendererResource::NotifyResourceTypeStats( + const WebKit::WebCache::ResourceTypeStats& stats) { + stats_ = stats; + pending_stats_update_ = false; +} + +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; +} + diff --git a/chrome/browser/task_manager_renderer_resource.h b/chrome/browser/task_manager_renderer_resource.h new file mode 100644 index 0000000..abcae52 --- /dev/null +++ b/chrome/browser/task_manager_renderer_resource.h @@ -0,0 +1,61 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_TASK_MANAGER_RENDERER_RESOURCE_H_ +#define CHROME_BROWSER_TASK_MANAGER_RENDERER_RESOURCE_H_ + +#include "base/basictypes.h" +#include "chrome/browser/task_manager.h" +#include "third_party/WebKit/WebKit/chromium/public/WebCache.h" + +// Functionality shared by all TaskManager::Resource classes that represent +// a render process (TabContents and Extensions). + +class RenderWidgetHost; + +class TaskManagerRendererResource : public TaskManager::Resource { + public: + explicit TaskManagerRendererResource(RenderWidgetHost* render_widget_host); + + virtual ~TaskManagerRendererResource(); + + 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. + bool SupportNetworkUsage() const { return true; } + void SetSupportNetworkUsage() { } + + virtual void Refresh(); + + virtual void NotifyResourceTypeStats( + const WebKit::WebCache::ResourceTypeStats& stats); + + virtual void NotifyV8HeapStats(size_t v8_memory_allocated, + size_t v8_memory_used); + + private: + RenderWidgetHost* render_widget_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_; + + // This flag is true if we are waiting for the renderer to report its stats. + bool pending_stats_update_; + + // We do a similar dance to gather the V8 memory usage in a process. + size_t v8_memory_allocated_; + size_t v8_memory_used_; + bool pending_v8_memory_allocated_update_; + + DISALLOW_COPY_AND_ASSIGN(TaskManagerRendererResource); +}; + +#endif // CHROME_BROWSER_TASK_MANAGER_RENDERER_RESOURCE_H_ + diff --git a/chrome/browser/task_manager_resource_providers.cc b/chrome/browser/task_manager_resource_providers.cc index 715dd08..7fab48a 100644 --- a/chrome/browser/task_manager_resource_providers.cc +++ b/chrome/browser/task_manager_resource_providers.cc @@ -46,20 +46,12 @@ TaskManagerTabContentsResource::TaskManagerTabContentsResource( TabContents* tab_contents) - : tab_contents_(tab_contents), - pending_stats_update_(false), - v8_memory_allocated_(0), - v8_memory_used_(0), - pending_v8_memory_allocated_update_(false) { + : TaskManagerRendererResource(tab_contents->render_view_host()), + tab_contents_(tab_contents) { // We cache the process as when the TabContents is closed the process // becomes NULL and the TaskManager still needs it. process_ = tab_contents_->process()->GetHandle(); pid_ = base::GetProcId(process_); - stats_.images.size = 0; - stats_.cssStyleSheets.size = 0; - stats_.scripts.size = 0; - stats_.xslStyleSheets.size = 0; - stats_.fonts.size = 0; } TaskManagerTabContentsResource::~TaskManagerTabContentsResource() { @@ -89,43 +81,6 @@ std::wstring TaskManagerTabContentsResource::GetTitle() const { return l10n_util::GetStringF(IDS_TASK_MANAGER_TAB_PREFIX, tab_title); } -void TaskManagerTabContentsResource::Refresh() { - if (!pending_stats_update_) { - tab_contents_->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); - pending_v8_memory_allocated_update_ = true; - } -} - -WebKit::WebCache::ResourceTypeStats - TaskManagerTabContentsResource::GetWebCoreCacheStats() const { - return stats_; -} - -size_t TaskManagerTabContentsResource::GetV8MemoryAllocated() const { - return v8_memory_allocated_; -} - -size_t TaskManagerTabContentsResource::GetV8MemoryUsed() const { - return v8_memory_used_; -} - -void TaskManagerTabContentsResource::NotifyResourceTypeStats( - const WebKit::WebCache::ResourceTypeStats& stats) { - stats_ = stats; - pending_stats_update_ = false; -} - -void TaskManagerTabContentsResource::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(); } @@ -512,7 +467,8 @@ SkBitmap* TaskManagerExtensionProcessResource::default_icon_ = NULL; TaskManagerExtensionProcessResource::TaskManagerExtensionProcessResource( ExtensionHost* extension_host) - : extension_host_(extension_host) { + : TaskManagerRendererResource(extension_host->render_view_host()), + extension_host_(extension_host) { if (!default_icon_) { ResourceBundle& rb = ResourceBundle::GetSharedInstance(); default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); diff --git a/chrome/browser/task_manager_resource_providers.h b/chrome/browser/task_manager_resource_providers.h index 65209f4..5c26c79 100644 --- a/chrome/browser/task_manager_resource_providers.h +++ b/chrome/browser/task_manager_resource_providers.h @@ -11,10 +11,10 @@ #include "base/basictypes.h" #include "base/process_util.h" #include "chrome/browser/task_manager.h" +#include "chrome/browser/task_manager_renderer_resource.h" #include "chrome/common/child_process_info.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" -#include "third_party/WebKit/WebKit/chromium/public/WebCache.h" class Extension; class ExtensionHost; @@ -22,50 +22,21 @@ class TabContents; // These file contains the resource providers used in the task manager. -class TaskManagerTabContentsResource : public TaskManager::Resource { +class TaskManagerTabContentsResource : public TaskManagerRendererResource { public: explicit TaskManagerTabContentsResource(TabContents* tab_contents); - ~TaskManagerTabContentsResource(); + virtual ~TaskManagerTabContentsResource(); // TaskManagerResource methods: - std::wstring GetTitle() const; - SkBitmap GetIcon() const; - base::ProcessHandle GetProcess() const; + virtual std::wstring GetTitle() const; + virtual SkBitmap GetIcon() const; + virtual base::ProcessHandle GetProcess() const; 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. - bool SupportNetworkUsage() const { return true; } - void SetSupportNetworkUsage() { } - - virtual void Refresh(); - - virtual void NotifyResourceTypeStats( - const WebKit::WebCache::ResourceTypeStats& stats); - - virtual void NotifyV8HeapStats(size_t v8_memory_allocated, - size_t v8_memory_used); - private: TabContents* tab_contents_; base::ProcessHandle process_; int pid_; - // 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_; - // This flag is true if we are waiting for the renderer to report its stats. - bool pending_stats_update_; - - // We do a similar dance to gather the V8 memory usage in a process. - size_t v8_memory_allocated_; - size_t v8_memory_used_; - bool pending_v8_memory_allocated_update_; DISALLOW_COPY_AND_ASSIGN(TaskManagerTabContentsResource); }; @@ -200,7 +171,7 @@ class TaskManagerChildProcessResourceProvider DISALLOW_COPY_AND_ASSIGN(TaskManagerChildProcessResourceProvider); }; -class TaskManagerExtensionProcessResource : public TaskManager::Resource { +class TaskManagerExtensionProcessResource : public TaskManagerRendererResource { public: explicit TaskManagerExtensionProcessResource(ExtensionHost* extension_host); ~TaskManagerExtensionProcessResource(); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 8c98e0c..7116cea 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1524,6 +1524,8 @@ 'browser/tabs/tab_strip_model_order_controller.h', 'browser/task_manager.cc', 'browser/task_manager.h', + 'browser/task_manager_renderer_resource.cc', + 'browser/task_manager_renderer_resource.h', 'browser/task_manager_resource_providers.cc', 'browser/task_manager_resource_providers.h', 'browser/theme_resources_util.cc', |