diff options
-rw-r--r-- | chrome/app/generated_resources.grd | 12 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.cc | 15 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.h | 2 | ||||
-rw-r--r-- | chrome/browser/task_manager.cc | 44 | ||||
-rw-r--r-- | chrome/browser/task_manager.h | 15 | ||||
-rw-r--r-- | chrome/browser/task_manager_browsertest.cc | 27 | ||||
-rw-r--r-- | chrome/browser/task_manager_resource_providers.cc | 47 | ||||
-rw-r--r-- | chrome/browser/task_manager_resource_providers.h | 17 | ||||
-rw-r--r-- | chrome/browser/views/task_manager_view.cc | 24 |
9 files changed, 202 insertions, 1 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 04d35d0..7da448b 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -2197,9 +2197,21 @@ each locale. aa1 --> <message name="IDS_TASK_MANAGER_GOATS_TELEPORTED_COLUMN" desc="The goats teleported column"> Goats Teleported </message> + <message name="IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN" desc="Task manager WebCore image cache size column."> + Image cache + </message> + <message name="IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN" desc="Task manager WebCore scripts cache size column."> + Script cache + </message> + <message name="IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN" desc="Task manager WebCore CSS cache size column."> + CSS cache + </message> <message name="IDS_TASK_MANAGER_MEM_CELL_TEXT" desc="The value displayed in the memory usage cells."> <ph name="NUM_KILOBYTES">$1<ex>5,000</ex></ph>K </message> + <message name="IDS_TASK_MANAGER_CACHE_SIZE_CELL_TEXT" desc="The value displayed in the cache size cells."> + <ph name="NUM_KILOBYTES">$1<ex>5,000</ex></ph>K (<ph name="NUM_KILOBYTES">$2<ex>5,000</ex></ph>K live) + </message> <message name="IDS_TASK_MANAGER_NA_CELL_TEXT" desc="The value displayed for network / webcache usage when the information is not available (Not Applicable)."> N/A </message> diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index 80e46683..0b8a923 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -28,6 +28,7 @@ #include "chrome/browser/renderer_host/render_widget_helper.h" #include "chrome/browser/spellchecker.h" #include "chrome/browser/spellchecker_platform_engine.h" +#include "chrome/browser/task_manager.h" #include "chrome/browser/worker_host/message_port_dispatcher.h" #include "chrome/browser/worker_host/worker_service.h" #include "chrome/common/appcache/appcache_dispatcher_host.h" @@ -724,6 +725,20 @@ void ResourceMessageFilter::OnResourceTypeStats( static_cast<int>(stats.xslStyleSheets.size / 1024)); HISTOGRAM_COUNTS("WebCoreCache.FontsSizeKB", static_cast<int>(stats.fonts.size / 1024)); + // We need to notify the TaskManager of these statistics from the UI + // thread. + ui_loop()->PostTask( + FROM_HERE, NewRunnableFunction( + &ResourceMessageFilter::OnResourceTypeStatsOnUIThread, + stats, + base::GetProcId(handle()))); +} + +void ResourceMessageFilter::OnResourceTypeStatsOnUIThread( + WebCache::ResourceTypeStats stats, base::ProcessId renderer_id) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + TaskManager::GetInstance()->model()->NotifyResourceTypeStats( + renderer_id, stats); } void ResourceMessageFilter::OnResolveProxy(const GURL& url, diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h index 00c3b13..6b93eee 100644 --- a/chrome/browser/renderer_host/resource_message_filter.h +++ b/chrome/browser/renderer_host/resource_message_filter.h @@ -214,6 +214,8 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, #endif void OnResourceTypeStats(const WebKit::WebCache::ResourceTypeStats& stats); + static void OnResourceTypeStatsOnUIThread(WebKit::WebCache::ResourceTypeStats, + base::ProcessId renderer_id); void OnResolveProxy(const GURL& url, IPC::Message* reply_msg); diff --git a/chrome/browser/task_manager.cc b/chrome/browser/task_manager.cc index 88083cc..1ac2411 100644 --- a/chrome/browser/task_manager.cc +++ b/chrome/browser/task_manager.cc @@ -37,6 +37,20 @@ static int ValueCompare(T value1, T value2) { return 1; } +// TaskManager::Resource default impls. + +std::wstring TaskManager::Resource::GetWebCoreImageCacheSize() { + return l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT); +} + +std::wstring TaskManager::Resource::GetWebCoreScriptsCacheSize() { + return l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT); +} + +std::wstring TaskManager::Resource::GetWebCoreCSSCacheSize() { + return l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT); +} + //////////////////////////////////////////////////////////////////////////////// // TaskManagerModel class //////////////////////////////////////////////////////////////////////////////// @@ -159,6 +173,25 @@ std::wstring TaskManagerModel::GetResourceGoatsTeleported(int index) const { return FormatNumber(goats_teleported_); } +std::wstring TaskManagerModel::GetResourceWebCoreImageCacheSize( + int index) const { + DCHECK(index < ResourceCount()); + return resources_[index]->GetWebCoreImageCacheSize(); +} + +std::wstring TaskManagerModel::GetResourceWebCoreScriptsCacheSize( + int index) const { + DCHECK(index < ResourceCount()); + return resources_[index]->GetWebCoreScriptsCacheSize(); +} + +std::wstring TaskManagerModel::GetResourceWebCoreCSSCacheSize( + int index) const { + DCHECK(index < ResourceCount()); + return resources_[index]->GetWebCoreCSSCacheSize(); +} + + bool TaskManagerModel::IsResourceFirstInGroup(int index) const { DCHECK(index < ResourceCount()); TaskManager::Resource* resource = resources_[index]; @@ -533,6 +566,17 @@ void TaskManagerModel::Clear() { } } +void TaskManagerModel::NotifyResourceTypeStats( + base::ProcessId renderer_id, + const WebKit::WebCache::ResourceTypeStats& stats) { + for (ResourceList::iterator it = resources_.begin(); + it != resources_.end(); ++it) { + if (base::GetProcId((*it)->GetProcess()) == renderer_id) { + (*it)->NotifyResourceTypeStats(stats); + } + } +} + void TaskManagerModel::Refresh() { DCHECK_NE(IDLE, update_state_); diff --git a/chrome/browser/task_manager.h b/chrome/browser/task_manager.h index 811cf2f..7c1e67e 100644 --- a/chrome/browser/task_manager.h +++ b/chrome/browser/task_manager.h @@ -21,6 +21,7 @@ #include "chrome/browser/tab_contents/tab_contents.h" #include "net/url_request/url_request_job_tracker.h" #include "testing/gtest/include/gtest/gtest_prod.h" +#include "webkit/api/public/WebCache.h" class MessageLoop; class SkBitmap; @@ -46,6 +47,10 @@ class TaskManager { virtual SkBitmap GetIcon() const = 0; virtual base::ProcessHandle GetProcess() const = 0; + virtual std::wstring GetWebCoreImageCacheSize(); + virtual std::wstring GetWebCoreScriptsCacheSize(); + virtual std::wstring GetWebCoreCSSCacheSize(); + // A helper function for ActivateFocusedTab. Returns NULL by default // because not all resources have an assoiciated tab. virtual TabContents* GetTabContents() const {return NULL;} @@ -60,6 +65,9 @@ class TaskManager { // Called when some bytes have been read and support_network_usage returns // false (meaning we do have network usage support). virtual void SetSupportNetworkUsage() = 0; + + virtual void NotifyResourceTypeStats( + const WebKit::WebCache::ResourceTypeStats& stats) {} }; // ResourceProviders are responsible for adding/removing resources to the task @@ -172,6 +180,9 @@ class TaskManagerModel : public URLRequestJobTracker::JobObserver, std::wstring GetResourcePhysicalMemory(int index) const; std::wstring GetResourceProcessId(int index) const; std::wstring GetResourceStatsValue(int index, int col_id) const; + std::wstring GetResourceWebCoreImageCacheSize(int index) const; + std::wstring GetResourceWebCoreScriptsCacheSize(int index) const; + std::wstring GetResourceWebCoreCSSCacheSize(int index) const; std::wstring GetResourceGoatsTeleported(int index) const; // Returns true if the resource is first in its group (resources @@ -213,6 +224,10 @@ class TaskManagerModel : public URLRequestJobTracker::JobObserver, void Clear(); // Removes all items. + void NotifyResourceTypeStats( + base::ProcessId renderer_handle, + const WebKit::WebCache::ResourceTypeStats& stats); + private: enum UpdateState { IDLE = 0, // Currently not updating. diff --git a/chrome/browser/task_manager_browsertest.cc b/chrome/browser/task_manager_browsertest.cc index 5439043..77a79e7 100644 --- a/chrome/browser/task_manager_browsertest.cc +++ b/chrome/browser/task_manager_browsertest.cc @@ -4,12 +4,14 @@ #include "chrome/browser/task_manager.h" +#include "app/l10n_util.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/extensions/extension_browsertest.h" #include "chrome/common/page_transition_types.h" #include "chrome/test/in_process_browser_test.h" #include "chrome/test/ui_test_utils.h" +#include "grit/generated_resources.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -115,3 +117,28 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionChanges) { test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); WaitForResourceChange(4); } + +IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, PopulateWebCacheFields) { + 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 tab and make sure we notice that. + GURL url(ui_test_utils::GetTestUrl(L".", L"title1.html")); + browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, + true, 0, false, NULL); + WaitForResourceChange(3); + + // Check that we get some value for the cache columns. + DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2), + l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT)); + DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(2), + l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT)); + DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(2), + l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT)); +} diff --git a/chrome/browser/task_manager_resource_providers.cc b/chrome/browser/task_manager_resource_providers.cc index 68f3f4a..8899463 100644 --- a/chrome/browser/task_manager_resource_providers.cc +++ b/chrome/browser/task_manager_resource_providers.cc @@ -35,6 +35,7 @@ #include "chrome/common/child_process_host.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/notification_service.h" +#include "chrome/common/render_messages.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" @@ -44,11 +45,17 @@ TaskManagerTabContentsResource::TaskManagerTabContentsResource( TabContents* tab_contents) - : tab_contents_(tab_contents) { + : tab_contents_(tab_contents), + pending_stats_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_->process()->process().handle(); 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() { @@ -78,6 +85,44 @@ std::wstring TaskManagerTabContentsResource::GetTitle() const { return l10n_util::GetStringF(IDS_TASK_MANAGER_TAB_PREFIX, tab_title); } +std::wstring FormatStatsSize(const WebKit::WebCache::ResourceTypeStat& stat) { + std::wstring size = FormatBytes(stat.size, DATA_UNITS_KILOBYTE, false); + std::wstring live_size = FormatBytes(stat.liveSize, + DATA_UNITS_KILOBYTE, + false); + return l10n_util::GetStringF(IDS_TASK_MANAGER_CACHE_SIZE_CELL_TEXT, + size, + live_size); +} + +void TaskManagerTabContentsResource::UpdateResourceStats() { + if (!pending_stats_update_) { + tab_contents_->render_view_host()->Send(new ViewMsg_GetCacheResourceStats); + pending_stats_update_ = true; + } +} + +std::wstring TaskManagerTabContentsResource::GetWebCoreImageCacheSize() { + UpdateResourceStats(); + return FormatStatsSize(stats_.images); +} + +std::wstring TaskManagerTabContentsResource::GetWebCoreScriptsCacheSize() { + UpdateResourceStats(); + return FormatStatsSize(stats_.scripts); +} + +std::wstring TaskManagerTabContentsResource::GetWebCoreCSSCacheSize() { + UpdateResourceStats(); + return FormatStatsSize(stats_.cssStyleSheets); +} + +void TaskManagerTabContentsResource::NotifyResourceTypeStats( + const WebKit::WebCache::ResourceTypeStats& stats) { + stats_ = stats; + pending_stats_update_ = false; +} + SkBitmap TaskManagerTabContentsResource::GetIcon() const { return tab_contents_->GetFavIcon(); } diff --git a/chrome/browser/task_manager_resource_providers.h b/chrome/browser/task_manager_resource_providers.h index e9640f0..d92767f 100644 --- a/chrome/browser/task_manager_resource_providers.h +++ b/chrome/browser/task_manager_resource_providers.h @@ -13,6 +13,7 @@ #include "chrome/browser/task_manager.h" #include "chrome/common/child_process_info.h" #include "chrome/common/notification_observer.h" +#include "webkit/api/public/WebCache.h" class Extension; class ExtensionHost; @@ -31,14 +32,30 @@ class TaskManagerTabContentsResource : public TaskManager::Resource { base::ProcessHandle GetProcess() const; TabContents* GetTabContents() const; + virtual std::wstring GetWebCoreImageCacheSize(); + virtual std::wstring GetWebCoreScriptsCacheSize(); + virtual std::wstring GetWebCoreCSSCacheSize(); + // TabContents always provide the network usage. bool SupportNetworkUsage() const { return true; } void SetSupportNetworkUsage() { } + virtual void NotifyResourceTypeStats( + const WebKit::WebCache::ResourceTypeStats& stats); + private: + void UpdateResourceStats(); + 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. A query to any of the + // GetWebCore*CacheSize() functions will send an IPC to the renderer asking + // for an update unless a query is already outstanding. + WebKit::WebCache::ResourceTypeStats stats_; + // This flag is true if we are waiting for the renderer to report its stats. + bool pending_stats_update_; DISALLOW_COPY_AND_ASSIGN(TaskManagerTabContentsResource); }; diff --git a/chrome/browser/views/task_manager_view.cc b/chrome/browser/views/task_manager_view.cc index 2a26896..5256b03 100644 --- a/chrome/browser/views/task_manager_view.cc +++ b/chrome/browser/views/task_manager_view.cc @@ -112,6 +112,15 @@ std::wstring TaskManagerTableModel::GetText(int row, int col_id) { case IDS_TASK_MANAGER_GOATS_TELEPORTED_COLUMN: // Goats Teleported! return model_->GetResourceGoatsTeleported(row); + case IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN: + return model_->GetResourceWebCoreImageCacheSize(row); + + case IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN: + return model_->GetResourceWebCoreScriptsCacheSize(row); + + case IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN: + return model_->GetResourceWebCoreCSSCacheSize(row); + default: return model_->GetResourceStatsValue(row, col_id); } @@ -293,6 +302,15 @@ void TaskManagerView::Init() { columns_.push_back(TableColumn(IDS_TASK_MANAGER_PROCESS_ID_COLUMN, TableColumn::RIGHT, -1, 0)); columns_.back().sortable = true; + columns_.push_back(TableColumn(IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN, + TableColumn::RIGHT, -1, 0)); + columns_.back().sortable = true; + columns_.push_back(TableColumn(IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN, + TableColumn::RIGHT, -1, 0)); + columns_.back().sortable = true; + columns_.push_back(TableColumn(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN, + TableColumn::RIGHT, -1, 0)); + columns_.back().sortable = true; tab_table_ = new views::GroupTableView(table_model_.get(), columns_, views::ICON_AND_TEXT, false, true, @@ -302,6 +320,12 @@ void TaskManagerView::Init() { tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PROCESS_ID_COLUMN, false); tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_SHARED_MEM_COLUMN, false); tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, false); + tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN, + false); + tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN, + false); + tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN, + false); tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_GOATS_TELEPORTED_COLUMN, false); |